Initial release 0.001
authorMarius Gavrilescu <Marius Gavrilescu>
Thu, 11 Jul 2013 20:30:37 +0000 (23:30 +0300)
committerMarius Gavrilescu <Marius Gavrilescu>
Thu, 11 Jul 2013 20:30:37 +0000 (23:30 +0300)
Changes [new file with mode: 0644]
MANIFEST [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
lib/POE/Component/IRC/Plugin/Hello.pm [new file with mode: 0644]
t/POE-Component-IRC-Plugin-Hello.t [new file with mode: 0644]

diff --git a/Changes b/Changes
new file mode 100644 (file)
index 0000000..48e3ab4
--- /dev/null
+++ b/Changes
@@ -0,0 +1,2 @@
+POE::Component::IRC::Plugin::Hello (0.001) 11 Jul 2013
+ * Initial release
\ No newline at end of file
diff --git a/MANIFEST b/MANIFEST
new file mode 100644 (file)
index 0000000..ce246a4
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,6 @@
+Changes
+Makefile.PL
+MANIFEST
+README
+t/POE-Component-IRC-Plugin-Hello.t
+lib/POE/Component/IRC/Plugin/Hello.pm
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..19cc118
--- /dev/null
@@ -0,0 +1,20 @@
+use 5.014000;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME             => 'POE::Component::IRC::Plugin::Hello',
+    VERSION_FROM     => 'lib/POE/Component/IRC/Plugin/Hello.pm',
+       ABSTRACT_FROM    => 'lib/POE/Component/IRC/Plugin/Hello.pm',
+       AUTHOR           => 'Marius Gavrilescu <marius@ieval.ro>',
+       MIN_PERL_VERSION => 5.014000,
+       LICENSE          => 'perl',
+       SIGN             => 1,
+    PREREQ_PM        => {
+         'List::Util' => 0,
+         'IRC::Utils' => 0,
+         'POE::Component::IRC::Plugin' => 0,
+       },
+       BUILD_REQUIRES   => {
+         'Test::MockObject' => 1.09,
+       },
+);
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..b35cfa4
--- /dev/null
+++ b/README
@@ -0,0 +1,31 @@
+POE-Component-IRC-Plugin-Hello version 0.001
+============================================
+
+POE::Component::IRC::Plugin::Hello is a PoCo-IRC plugin that greets back
+who greet him or a channel in public. It knows how to say hello in several
+languages, and greets people in a randomly chosen language.
+
+INSTALLATION
+
+To install this module type the following:
+
+   perl Makefile.PL
+   make
+   make test
+   make install
+
+DEPENDENCIES
+
+This module requires these other modules and libraries:
+
+* List::Util
+* IRC::Utils
+* POE::Component::IRC::Plugin
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2013 by Marius Gavrilescu
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.14.2 or,
+at your option, any later version of Perl 5 you may have available.
diff --git a/lib/POE/Component/IRC/Plugin/Hello.pm b/lib/POE/Component/IRC/Plugin/Hello.pm
new file mode 100644 (file)
index 0000000..1820f84
--- /dev/null
@@ -0,0 +1,80 @@
+package POE::Component::IRC::Plugin::Hello 0.001;
+
+use 5.014000;
+use strict;
+use warnings;
+
+use List::Util qw/first/;
+
+use IRC::Utils qw/parse_user/;
+use POE::Component::IRC::Plugin qw/PCI_EAT_NONE/;
+
+sub new {
+  my $class = shift;
+  my $self = {
+       greetings => [qw/privet hello salut salutari neata neaţa hola hey hi bonjour niihau wassup sup hallo chikmaa tungjatjeta parev salam namaskaar mingalarba ahoy saluton allo moin aloha namaste shalom ciào ciao servus salve ave merhaba witaj hei hola selam sawubona/, "what's up", 'que tal', 'こんにちは', '你好'],
+       @_
+  };
+
+  bless $self, $class
+}
+
+sub PCI_register {
+  my ($self, $irc) = @_;
+  $irc->plugin_register($self, SERVER => qw/public/);
+  1
+}
+
+sub PCI_unregister { 1 }
+
+sub S_public{
+  my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
+  my $nick = parse_user $$rfullname;
+  my $mynick = $irc->nick_name;
+  my @hello = @{$self->{greetings}};
+
+  my $match = first { $$rmessage =~ /^\s*(?:$mynick(?:)[:,])?\s*$_\s*$/i } @hello;
+  $irc->yield(privmsg => $$rchannels->[0] => $hello[int rand $#hello].", $nick") if $match;
+  PCI_EAT_NONE
+}
+
+1;
+__END__
+
+=head1 NAME
+
+POE::Component::IRC::Plugin::Hello - PoCo-IRC plugin that says hello
+
+=head1 SYNOPSIS
+
+  use POE::Component::IRC::Plugin::Hello;
+
+  my $irc = POE::Component::IRC::State->spawn(...);
+  $irc->plugin_add(Hello => POE::Component::IRC::Plugin::Hello->new);
+
+=head1 DESCRIPTION
+
+POE::Component::IRC::Plugin::Hello is a PoCo-IRC plugin that greets back
+who greet him or a channel in public. It knows how to say hello in several
+languages, and greets people in a randomly chosen language.
+
+The list of greetings is configurable by the plugin user.
+
+=head1 SEE ALSO
+
+L<POE::Component::IRC::Plugin>
+
+=head1 AUTHOR
+
+Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2013 by Marius Gavrilescu
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.14.2 or,
+at your option, any later version of Perl 5 you may have available.
+
+
+=cut
diff --git a/t/POE-Component-IRC-Plugin-Hello.t b/t/POE-Component-IRC-Plugin-Hello.t
new file mode 100644 (file)
index 0000000..ebb2ef5
--- /dev/null
@@ -0,0 +1,45 @@
+use v5.14;
+use strict;
+use warnings;
+
+use Test::More tests => 15;
+use Test::MockObject;
+
+BEGIN { use_ok('POE::Component::IRC::Plugin::Hello') };
+
+# Variable setup
+my $hello_sent;
+
+my $mockirc = Test::MockObject->new;
+$mockirc->mock(yield => sub { $hello_sent = 1 })->set_always(nick_name => 'hellobot');
+
+my $self = POE::Component::IRC::Plugin::Hello->new;
+my $channels = [ '#chan' ];
+
+# Sub setup
+sub runtest{
+  my ($message, $expect, $comment) = @_;
+  $hello_sent=0;
+  $self->S_public($mockirc, \'mgv!marius@ieval.ro', \$channels, \$message);
+  ok($hello_sent == $expect, $comment)
+}
+
+#Tests
+runtest 'privet', 1, 'simple privet';
+runtest 'PrIvEt', 1, 'privet in mixed case';
+runtest '  privet  ', 1, 'privet with spaces';
+runtest 'hellobot: privet', 1, 'addressed privet';
+runtest 'hellobot:    privet   ', 1, 'addressed privet with spaces';
+runtest 'ahoy', 1, 'ahoy';
+runtest 'namaste', 1, 'namaste';
+runtest 'neaţa', 1, 'neaţa (UTF-8 test)';
+runtest 'こんにちは', 1, 'こんにちは (another UTF-8 test)';
+
+runtest 'salu', 0, 'salu (misspelling)';
+runtest 'hii', 0, 'hii (misspelling)';
+runtest 'neaţa mgv', 0, 'neaţa mgv (valid greeting with garbage after it)';
+
+$self = POE::Component::IRC::Plugin::Hello->new(greetings => ['sayonara']);
+
+runtest 'privet', 0, 'custom greetings - privet';
+runtest '  sayonara   ', 1, 'custom greetings - sayonara';
This page took 0.014691 seconds and 4 git commands to generate.