| 1 | package POE::Component::IRC::Plugin::Google::PageRank; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '2.001004'; # VERSION | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use POE qw(Component::WWW::Google::PageRank); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use POE::Component::IRC::Plugin qw(:ALL); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 0 | my $package = shift; | |||||||||||||||||||||||||||
| 14 | 0 | ▶ | croak "Even number of arguments must be specified" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | if @_ & 1; | ||||||||||||||||||||||||||||
| 16 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 17 | 0 | $args{ lc $_ } = delete $args{ $_ } for keys %args; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # fill in the defaults | ||||||||||||||||||||||||||||
| 20 | 0 | %args = ( | |||||||||||||||||||||||||||
| 21 | debug => 0, | ||||||||||||||||||||||||||||
| 22 | auto => 1, | ||||||||||||||||||||||||||||
| 23 | response_event => 'irc_google_pagerank', | ||||||||||||||||||||||||||||
| 24 | banned => [], | ||||||||||||||||||||||||||||
| 25 | addressed => 1, | ||||||||||||||||||||||||||||
| 26 | eat => 1, | ||||||||||||||||||||||||||||
| 27 | trigger => qr/^rank\s+(?=\S)/i, | ||||||||||||||||||||||||||||
| 28 | listen_for_input => [ qw(public notice privmsg) ], | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | %args, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | $args{listen_for_input} = { | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | map { $_ => 1 } @{ $args{listen_for_input} || [] } | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'listen_for_input'} || []
MC/DC0%0/1
$args{'listen_for_input'} || []
$args{'listen_for_input'}
Truth table0%0/2
A
A= $args{'listen_for_input'}
| |||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | return bless \%args, $package; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub _start { | ||||||||||||||||||||||||||
|
Subroutine
_start: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 41 | 0 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||||||||||||||||
| 42 | 0 | $self->{_session_id} = $_[SESSION]->ID(); | |||||||||||||||||||||||||||
| 43 | 0 | $kernel->refcount_increment( $self->{_session_id}, __PACKAGE__ ); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | $self->{poco} = POE::Component::WWW::Google::PageRank->spawn( | ||||||||||||||||||||||||||||
| 46 | debug => $self->{debug}, | ||||||||||||||||||||||||||||
| 47 | 0 | ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | undef; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub PCI_register { | ||||||||||||||||||||||||||
|
Subroutine
PCI_register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 0 | my ( $self, $irc ) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | $self->{irc} = $irc; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | $irc->plugin_register( $self, 'SERVER', qw(public notice msg) ); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | $self->{_session_id} = POE::Session->create( | |||||||||||||||||||||||||||
| 60 | object_states => [ | ||||||||||||||||||||||||||||
| 61 | $self => [ | ||||||||||||||||||||||||||||
| 62 | qw( | ||||||||||||||||||||||||||||
| 63 | _start | ||||||||||||||||||||||||||||
| 64 | _shutdown | ||||||||||||||||||||||||||||
| 65 | _rank_done | ||||||||||||||||||||||||||||
| 66 | ) | ||||||||||||||||||||||||||||
| 67 | ], | ||||||||||||||||||||||||||||
| 68 | ], | ||||||||||||||||||||||||||||
| 69 | )->ID; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | return 1; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub _shutdown { | ||||||||||||||||||||||||||
|
Subroutine
_shutdown: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 75 | 0 | my ($kernel, $self) = @_[ KERNEL, OBJECT ]; | |||||||||||||||||||||||||||
| 76 | 0 | $self->{poco}->shutdown; | |||||||||||||||||||||||||||
| 77 | 0 | $kernel->alarm_remove_all(); | |||||||||||||||||||||||||||
| 78 | 0 | $kernel->refcount_decrement( $self->{_session_id}, __PACKAGE__ ); | |||||||||||||||||||||||||||
| 79 | 0 | undef; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub PCI_unregister { | ||||||||||||||||||||||||||
|
Subroutine
PCI_unregister: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # Plugin is dying make sure our POE session does as well. | ||||||||||||||||||||||||||||
| 86 | 0 | $poe_kernel->call( $self->{_session_id} => '_shutdown' ); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | delete $self->{irc}; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | return 1; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub S_public { | ||||||||||||||||||||||||||
|
Subroutine
S_public: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | 0 | my ( $self, $irc ) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 95 | 0 | my $who = ${ $_[0] }; | |||||||||||||||||||||||||||
| 96 | 0 | my $channel = ${ $_[1] }->[0]; | |||||||||||||||||||||||||||
| 97 | 0 | my $message = ${ $_[2] }; | |||||||||||||||||||||||||||
| 98 | 0 | return $self->_parse_input( $irc, $who, $channel, $message, 'public' ); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub S_notice { | ||||||||||||||||||||||||||
|
Subroutine
S_notice: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 0 | my ( $self, $irc ) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 103 | 0 | my $who = ${ $_[0] }; | |||||||||||||||||||||||||||
| 104 | 0 | my $channel = ${ $_[1] }->[0]; | |||||||||||||||||||||||||||
| 105 | 0 | my $message = ${ $_[2] }; | |||||||||||||||||||||||||||
| 106 | 0 | return $self->_parse_input( $irc, $who, $channel, $message, 'notice' ); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub S_msg { | ||||||||||||||||||||||||||
|
Subroutine
S_msg: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 110 | 0 | my ( $self, $irc ) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 111 | 0 | my $who = ${ $_[0] }; | |||||||||||||||||||||||||||
| 112 | 0 | my $channel = ${ $_[1] }->[0]; | |||||||||||||||||||||||||||
| 113 | 0 | my $message = ${ $_[2] }; | |||||||||||||||||||||||||||
| 114 | 0 | return $self->_parse_input( $irc, $who, $channel, $message, 'privmsg' ); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub _parse_input { | ||||||||||||||||||||||||||
|
Subroutine
_parse_input: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||
| 118 | 0 | my ( $self, $irc, $who, $channel, $message, $type ) = @_; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | warn "Got input: [ who => $who, channel => $channel, " | ||||||||||||||||||||||||||||
| 121 | . "mesage => $message ]" | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | return PCI_EAT_NONE | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | unless exists $self->{listen_for_input}{ $type }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | my $what; | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ( $self->{addressed} and $type eq 'public' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"addressed"} and $type eq "public"
MC/DC0%0/2
$self->{"addressed"} and $type eq "public"
$self->{"addressed"}
$type eq "public"
Truth table0%0/3
A and B
A= $self->{"addressed"}B= $type eq "public"
| |||||||||||||||||||||||||||||
| 129 | 0 | my $my_nick = $irc->nick_name(); | |||||||||||||||||||||||||||
| 130 | 0 | ($what) = $message =~ m/^\s*\Q$my_nick\E[\:\,\;\.]?\s*(.*)$/i; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | else { | ||||||||||||||||||||||||||||
| 133 | 0 | $what = $message; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | return PCI_EAT_NONE | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $what and $what =~ s/$self->{"trigger"}//
MC/DC0%0/2
defined $what and $what =~ s/$self->{"trigger"}//
defined $what
$what =~ s/$self->{"trigger"}//
Truth table0%0/3
A and B
A= defined $whatB= $what =~ s/$self->{"trigger"}//
| |||||||||||||||||||||||||||||
| 137 | unless defined $what and $what =~ s/$self->{trigger}//; | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | $what =~ s/^\s+|\s+$//; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | return PCI_EAT_NONE | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | unless defined $message; | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | warn "Matched trigger: [ who => $who, channel => $channel, " | ||||||||||||||||||||||||||||
| 145 | . "what => $what ]" | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | foreach my $ban_re ( @{ $self->{banned} || [] } ) { | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'banned'} || []
MC/DC0%0/1
$self->{'banned'} || []
$self->{'banned'}
Truth table0%0/2
A
A= $self->{'banned'}
| |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | return PCI_EAT_NONE | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | if $who =~ /$ban_re/; | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | $self->{poco}->rank( { | ||||||||||||||||||||||||||||
| 154 | session => $self->{_session_id}, | ||||||||||||||||||||||||||||
| 155 | 0 | event => '_rank_done', | |||||||||||||||||||||||||||
| 156 | page => $what, | ||||||||||||||||||||||||||||
| 157 | _who => $who, | ||||||||||||||||||||||||||||
| 158 | _channel => $channel, | ||||||||||||||||||||||||||||
| 159 | _message => $message, | ||||||||||||||||||||||||||||
| 160 | _type => $type, | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | ); | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | return $self->{eat} ? PCI_EAT_ALL : PCI_EAT_NONE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub _rank_done { | ||||||||||||||||||||||||||
|
Subroutine
_rank_done: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 168 | 0 | my ( $kernel, $self, $in_ref ) = @_[ KERNEL, OBJECT, ARG0 ]; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | my $response_message; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ( exists $in_ref->{error} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | $response_message = defined $in_ref->{error} | ||||||||||||||||||||||||||||
| 174 | 0 | ▶ | ? "Error: $in_ref->{error}" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | : "Error: unknown"; | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | else { | ||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $in_ref->{rank} ||= 'not available'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$in_ref->{"rank"} ||= "not available"
MC/DC0%0/1
$in_ref->{"rank"} ||= "not available"
$in_ref->{"rank"}
Truth table0%0/2
A
A= $in_ref->{"rank"}
| |||||||||||||||||||||||||||||
| 179 | 0 | $response_message = "Rank is $in_ref->{rank}"; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | $self->{irc}->send_event( $self->{response_event} => { | ||||||||||||||||||||||||||||
| 183 | result => $response_message, | ||||||||||||||||||||||||||||
| 184 | page => $in_ref->{page}, | ||||||||||||||||||||||||||||
| 185 | 0 | map { $_ => $in_ref->{"_$_"} } | |||||||||||||||||||||||||||
| 186 | qw( who channel message type ), | ||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if ( $self->{auto} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | my $response_type = $in_ref->{_type} eq 'public' | ||||||||||||||||||||||||||||
| 192 | ? 'privmsg' | ||||||||||||||||||||||||||||
| 193 | 0 | ▶ | : $in_ref->{_type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | my $where = $in_ref->{_type} eq 'public' | ||||||||||||||||||||||||||||
| 196 | ? $in_ref->{_channel} | ||||||||||||||||||||||||||||
| 197 | 0 | ▶ | : (split /!/, $in_ref->{_who})[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | $kernel->post( $self->{irc} => | ||||||||||||||||||||||||||||
| 200 | 0 | $response_type => | |||||||||||||||||||||||||||
| 201 | $where => | ||||||||||||||||||||||||||||
| 202 | $response_message | ||||||||||||||||||||||||||||
| 203 | ); | ||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | undef; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 1 | 1; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | __END__ | ||||||||||||||||||||||||||||