File Coverage

blib/lib/POE/Component/IRC/Plugin/Hello.pm
Criterion Covered Total %
statement 44 48 91.6
branch 2 2 100.0
condition n/a
subroutine 13 15 86.6
pod 0 4 0.0
total 59 69 85.5


line stmt bran cond sub pod time code
1             package POE::Component::IRC::Plugin::Hello;
2              
3 1     1   17293 use 5.014000;
  1         2  
  1         27  
4 1     1   3 use strict;
  1         1  
  1         20  
5 1     1   2 use warnings;
  1         1  
  1         16  
6 1     1   534 use utf8;
  1         11  
  1         3  
7 1     1   505 use Encode qw/encode decode/;
  1         7928  
  1         66  
8 1     1   1404 use Unicode::Normalize qw/NFC/;
  1         2730  
  1         130  
9              
10             our $VERSION = '0.001003';
11              
12 1     1   10 use List::Util qw/first/;
  1         1  
  1         131  
13              
14 1     1   757 use IRC::Utils qw/parse_user/;
  1         14908  
  1         152  
15 1     1   890 use POE::Component::IRC::Plugin qw/PCI_EAT_NONE/;
  1         581  
  1         557  
16              
17             sub new {
18 2     2 0 410 my $class = shift;
19 2         27 my $self = {
20             greetings => [
21             qw/privet hello salut salutari neata neaţa neața neatza
22             hola hey hi bonjour wassup sup hallo chikmaa
23             tungjatjeta parev salam namaskaar mingalarba ahoy
24             saluton allo moin aloha namaste shalom ciào ciao servus
25             salve ave merhaba witaj hei hola selam sawubona
26             geodemorgen hoi καλημέρα/,
27             'what\'s up', 'que tal', 'こんにちは', '你好', 'ni hao',
28             'добро јутро', 'γεια σας', 'bom dia', 'hyvää huomenta'],
29             @_
30             };
31              
32 2         9 bless $self, $class
33             }
34              
35             sub PCI_register {
36 0     0 0 0 my ($self, $irc) = @_;
37 0         0 $irc->plugin_register($self, SERVER => qw/public/);
38 0         0 1
39             }
40              
41 0     0 0 0 sub PCI_unregister { 1 }
42              
43             sub S_public{
44 18     18 0 6160 my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
45 18         51 my $nick = parse_user $$rfullname;
46 18         237 my $mynick = $irc->nick_name;
47 18         840 my $message = NFC decode 'UTF-8', $$rmessage;
48 18         805 my @hello = @{$self->{greetings}};
  18         118  
49              
50 1     1   6 my $match = first { $message =~ /^\s*(?:$mynick(?:)[:,])?\s*$_\s*[.!]?\s*$/is } @hello;
  1     320   1  
  1         12  
  18         91  
  320         29114  
51 18         168 my $randhello = encode 'UTF-8', $hello[int rand $#hello];
52 18 100       602 $irc->yield(privmsg => $$rchannels->[0] => "$randhello, $nick") if $match;
53 18         670 PCI_EAT_NONE
54             }
55              
56             1;
57             __END__