Commits

Shlomi Fish  committed 703700f

Changed an if/elsif chain to a dispatch table.

  • Participants
  • Parent commits 7d0e2eb

Comments (0)

Files changed (1)

     return $self->{'_config'};
 }
 
+
 # perform - called to perform/do anything (duh) 
 # (no, do, not duh) (oh, ok, sorry)
 sub perform {
     # if it is not we quit straight away as well.
     return 1 unless ($e->{'channel'} eq '') or ($self->InChannel($e));
     # Ok, dispatch the event.
-    if ($type eq 'Told') {
-        return $self->Told($e, $e->{'data'});
-    } elsif ($type eq 'Heard') {
-        return $self->Heard($e, $e->{'data'});
-    } elsif ($type eq 'Baffled') {
-        return $self->Baffled($e, $e->{'data'});
-    } elsif ($type eq 'Noticed') {
-        return $self->Noticed($e, $e->{'data'});
-    } elsif ($type eq 'Felt') {
-        return $self->Felt($e, $e->{'data'});
-    } elsif ($type eq 'Saw') {
-        return $self->Saw($e, $e->{'data'});
-    } elsif ($type eq 'Invited') {
-        return $self->Invited($e, $e->{'data'});
-    } elsif ($type eq 'Kicked') {
-        return $self->Kicked($e, $e->{'channel'});
-    } elsif ($type eq 'ModeChange') {
-        return $self->ModeChange($e, $e->{'channel'}, $e->{'data'}, $e->{'from'});
-    } elsif ($type eq 'Authed') {
-        return $self->Authed($e, $e->{'from'});
-    } elsif ($type eq 'SpottedNickChange') {
-        return $self->SpottedNickChange($e, $e->{'from'}, $e->{'data'});
-    } elsif ($type eq 'SpottedTopicChange') {
-        return $self->SpottedTopicChange($e, $e->{'channel'}, $e->{'data'});
-    } elsif ($type eq 'SpottedJoin') {
-        return $self->SpottedJoin($e, $e->{'channel'}, $e->{'from'});
-    } elsif ($type eq 'SpottedPart') {
-        return $self->SpottedPart($e, $e->{'channel'}, $e->{'from'});
-    } elsif ($type eq 'SpottedKick') {
-        return $self->SpottedKick($e, $e->{'channel'}, $e->{'data'});
-    } elsif ($type eq 'SpottedQuit') {
-        return $self->SpottedQuit($e, $e->{'from'}, $e->{'data'});
-    } elsif ($type eq 'CTCPPing') {
-        return $self->CTCPPing($e, $e->{'from'}, $e->{'data'});
-    } elsif ($type eq 'CTCPVersion') {
-        return $self->CTCPVersion($e, $e->{'from'}, $e->{'data'});
-    } elsif ($type eq 'CTCPSource') {
-        return $self->CTCPSource($e, $e->{'from'}, $e->{'data'});
-
-    # XXX have not implemented mode parsing yet
-    } elsif ($type eq 'GotOpped') {
-        return $self->GotOpped($e, $e->{'channel'}, $e->{'from'});
-    } elsif ($type eq 'GotDeopped') {
-        return $self->GotDeopped($e, $e->{'channel'}, $e->{'from'});
-    } elsif ($type eq 'SpottedOpping') {
-        return $self->SpottedOpping($e, $e->{'channel'}, $e->{'from'});
-    } elsif ($type eq 'SpottedDeopping') {
-        return $self->SpottedDeopping($e, $e->{'channel'}, $e->{'from'});
+    #
+
+    my %dispatch_by_type = 
+    (
+        (map { $_ => sub { return $self->$type($e, $e->{'from'}, $e->{'data'});}, } qw(CTCPPing CTCPSource CTCPVersion SpottedNickChange SpottedQuit)),
+    (map { $_ => sub { return $self->$type($e, $e->{'channel'}, $e->{'data'}, $e->{'from'});}, } qw(ModeChange)),
+(map { $_ => sub { return $self->$type($e, $e->{'data'});}, } qw(Baffled Felt Heard Invited Noticed Saw Told)),
+    (map { $_ => sub { return $self->$type($e, $e->{'channel'}, $e->{'data'});}, } qw(SpottedKick SpottedTopicChange)),
+(map { $_ => sub { return $self->$type($e, $e->{'channel'});}, } qw(Kicked)),
+    (map { $_ => sub { return $self->$type($e, $e->{'from'});}, } qw(Authed)),
+(map { $_ => sub { return $self->$type($e, $e->{'channel'}, $e->{'from'});}, } qw(GotDeopped GotOpped SpottedDeopping SpottedJoin SpottedOpping SpottedPart)),
+    );
+
+    if (my $callback = $dispatch_by_type{$type}) {
+        return $callback->();
     } else {
         $self->debug("Unknown action type '$type'. Ignored.");
         # XXX UModeChange (not implemented yet)