Reindent code, tests, Makefile.PL
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 16 Aug 2014 21:34:16 +0000 (00:34 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 16 Aug 2014 21:34:16 +0000 (00:34 +0300)
Makefile.PL
lib/POE/Component/IRC/Plugin/Infobot.pm
t/POE-Component-IRC-Plugin-Infobot.t

index 372de9c7bf49da1604343b924f3cdae4e4c23d7e..4645acd10afe789e1273625d254d7d69f3246fc1 100644 (file)
@@ -1,21 +1,21 @@
 use ExtUtils::MakeMaker;
 
 WriteMakefile(
-  NAME              => 'POE::Component::IRC::Plugin::Infobot',
-  VERSION_FROM      => 'lib/POE/Component/IRC/Plugin/Infobot.pm',
-  ABSTRACT_FROM     => 'lib/POE/Component/IRC/Plugin/Infobot.pm',
-  AUTHOR            => 'Marius Gavrilescu <marius@ieval.ro>',
-  LICENSE           => 'perl',
-  MIN_PERL_VERSION  => '5.14.0',
-  META_ADD          => {
-       dynamic_config  => 0,
-  },
-  PREREQ_PM         => {
-       POE::Component::IRC::Plugin => 0,
-       IRC::Utils => 0.12,
-       DB_File => 0.
-  },
-  BUILD_REQUIRES      => {
-       Test::MockObject => 0,
-  }
+       NAME              => 'POE::Component::IRC::Plugin::Infobot',
+       VERSION_FROM      => 'lib/POE/Component/IRC/Plugin/Infobot.pm',
+       ABSTRACT_FROM     => 'lib/POE/Component/IRC/Plugin/Infobot.pm',
+       AUTHOR            => 'Marius Gavrilescu <marius@ieval.ro>',
+       LICENSE           => 'perl',
+       MIN_PERL_VERSION  => '5.14.0',
+       META_ADD          => {
+               dynamic_config  => 0,
+       },
+       PREREQ_PM         => {
+               POE::Component::IRC::Plugin => 0,
+               IRC::Utils => 0.12,
+               DB_File => 0.
+       },
+       BUILD_REQUIRES      => {
+               Test::MockObject => 0,
+       }
 );
index 4e3426a07db39571d2550e8cf4392db834c66aa9..1527d865933d633f1ef2d33192301508ed4599ef 100644 (file)
@@ -12,120 +12,120 @@ use IRC::Utils qw/parse_user/;
 use POE::Component::IRC::Plugin qw/PCI_EAT_NONE/;
 
 use constant +{
-  OK => [ 'sure, %s', 'ok, %s', 'gotcha, %s'],
-  A_IS_B => [ '%s is %s', 'I think %s is %s', 'hmmm... %s is %s', 'it has been said that %s is %s', '%s is probably %s', 'rumour has it %s is %s', 'i heard %s was %s', 'somebody said %s is %s', 'i guess %s is %s', 'well, %s is %s', '%s is, like, %s', 'methinks %s is %s'],
-  I_DONT_KNOW => [ 'I don\'t know, %s', 'Dunno, %s', 'No idea, %s', '%s: huh?', 'nem tudom, %s', 'anlamıyorum, %s', 'bilmiyorum, %s', 'nu ştiu d\'astea, %s', 'Je ne sais pas, %s', 'Я не знаю, %s'],
+       OK => [ 'sure, %s', 'ok, %s', 'gotcha, %s'],
+       A_IS_B => [ '%s is %s', 'I think %s is %s', 'hmmm... %s is %s', 'it has been said that %s is %s', '%s is probably %s', 'rumour has it %s is %s', 'i heard %s was %s', 'somebody said %s is %s', 'i guess %s is %s', 'well, %s is %s', '%s is, like, %s', 'methinks %s is %s'],
+       I_DONT_KNOW => [ 'I don\'t know, %s', 'Dunno, %s', 'No idea, %s', '%s: huh?', 'nem tudom, %s', 'anlamıyorum, %s', 'bilmiyorum, %s', 'nu ştiu d\'astea, %s', 'Je ne sais pas, %s', 'Я не знаю, %s'],
 };
 
 sub new {
-  my $class = shift;
-  my $self = {
-       filename => 'factoids.db',
-       @_
-  };
-
-  my %db;
-  $self->{dbobj} = tie %db, DB_File => $self->{filename} if defined $self->{filename};
-  $self->{db} = \%db;
-  bless $self, $class
+       my $class = shift;
+       my $self = {
+               filename => 'factoids.db',
+               @_
+       };
+
+       my %db;
+       $self->{dbobj} = tie %db, DB_File => $self->{filename} if defined $self->{filename};
+       $self->{db} = \%db;
+       bless $self, $class
 }
 
 sub getstr {
-  my $rstrings = shift;
-  my @strings = @$rstrings;
-  sprintf $strings[int rand $#strings], @_
+       my $rstrings = shift;
+       my @strings = @$rstrings;
+       sprintf $strings[int rand $#strings], @_
 }
 
 sub infobot_add {
-  my ($self, $irc, $key, $value, $to, $nick) = @_;
-  if (exists $self->{db}->{$key}) {
-       $irc->yield(privmsg => $to => "I already had it that way, $nick") if $value eq $self->{db}->{$key};
-       $irc->yield(privmsg => $to => "... but $key is $self->{db}->{$key}!") unless $value eq $self->{db}->{$key};
-  } else {
-       $self->{db}->{$key} = $value;
-       $self->{dbobj}->sync if exists $self->{dbobj};
-       $irc->yield(privmsg => $to => getstr OK, $nick);
-  }
+       my ($self, $irc, $key, $value, $to, $nick) = @_;
+       if (exists $self->{db}->{$key}) {
+               $irc->yield(privmsg => $to => "I already had it that way, $nick") if $value eq $self->{db}->{$key};
+               $irc->yield(privmsg => $to => "... but $key is $self->{db}->{$key}!") unless $value eq $self->{db}->{$key};
+       } else {
+               $self->{db}->{$key} = $value;
+               $self->{dbobj}->sync if exists $self->{dbobj};
+               $irc->yield(privmsg => $to => getstr OK, $nick);
+       }
 }
 
 sub infobot_query {
-  my ($self, $irc, $key, $to, $nick, $addressed) = @_;
-  if (exists $self->{db}->{$key}) {
-       my @answers = split /\s+\|\s+/, $self->{db}->{$key};
-       local $_ = $answers[int rand $#answers];
-
-       if (/^<action> (.+)$/i) {
-         $irc->yield(ctcp => $to => "ACTION $1")
-       } elsif (/^<reply> (.*)$/i){
-         $irc->yield(privmsg => $to => $1)
-       } else {
-         $irc->yield(privmsg => $to => getstr A_IS_B, $key, $_)
+       my ($self, $irc, $key, $to, $nick, $addressed) = @_;
+       if (exists $self->{db}->{$key}) {
+               my @answers = split /\s+\|\s+/, $self->{db}->{$key};
+               local $_ = $answers[int rand $#answers];
+
+               if (/^<action> (.+)$/i) {
+                       $irc->yield(ctcp => $to => "ACTION $1")
+               } elsif (/^<reply> (.*)$/i) {
+                       $irc->yield(privmsg => $to => $1)
+               } else {
+                       $irc->yield(privmsg => $to => getstr A_IS_B, $key, $_)
+               }
+       } elsif ($addressed) {
+               $irc->yield(privmsg => $to => getstr I_DONT_KNOW, $nick)
        }
-  } elsif ($addressed) {
-       $irc->yield(privmsg => $to => getstr I_DONT_KNOW, $nick)
-  }
 }
 
 sub infobot_forget {
-  my ($self, $irc, $key, $to, $nick) = @_;
-  if (exists $self->{db}->{$key}) {
-       delete $self->{db}->{$key};
-       $self->{dbobj}->sync if exists $self->{dbobj};
-       $irc->yield(privmsg => $to => "$nick: I forgot $key")
-  } else {
-       $irc->yield(privmsg => $to => "I didn't have anything matching $key, $nick")
-  }
+       my ($self, $irc, $key, $to, $nick) = @_;
+       if (exists $self->{db}->{$key}) {
+               delete $self->{db}->{$key};
+               $self->{dbobj}->sync if exists $self->{dbobj};
+               $irc->yield(privmsg => $to => "$nick: I forgot $key")
+       } else {
+               $irc->yield(privmsg => $to => "I didn't have anything matching $key, $nick")
+       }
 }
 
 sub runcmd{
-  my ($self, $irc, $to, $nick, $message, $addressed) = @_;
+       my ($self, $irc, $to, $nick, $message, $addressed) = @_;
 
-  local $_= $message;
+       local $_= $message;
 
-  if (/^(.+)\s+is\s+(.*[^?])$/) {
-       infobot_add $self, $irc, $1, $2, $to, $nick if $addressed
-  } elsif (/^(.+)\?$/) {
-       infobot_query $self, $irc, $1, $to, $nick, $addressed
-  } elsif (/^forget\s+(.*)$/) {
-       infobot_forget $self, $irc, $1, $to, $nick if $addressed
-  }
+       if (/^(.+)\s+is\s+(.*[^?])$/) {
+               infobot_add $self, $irc, $1, $2, $to, $nick if $addressed
+       } elsif (/^(.+)\?$/) {
+               infobot_query $self, $irc, $1, $to, $nick, $addressed
+       } elsif (/^forget\s+(.*)$/) {
+               infobot_forget $self, $irc, $1, $to, $nick if $addressed
+       }
 }
 
 sub PCI_register {
-  my ($self, $irc) = @_;
-  $irc->plugin_register($self, SERVER => qw/public msg/);
-  1
+       my ($self, $irc) = @_;
+       $irc->plugin_register($self, SERVER => qw/public msg/);
+       1
 }
 
 sub PCI_unregister{ 1 }
 
 sub S_public {
-  my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
-  my $nick = parse_user $$rfullname;
+       my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
+       my $nick = parse_user $$rfullname;
 
-  for my $channel (@$$rchannels) {
-       local $_ = $$rmessage;
+       for my $channel (@$$rchannels) {
+               local $_ = $$rmessage;
 
-       my $addressed=0;
-       my $mynick=$irc->nick_name;
-       if (/^$mynick [,:]\s+/x) {
-         $addressed=1;
-         s/^$mynick [,:]\s+//x;
-       }
+               my $addressed=0;
+               my $mynick=$irc->nick_name;
+               if (/^$mynick [,:]\s+/x) {
+                       $addressed=1;
+                       s/^$mynick [,:]\s+//x;
+               }
 
-       runcmd $self, $irc, $channel, $nick, $_, $addressed
-  }
+               runcmd $self, $irc, $channel, $nick, $_, $addressed
+       }
 
-  PCI_EAT_NONE
+       PCI_EAT_NONE
 }
 
 sub S_msg{
-  my ($self, $irc, $rfullname, $rtargets, $rmessage) = @_;
-  my $nick = parse_user $$rfullname;
+       my ($self, $irc, $rfullname, $rtargets, $rmessage) = @_;
+       my $nick = parse_user $$rfullname;
 
-  runcmd $self, $irc, $nick, $nick, $$rmessage, 1;
+       runcmd $self, $irc, $nick, $nick, $$rmessage, 1;
 
-  PCI_EAT_NONE
+       PCI_EAT_NONE
 }
 
 1;
index d2d02d11236c941994042cb7a54257175b7a97b4..cbe422ebc33114c303ddf7f8a960dbb747cfc3c5 100644 (file)
@@ -9,8 +9,8 @@ BEGIN { use_ok('POE::Component::IRC::Plugin::Infobot') };
 
 no warnings 'redefine';
 sub POE::Component::IRC::Plugin::Infobot::getstr {
-  my $rstrings = shift;
-  sprintf @{$rstrings}[0], @_
+       my $rstrings = shift;
+       sprintf @{$rstrings}[0], @_
 }
 use warnings 'redefine';
 
@@ -18,8 +18,8 @@ my $last_msg;
 my $last_ctcp;
 
 sub yield {
-  $last_msg = $_[3] if $_[1] eq 'privmsg';
-  $last_ctcp = $_[3] if $_[1] eq 'ctcp';
+       $last_msg = $_[3] if $_[1] eq 'privmsg';
+       $last_ctcp = $_[3] if $_[1] eq 'ctcp';
 }
 
 my $mockirc = Test::MockObject->new;
@@ -28,12 +28,12 @@ $mockirc->mock(yield => \&yield)->set_always(nick_name => 'bot');
 my $self = POE::Component::IRC::Plugin::Infobot->new(filename => undef);
 
 sub runtest{
-  my ($message, $expect, $comment, $private) = @_;
-  undef $last_msg;
-  undef $last_ctcp;
-  $self->S_public($mockirc, \'mgv!marius@ieval.ro', \([ '#chan' ]), \$message) unless $private;
-  $self->S_msg($mockirc, \'mgv!marius@ieval.ro', undef, \$message) if $private;
-  is($last_msg // $last_ctcp, $expect, $comment)
+       my ($message, $expect, $comment, $private) = @_;
+       undef $last_msg;
+       undef $last_ctcp;
+       $self->S_public($mockirc, \'mgv!marius@ieval.ro', \([ '#chan' ]), \$message) unless $private;
+       $self->S_msg($mockirc, \'mgv!marius@ieval.ro', undef, \$message) if $private;
+       is($last_msg // $last_ctcp, $expect, $comment)
 }
 
 runtest 'bot: a is b', 'sure, mgv', 'add';
This page took 0.019621 seconds and 4 git commands to generate.