From: Marius Gavrilescu Date: Sat, 2 May 2015 18:35:56 +0000 (+0300) Subject: Replace given/when with if/elsif/else X-Git-Tag: 0.001~3 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=a750465391500500569d859a16cb92f5d37a3965;p=app-fonbot-daemon.git Replace given/when with if/elsif/else --- diff --git a/lib/App/FonBot/Plugin/IRC.pm b/lib/App/FonBot/Plugin/IRC.pm index 71904c5..be9b177 100644 --- a/lib/App/FonBot/Plugin/IRC.pm +++ b/lib/App/FonBot/Plugin/IRC.pm @@ -72,60 +72,48 @@ sub irc_msg{ my @args=shellwords $msg; my $cmd=shift @args; - given($cmd){ - when(/^myid$/i){ - $self->{irc}->yield(privmsg => $nick, $from); + local $_ = $cmd; + if (/^myid$/i){ + $self->{irc}->yield(privmsg => $nick, $from); + } elsif (/^login$/i) { + my ($user, $pass) = @args; + + eval { pwcheck $user, $pass }; + + if ($@) { + $self->{log}->debug("Login for $user failed"); + $self->{irc}->yield(privmsg => $nick, 'Bad username/password combination'); + } else { + $self->{log}->debug("Login for $user succeded"); + $self->{nick_to_username}{$from} = $user; + $self->{irc}->yield(privmsg => $nick, "Logged in as $user"); } - - when(/^login$/i) { - my ($user, $pass) = @args; - - eval { pwcheck $user, $pass }; - - if ($@) { - $self->{log}->debug("Login for $user failed"); - $self->{irc}->yield(privmsg => $nick, 'Bad username/password combination'); - } else { - $self->{log}->debug("Login for $user succeded"); - $self->{nick_to_username}{$from} = $user; - $self->{irc}->yield(privmsg => $nick, "Logged in as $user"); - } - } - - when(/^logout$/i){ - delete $self->{nick_to_username}{$from}; - } - - when(/^prefix$/i){ - if (defined $username) { - $self->{prefix}{$username} = [@args]; - } else { - $self->{irc}->yield(privmsg => $nick, 'You are not logged in. Say "login your_username your_password" (where your_username and your_password are your login credentials) to login.'); - } + } elsif (/^logout$/i){ + delete $self->{nick_to_username}{$from}; + } elsif (/^prefix$/i){ + if (defined $username) { + $self->{prefix}{$username} = [@args]; + } else { + $self->{irc}->yield(privmsg => $nick, 'You are not logged in. Say "login your_username your_password" (where your_username and your_password are your login credentials) to login.'); } - - when(/^noprefix$/i){ - if (defined $username) { - delete $self->{prefix}{$username} - } else { - $self->{irc}->yield(privmsg => $nick, 'You are not logged in. Say "login your_username your_password" (where your_username and your_password are your login credentials) to login.'); - } + } elsif (/^noprefix$/i){ + if (defined $username) { + delete $self->{prefix}{$username} + } else { + $self->{irc}->yield(privmsg => $nick, 'You are not logged in. Say "login your_username your_password" (where your_username and your_password are your login credentials) to login.'); } - - default { - if (defined $username) { - $ok_user_addresses{"$username $address"}=1; - $self->{log}->debug("Command $cmd @args from $username"); - if (exists $self->{prefix}{$username}) { - sendmsg $username, undef, $address, @{$self->{prefix}{$username}}, $cmd, @args; - } else { - sendmsg $username, undef, $address, $cmd, @args; - } + } else { + if (defined $username) { + $ok_user_addresses{"$username $address"}=1; + $self->{log}->debug("Command $cmd @args from $username"); + if (exists $self->{prefix}{$username}) { + sendmsg $username, undef, $address, @{$self->{prefix}{$username}}, $cmd, @args; } else { - $self->{irc}->yield(privmsg => $nick, 'You are not logged in. Say "login your_username your_password" (where your_username and your_password are your login credentials) to login.'); + sendmsg $username, undef, $address, $cmd, @args; } + } else { + $self->{irc}->yield(privmsg => $nick, 'You are not logged in. Say "login your_username your_password" (where your_username and your_password are your login credentials) to login.'); } - } }