From a6026a4cc907eb81018425399cc298a6a6cfd342 Mon Sep 17 00:00:00 2001 From: Andreas Scherbaum Date: Sat, 7 Jul 2012 13:31:51 +0200 Subject: [PATCH] - get rid of the Switch module - use Perl builtin functionality instead --- docbot.pl | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/docbot.pl b/docbot.pl index e794a25..d24a9c9 100755 --- a/docbot.pl +++ b/docbot.pl @@ -48,8 +48,8 @@ use Data::Dumper; use POSIX ":sys_wait_h"; use Scalar::Util 'refaddr'; use YAML::XS qw (/./); -use Switch; use URI::Escape; +use feature qw/switch/; import docbot::config; import docbot::db; @@ -1866,54 +1866,54 @@ sub handle_command { my $channel = shift; - switch ($command) { - case('search') { + given ($command) { + when('search') { $main::statistics{'command_counter_search'}++; return handle_command_search($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('help') { + when('help') { $main::statistics{'command_counter_help'}++; return handle_command_help($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('info') { + when('info') { $main::statistics{'command_counter_info'}++; } - case('learn') { + when('learn') { $main::statistics{'command_counter_learn'}++; return handle_command_learn($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('forget') { + when('forget') { $main::statistics{'command_counter_forget'}++; return handle_command_forget($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('config') { + when('config') { $main::statistics{'command_counter_config'}++; } - case('status') { + when('status') { $main::statistics{'command_counter_status'}++; return handle_command_status($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('wallchan') { + when('wallchan') { $main::statistics{'command_counter_wallchan'}++; return handle_command_wallchan($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('say') { + when('say') { return handle_command_say($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('join') { + when('join') { return handle_command_join($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('leave') { + when('leave') { return handle_command_leave($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('lost') { + when('lost') { $main::statistics{'command_counter_lost'}++; return handle_command_lost($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('url') { + when('url') { return handle_command_url($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } - case('key') { + when('key') { return handle_command_key($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } } @@ -4005,11 +4005,11 @@ sub on_irc_notice { my $irc = $sender->get_heap(); my $session = find_irc_session($irc); - switch ($who) { - case(/^NickServ/) {} - case(/^ChanServ/) {} - case(/\.freenode\.net/i) {} - else { + given ($who) { + when(/^NickServ/) {} + when(/^ChanServ/) {} + when(/\.freenode\.net/i) {} + default { # send to commandchannel my $text = 'irc notice on session ' . $irc->nick_name() . ' from: ' . $nick; send_to_commandchannel($text); @@ -4067,32 +4067,32 @@ if (substr($event, 0, 1) eq '_') { my $print_it = 1; - switch ($event) { - case('autoping') { $print_it = 0; } - case('irc_ping') { $print_it = 0; } - case('irc_pong') { $print_it = 0; } - case('irc_connected') { $print_it = 0; } - case('irc_snotice') { $print_it = 0; } - case('irc_whois') { $print_it = 0; } - case('irc_mode') { $print_it = 0; } - case('irc_topic') { $print_it = 0; } - case('irc_ctcp_action') { $print_it = 0; } - case('irc_ctcp') { $print_it = 0; } - case('irc_isupport') { $print_it = 0; } - case('irc_nick') { $print_it = 0; } - case('autoping') { $print_it = 0; } - case('irc_disconnected') { $print_it = 0; } - case('irc_socketerr') { $print_it = 0; } - case('irc_cap') { $print_it = 0; } - case('irc_notice') { + given ($event) { + when('autoping') { $print_it = 0; } + when('irc_ping') { $print_it = 0; } + when('irc_pong') { $print_it = 0; } + when('irc_connected') { $print_it = 0; } + when('irc_snotice') { $print_it = 0; } + when('irc_whois') { $print_it = 0; } + when('irc_mode') { $print_it = 0; } + when('irc_topic') { $print_it = 0; } + when('irc_ctcp_action') { $print_it = 0; } + when('irc_ctcp') { $print_it = 0; } + when('irc_isupport') { $print_it = 0; } + when('irc_nick') { $print_it = 0; } + when('autoping') { $print_it = 0; } + when('irc_disconnected') { $print_it = 0; } + when('irc_socketerr') { $print_it = 0; } + when('irc_cap') { $print_it = 0; } + when('irc_notice') { if (@$args[0] =~ /^NickServ/) { $print_it = 0; } if (@$args[0] =~ /^ChanServ/) { $print_it = 0; } if (@$args[0] =~ /\.freenode\.net/i) { $print_it = 0; } } - case('irc_ctcp_version') { + when('irc_ctcp_version') { if (@$args[0] =~ /^freenode\-connect/) { $print_it = 0; } } - case(/^irc_\d+/) { $print_it = 0; } + when(/^irc_\d+/) { $print_it = 0; } } #$print_it = 1; -- 2.39.5