summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLibravatarWilliam Heimbigner <william.heimbigner@gmail.com>2016-01-14 14:48:23 -0700
committerLibravatarWilliam Heimbigner <william.heimbigner@gmail.com>2016-01-14 14:48:23 -0700
commitda7d90773b8acf3dde1731f81237bb451ab73e33 (patch)
tree07c86d4a421152550efd4c80f6fcc62d71a7e438 /lib
parentcca3bcc2cf7e0b7bd8d365aa77ae75716bdbcf6e (diff)
Allow multiple event handlers to be added for the same event. Increased version number to allow for depending on this ability
Diffstat (limited to 'lib')
-rw-r--r--lib/Net/IRC.pm2
-rw-r--r--lib/Net/IRC/Connection.pm26
2 files changed, 13 insertions, 15 deletions
diff --git a/lib/Net/IRC.pm b/lib/Net/IRC.pm
index 4b93fe1..92bb2af 100644
--- a/lib/Net/IRC.pm
+++ b/lib/Net/IRC.pm
@@ -33,7 +33,7 @@ BEGIN {
use strict;
use vars qw($VERSION);
-$VERSION = "0.90";
+$VERSION = "0.91";
sub new {
my $proto = shift;
diff --git a/lib/Net/IRC/Connection.pm b/lib/Net/IRC/Connection.pm
index 65af574..b0ce1ec 100644
--- a/lib/Net/IRC/Connection.pm
+++ b/lib/Net/IRC/Connection.pm
@@ -161,7 +161,17 @@ sub _add_generic_handler {
}
}
- $hash_ref->{lc $ev} = [ $ref, $rp ];
+# $hash_ref->{lc $ev} = [ @{$hash_ref->{lc $ev}}, [$ref, $rp] ];
+ if (!defined($hash_ref->{lc $ev})) {
+ $hash_ref->{lc $ev} = [ ];
+ }
+ if ($rp == 0) {
+ $hash_ref->{lc $ev} = [ $ref ];
+ } elsif ($rp == 1) {
+ $hash_ref->{lc $ev} = [ $ref, @{$hash_ref->{lc $ev}} ];
+ } elsif ($rp == 2) {
+ $hash_ref->{lc $ev} = [ @{$hash_ref->{lc $ev}}, $ref ];
+ }
}
return 1;
}
@@ -498,20 +508,8 @@ sub handler {
} else {
return $self->_default($event, @_);
}
-
- my ($code, $rp) = @{$handler};
-
- # If we have args left, try to call the handler.
- if ($rp == 0) { # REPLACE
+ foreach my $code (@{$handler}) {
&$code($self, $event, @_);
- } elsif ($rp == 1) { # BEFORE
- &$code($self, $event, @_);
- $self->_default($event, @_);
- } elsif ($rp == 2) { # AFTER
- $self->_default($event, @_);
- &$code($self, $event, @_);
- } else {
- confess "Bad parameter passed to handler(): rp=$rp";
}
warn "Handler for '$ev' called.\n" if $self->{_debug};