File Coverage

blib/lib/POE/Component/IRC/Plugin/CoreList.pm
Criterion Covered Total %
statement 20 65 30.7
branch 0 24 0.0
condition 0 14 0.0
subroutine 7 10 70.0
pod 1 5 20.0
total 28 118 23.7


line stmt bran cond sub pod time code
1             package POE::Component::IRC::Plugin::CoreList;
2             $POE::Component::IRC::Plugin::CoreList::VERSION = '1.04';
3             #ABSTRACT: A POE::Component::IRC plugin that provides Module::CoreList goodness.
4              
5 1     1   197665 use strict;
  1         2  
  1         23  
6 1     1   4 use warnings;
  1         1  
  1         70  
7 1     1   2158 use Module::CoreList;
  1         30874  
  1         7  
8 1     1   426 use POE::Component::IRC::Plugin qw(:ALL);
  1         1  
  1         816  
9              
10             my $cmds = qr/find|search|release|date/;
11              
12             sub new {
13 1     1 1 4468 my $package = shift;
14 1         2 my %args = @_;
15 1         3 $args{lc $_} = delete $args{$_} for keys %args;
16 1         3 bless \%args, $package;
17             }
18              
19             sub PCI_register {
20 1     1 0 332 my ($self,$irc) = @_;
21 1         4 $irc->plugin_register( $self, 'SERVER', qw(public msg) );
22 1         25 return 1;
23             }
24              
25             sub PCI_unregister {
26 1     1 0 1409 return 1;
27             }
28              
29             sub S_public {
30 0     0 0   my ($self,$irc) = splice @_, 0 , 2;
31 0           my ($nick,$userhost) = ( split /!/, ${ $_[0] } )[0..1];
  0            
32 0           my $channel = ${ $_[1] }->[0];
  0            
33 0           my $what = ${ $_[2] };
  0            
34 0           my $mynick = $irc->nick_name();
35 0   0       my $cmdstr = $self->{command} || '';
36 0           my ($string) = $what =~ m/^\s*\Q$mynick\E[\:\,\;\.]?\s*(.*)$/i;
37 0 0 0       return PCI_EAT_NONE unless ( $string and $string =~ /^\Q$cmdstr\E\s*(?:($cmds))?\s*(.*)/io );
38 0   0       my ( $command, $module, @args ) = ( $1 || 'release', split /\s+/, $2 );
39 0           my $reply = _corelist( $command, $module, @args );
40 0           $irc->yield( 'privmsg', $channel, $reply );
41 0           return PCI_EAT_NONE;
42             }
43              
44             sub S_msg {
45 0     0 0   my ($self,$irc) = splice @_, 0 , 2;
46 0           my ($nick,$userhost) = ( split /!/, ${ $_[0] } )[0..1];
  0            
47 0           my $string = ${ $_[2] };
  0            
48 0   0       my $cmdstr = $self->{command} || '';
49 0 0 0       return PCI_EAT_NONE unless ( $string and $string =~ /^\Q$cmdstr\E\s*(?:($cmds))?\s*(.*)/io );
50 0   0       my ( $command, $module, @args ) = ( $1 || 'release', split /\s+/, $2 );
51 0           my $reply = _corelist( $command, $module, @args );
52 0 0         $irc->yield( ( $self->{privmsg} ? 'privmsg' : 'notice' ), $nick, $reply );
53 0           return PCI_EAT_NONE;
54             }
55              
56             sub _corelist {
57 0     0     my ($command,$module,@args) = @_;
58             # compute the reply
59 0           my $reply;
60 0 0         if ( $command =~ /^(?:find|search)$/i ) {
61 0           my @modules = Module::CoreList->find_modules( qr/$module/, @args );
62              
63             # shorten large response lists
64 0 0         @modules = (@modules[0..8], '...') if @modules > 9;
65              
66 0           local $" = ', ';
67 0 0         my $where = ( @args ? " in perl @args" : '' );
68 0 0         $reply = ( @modules
69             ? "Found @modules"
70             : "Found no module matching /$module/" )
71             . $where;
72             }
73             else {
74 0           my ( $release, $patchlevel, $date )
75             = ( Module::CoreList->first_release($module), '', '' );
76 0 0         if ($release) {
77 0           $date = $Module::CoreList::released{$release};
78             }
79 0           my $rem;
80 0 0         if ( Module::CoreList->can('removed_from') ) {
81 0           my $removed = Module::CoreList->removed_from($module);
82 0 0         if ( $removed ) {
83 0           my $remdate = $Module::CoreList::released{$removed};
84 0           $rem = " and removed from $removed (released on $remdate)";
85             }
86             }
87 0 0         $reply = $release
    0          
88             ? "$module was first released with perl $release ("
89             . "released on $date)"
90             . ( $rem ? $rem : '' )
91             : "$module is not in the core";
92             }
93 0           return $reply;
94             }
95              
96             qq[Apple::Core];
97              
98             __END__