BasePoCoWrap.pm

filter: Statementstmt 15.3% 17 / 111 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 29.4% 5 / 17 Podpod 0.0% 0 / 6 totaltotal 11.7% 22 / 188 CC 26 SCAR 46.4
CC
26
Cov
11%
_parse_input
240.0
_poco_done
72.0
new
30.0
CRAP 103.5
« BaseWrap.pm ↑ Summary
1 package POE::Component::IRC::Plugin::BasePoCoWrap;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '1.001002'; # VERSION
7  
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶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=5 SCAR=34.0
Pod undocumented
13 0 my $package = shift;
14 0 ▶ croak "Even number of arguments must be specified"
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 0 0
15 if @_ & 1;
16 0 my %args = @_;
17 0 $args{ lc $_ } = delete $args{ $_ } for keys %args;
18  
19 # fill in the defaults
20 0 my $self = bless {}, $package;
21 0 %args = (
22 debug => 0,
23 auto => 1,
24 response_event => 'irc_poco_wrap_response',
25 banned => [],
26 addressed => 1,
27 eat => 1,
28 trigger => qr/^poco_wrap\s+(?=\S)/i,
29 listen_for_input => [ qw(public notice privmsg) ],
30 response_types => {
31 public => 'public',
32 privmsg => 'privmsg',
33 notice => 'notice',
34 },
35  
36 $self->_make_default_args(),
37  
38 %args,
39 );
40  
41 $args{listen_for_input} = {
42 0 ▶ map { $_ => 1 } @{ $args{listen_for_input} || [] }
Condition0%0/2
$args{'listen_for_input'} || []
l!l
00
MC/DC0%0/1
$args{'listen_for_input'} || []
$args{'listen_for_input'}
Truth table0%0/2
A
A= $args{'listen_for_input'}
Aresult
11
00
43 };
44  
45 0 $self->{ $_ } = delete $args{ $_ } for keys %args;
46  
47 0 return $self;
48 }
49  
50 0 ▶sub _start {
Subroutine _start: not called CC=1 SCAR=6.9
51 0 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
52 0 $self->{_session_id} = $_[SESSION]->ID();
53 0 $kernel->refcount_increment( $self->{_session_id}, __PACKAGE__ );
54  
55 0 $self->{poco} = $self->_make_poco;
56  
57 0 undef;
58 }
59  
60 0 ▶sub PCI_register {
Subroutine PCI_register: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my ( $self, $irc ) = splice @_, 0, 2;
62  
63 0 $self->{irc} = $irc;
64  
65 0 $irc->plugin_register( $self, 'SERVER', qw(public notice msg) );
66  
67 0 $self->{_session_id} = POE::Session->create(
68 object_states => [
69 $self => [
70 qw(
71 _start
72 _shutdown
73 _poco_done
74 _poco_begin
75 )
76 ],
77 ],
78 )->ID;
79  
80 0 return 1;
81 }
82  
83 0 ▶sub _shutdown {
Subroutine _shutdown: not called CC=1 SCAR=6.9
84 0 my ($kernel, $self) = @_[ KERNEL, OBJECT ];
85 0 $self->{poco}->shutdown;
86 0 $kernel->alarm_remove_all();
87 0 $kernel->refcount_decrement( $self->{_session_id}, __PACKAGE__ );
88 0 undef;
89 }
90  
91 0 ▶sub PCI_unregister {
Subroutine PCI_unregister: not called CC=1 SCAR=6.9
Pod undocumented
92 0 my $self = shift;
93  
94 # Plugin is dying make sure our POE session does as well.
95 0 $poe_kernel->call( $self->{_session_id} => '_shutdown' );
96  
97 0 delete $self->{irc};
98  
99 0 return 1;
100 }
101  
102 0 ▶sub S_public {
Subroutine S_public: not called CC=1 SCAR=6.9
Pod undocumented
103 0 my ( $self, $irc ) = splice @_, 0, 2;
104 0 my $who = ${ $_[0] };
105 0 my $channel = ${ $_[1] }->[0];
106 0 my $message = ${ $_[2] };
107 0 return $self->_parse_input( $irc, $who, $channel, $message, 'public' );
108 }
109  
110 0 ▶sub S_notice {
Subroutine S_notice: not called CC=1 SCAR=6.9
Pod undocumented
111 0 my ( $self, $irc ) = splice @_, 0, 2;
112 0 my $who = ${ $_[0] };
113 0 my $channel = ${ $_[1] }->[0];
114 0 my $message = ${ $_[2] };
115 0 return $self->_parse_input( $irc, $who, $channel, $message, 'notice' );
116 }
117  
118 0 ▶sub S_msg {
Subroutine S_msg: not called CC=1 SCAR=6.9
Pod undocumented
119 0 my ( $self, $irc ) = splice @_, 0, 2;
120 0 my $who = ${ $_[0] };
121 0 my $channel = ${ $_[1] }->[0];
122 0 my $message = ${ $_[2] };
123 0 return $self->_parse_input( $irc, $who, $channel, $message, 'privmsg' );
124 }
125  
126 0 ▶sub _parse_input {
Subroutine _parse_input: not called CC=15 SCAR=54.8
127 0 my ( $self, $irc, $who, $channel, $message, $type ) = @_;
128  
129 warn "Got input: [ who => $who, channel => $channel, "
130 . "mesage => $message ]"
131 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
132  
133 return PCI_EAT_NONE
134 0 ▶ unless exists $self->{listen_for_input}{ $type };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"listen_for_input"}{$type} 0 0 0
135  
136 0 my $what;
137 0 ▶ if ( $self->{addressed} and $type eq 'public' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'addressed'} and $type eq 'public') { } 0 0 0
Condition0%0/3
$self->{"addressed"} and $type eq "public"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
138 0 my $my_nick = $irc->nick_name();
139 0 ($what) = $message =~ m/^\s*\Q$my_nick\E[\:\,\;\.]?\s*(.*)$/i;
140 }
141 else {
142 0 $what = $message;
143 }
144  
145 0 ▶ return PCI_EAT_NONE
Branch: 1 branch
BranchTrueFalseTotal
unless defined $what 0 0 0
146 unless defined $what;
147  
148 return PCI_EAT_NONE
149 unless (
150 ( exists $self->{triggers}{ $type }
151 and $what =~ s/$self->{triggers}{$type}//
152 )
153 or
154 0 ▶ ( exists $self->{trigger} and $what =~ s/$self->{trigger}// )
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"triggers"}{$type} and $what =~ s/$self->{"triggers"}{$type}// or exists $self->{"trigger"} and $what =~ s/$self->{"trigger"}// 0 0 0
Condition0%0/9
exists $self->{"triggers"}{$type} and $what =~ s/$self->{"triggers"}{$type}// or exists $self->{"trigger"} and $what =~ s/$self->{"trigger"}//
l!l&&r!l&&!r
000
exists $self->{"triggers"}{$type} and $what =~ s/$self->{"triggers"}{$type}//
!ll&&!rl&&r
000
exists $self->{"trigger"} and $what =~ s/$self->{"trigger"}//
!ll&&!rl&&r
000
MC/DC0%0/4
exists $self->{"triggers"}{$type} and $what =~ s/$self->{"triggers"}{$type}// or exists $self->{"trigger"} and $what =~ s/$self->{"trigger"}//
exists $self->{"triggers"}{$type} $what =~ s/$self->{"triggers"}{$type}// exists $self->{"trigger"} $what =~ s/$self->{"trigger"}//
Truth table0%0/7
A and B or C and D
A= exists $self->{"triggers"}{$type}B= $what =~ s/$self->{"triggers"}{$type}//C= exists $self->{"trigger"}D= $what =~ s/$self->{"trigger"}//
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
155 );
156  
157 0 $what =~ s/^\s+|\s+$//g;
158  
159 warn "Matched trigger: [ who => $who, channel => $channel, "
160 . "what => $what ]"
161 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
162  
163 0 ▶ foreach my $ban_re ( @{ $self->{banned} || [] } ) {
Condition0%0/2
$self->{'banned'} || []
l!l
00
MC/DC0%0/1
$self->{'banned'} || []
$self->{'banned'}
Truth table0%0/2
A
A= $self->{'banned'}
Aresult
11
00
164 0 ▶ return PCI_EAT_NONE
Branch: 1 branch
BranchTrueFalseTotal
if $who =~ /$ban_re/ 0 0 0
165 if $who =~ /$ban_re/;
166 }
167  
168 0 $poe_kernel->post( $self->{_session_id} => _poco_begin => {
169 what => $what,
170 who => $who,
171 channel => $channel,
172 message => $message,
173 type => $type,
174 }
175 );
176  
177 0 ▶ return $self->{eat} ? PCI_EAT_ALL : PCI_EAT_NONE;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'eat'} ? : 0 0 0
178 }
179  
180 0 ▶sub _poco_begin {
Subroutine _poco_begin: not called CC=1 SCAR=6.9
181 0 my ( $self, $args_ref ) = @_[OBJECT, ARG0];
182 0 $self->_make_poco_call( $args_ref );
183 }
184  
185 0 ▶sub _poco_done {
Subroutine _poco_done: not called CC=8 SCAR=42.8
186 0 my ( $kernel, $self, $in_ref ) = @_[ KERNEL, OBJECT, ARG0 ];
187  
188 0 my $response_message
189 = $self->_make_response_message( @_[ARG0 .. $#_] );
190  
191 0 my $event_response;
192 0 ▶ if ( my $key = $self->_message_into_response_event( $in_ref ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = $self->_message_into_response_event($in_ref)) { } 0 0 0
193 0 ▶ if ( ref $key eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $key eq 'ARRAY') { } 0 0 0
194 0 $in_ref->{ $key->[0] } = $response_message;
195 %$in_ref = (
196 %$in_ref,
197 0 %{ $key->[1] },
198 );
199 }
200 else {
201 0 $in_ref->{ $key } = $response_message;
202 }
203 0 $event_response = $in_ref;
204 }
205 else {
206 0 $event_response = $self->_make_response_event( $in_ref );
207 }
208  
209 0 ▶ $response_message = [ $response_message ]
Branch: 1 branch
BranchTrueFalseTotal
unless ref $response_message eq "ARRAY" 0 0 0
210 unless ref $response_message eq 'ARRAY';
211  
212 $self->{irc}->send_event(
213 0 $self->{response_event} => $event_response,
214 );
215  
216 0 ▶ if ( $self->{auto} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"auto"}) 0 0 0
217 0 $in_ref->{_type} = $self->{response_types}{ $in_ref->{_type} };
218  
219 my $response_type = $in_ref->{_type} eq 'public'
220 ? 'privmsg'
221 0 ▶ : $in_ref->{_type};
Branch: 1 branch
BranchTrueFalseTotal
$in_ref->{'_type'} eq 'public' ? : 0 0 0
222  
223 my $where = $in_ref->{_type} eq 'public'
224 ? $in_ref->{_channel}
225 0 ▶ : (split /!/, $in_ref->{_who})[0];
Branch: 1 branch
BranchTrueFalseTotal
$in_ref->{'_type'} eq 'public' ? : 0 0 0
226  
227 0 for ( @$response_message ) {
228 $kernel->post( $self->{irc} =>
229 0 $response_type =>
230 $where =>
231 $_
232 );
233 }
234 }
235  
236 0 undef;
237 }
238  
239 0 ▶sub _message_into_response_event { undef; }
Subroutine _message_into_response_event: not called CC=1 SCAR=6.9
240  
241 2 1;
242 __END__
« BaseWrap.pm ↑ Summary