Permalink
Browse files

Replace masak++'s attempt at dispatchy stuff with one that doesn't re…

…ly on string matching exceptions. And use it more widely.
  • Loading branch information...
1 parent 15662a1 commit 7af1fb4f17d5b85d89e911a766b46e184e4c3b96 @jnthn jnthn committed May 16, 2012
Showing with 16 additions and 14 deletions.
  1. +16 −14 lib/Net/IRC/Bot.pm
View
@@ -123,43 +123,45 @@ class Net::IRC::Bot {
$text ~~ /^ (.+?) [<.ws> (.*)]? $/;
$event.what = $1 && ~$1;
- @.modules>>.*"ctcp_{ lc $0 }"($event);
+ self.do_dispatch("ctcp_{ lc $0 }", $event);
#If its a CTCP ACTION then we also call 'emoted'
- @.modules>>.*emoted($event) if uc $0 eq 'ACTION';
+ self.do_dispatch("emoted", $event) if uc $0 eq 'ACTION';
}
else {
- for @.modules -> $m {
- say $event.WHAT;
- try $m.said($event);
- if $! && $!.message !~~ /'none of these signatures match'/ {
- die $!;
- }
- }
+ self.do_dispatch("said", $event);
}
}
when "NOTICE" {
- @.modules>>.*noticed($event);
+ self.do_dispatch("noticed", $event);
}
when "KICK" {
$event.what = $raw<params>[1];
- @.modules>>.*kicked($event);
+ self.do_dispatch("kicked", $event);
}
when "JOIN" {
- @.modules>>.*joined($event);
+ self.do_dispatch("joined", $event);
}
when "NICK" {
- @.modules>>.*nickchange($event);
+ self.do_dispatch("nickchange", $event);
}
when "376"|"422" {
#End of motd / no motd. (Usually) The last thing a server sends the client on connect.
- @.modules>>.*connected($event)
+ self.do_dispatch("connected", $event);
}
}
}
+
+ method do_dispatch($method, $event) {
+ for @.modules -> $mod {
+ if $mod.^find_method($method) -> $multi {
+ $multi.candidates_matching($mod, $event)>>.($mod, $event);
+ }
+ }
+ }
}

0 comments on commit 7af1fb4

Please sign in to comment.