]> iEval git - app-fonbot-daemon.git/commitdiff
Replace given/when with if/elsif/else
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 2 May 2015 18:35:56 +0000 (21:35 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 2 May 2015 18:35:56 +0000 (21:35 +0300)
lib/App/FonBot/Plugin/IRC.pm

index 71904c5c20384f6f0ab6906a24ed2f7062deb962..be9b177a5d74806e71c6dc72eed9b1184f193c34 100644 (file)
@@ -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.');
                }
-
        }
 }
 
This page took 0.023746 seconds and 4 git commands to generate.