IRC.pm

filter: Statementstmt 43.1% 157 / 364 Branchbran 24.1% 41 / 170 Conditioncond 23.2% 23 / 99 MC/DCmcdc 13.4% 7 / 52 Subroutinesub 59.1% 29 / 49 Podpod 100% 24 / 24 totaltotal 37.0% 281 / 758 CC 144 SCAR 61.3
CC
144
Cov
35%
_on_message
1806.0
_parent
506.0
__ANON__
42.0
CRAP 461.3
↑ Summary IRC/History.pm »
1 package Bot::IRC;
2 # ABSTRACT: Yet Another IRC Bot
3  
4 14 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use exact;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 ▶use Daemon::Device;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Date::Format 'time2str';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use Encode qw( encode decode );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use IO::Socket::IP -register;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use IO::Socket::SSL;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use Time::Crontab;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 14 our $VERSION = '1.49'; # VERSION
15  
16 17 ▶sub new {
Subroutine new: called CC=20 SCAR=31.9
Pod documented
17 17 my $class = shift;
18 17 my $self = bless( {@_}, $class );
19  
20 17 ▶ croak('Odd number of elements passed to new()') if ( @_ % 2 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 17 17
21 croak('connect/server not provided to new()')
22 17 ▶ unless ( ref $self->{connect} eq 'HASH' and $self->{connect}{server} );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"connect"} eq "HASH" and $self->{"connect"}{"server"} 1 16 17
Condition66%2/3
ref $self->{"connect"} eq "HASH" and $self->{"connect"}{"server"}
!ll&&!rl&&r
1016
MC/DC50%1/2
ref $self->{"connect"} eq "HASH" and $self->{"connect"}{"server"}
ref $self->{"connect"} eq "HASH" $self->{"connect"}{"server"}
Truth table66%2/3
A and B
A= ref $self->{"connect"} eq "HASH"B= $self->{"connect"}{"server"}
ABresult
0X0
100
111
23  
24 16 ▶ $self->{spawn} ||= 2;
Condition100%2/2
$self->{"spawn"} ||= 2
l!l
412
MC/DC100%1/1
$self->{"spawn"} ||= 2
$self->{"spawn"}
Truth table100%2/2
A
A= $self->{"spawn"}
Aresult
11
00
25 16 ▶ $self->{encoding} //= 'UTF-8';
Condition50%1/2
$self->{"encoding"} //= "UTF-8"
l!l
016
MC/DC0%0/1
$self->{"encoding"} //= "UTF-8"
$self->{"encoding"}
Truth table50%1/2
A
A= $self->{"encoding"}
Aresult
11
00
26  
27 16 ▶ $self->{connect}{nick} //= 'bot';
Condition100%2/2
$self->{"connect"}{"nick"} //= "bot"
l!l
412
MC/DC100%1/1
$self->{"connect"}{"nick"} //= "bot"
$self->{"connect"}{"nick"}
Truth table100%2/2
A
A= $self->{"connect"}{"nick"}
Aresult
11
00
28 16 ▶ $self->{connect}{name} //= 'Yet Another IRC Bot';
Condition100%2/2
$self->{"connect"}{"name"} //= "Yet Another IRC Bot"
l!l
412
MC/DC100%1/1
$self->{"connect"}{"name"} //= "Yet Another IRC Bot"
$self->{"connect"}{"name"}
Truth table100%2/2
A
A= $self->{"connect"}{"name"}
Aresult
11
00
29 16 ▶ $self->{connect}{port} ||= ( $self->{connect}{ssl} ) ? 6670 : 6667;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'connect'}{'ssl'} ? : 0 12 12
Condition66%2/3
$self->{"connect"}{"port"} ||= $self->{"connect"}{"ssl"} ? 6670 : 6667
l!l&&r!l&&!r
4120
MC/DC0%0/2
$self->{"connect"}{"port"} ||= $self->{"connect"}{"ssl"} ? 6670 : 6667
$self->{"connect"}{"port"} $self->{"connect"}{"ssl"} ? 6670 : 6667
Truth table66%2/3
A ||= B
A= $self->{"connect"}{"port"}B= $self->{"connect"}{"ssl"} ? 6670 : 6667
ABresult
1X1
011
000
30  
31 16 ▶ $self->{disconnect} //= sub {};
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$self->{"disconnect"} //= sub { }
l!l&&r!l&&!r
0160
MC/DC0%0/2
$self->{"disconnect"} //= sub { }
$self->{"disconnect"} sub { }
Truth table33%1/3
A //= B
A= $self->{"disconnect"}B= sub { }
ABresult
1X1
011
000
32  
33 16 ▶ $self->{daemon} //= {};
Condition100%2/2
$self->{"daemon"} //= {}
l!l
412
MC/DC100%1/1
$self->{"daemon"} //= {}
$self->{"daemon"}
Truth table100%2/2
A
A= $self->{"daemon"}
Aresult
11
00
34 16 ▶ $self->{daemon}{name} //= $self->{connect}{nick};
Condition66%2/3
$self->{"daemon"}{"name"} //= $self->{"connect"}{"nick"}
l!l&&r!l&&!r
4120
MC/DC0%0/2
$self->{"daemon"}{"name"} //= $self->{"connect"}{"nick"}
$self->{"daemon"}{"name"} $self->{"connect"}{"nick"}
Truth table66%2/3
A //= B
A= $self->{"daemon"}{"name"}B= $self->{"connect"}{"nick"}
ABresult
1X1
011
000
35 16 ▶ $self->{daemon}{pid_file} //= $self->{daemon}{name} . '.pid';
Condition100%2/2
$self->{"daemon"}{"pid_file"} //= $self->{"daemon"}{"name"} . '.pid'
l!l
412
MC/DC100%1/1
$self->{"daemon"}{"pid_file"} //= $self->{"daemon"}{"name"} . '.pid'
$self->{"daemon"}{"pid_file"}
Truth table100%2/2
A
A= $self->{"daemon"}{"pid_file"}
Aresult
11
00
36  
37 16 $self->{nick} = $self->{connect}{nick};
38  
39 16 $self->{hooks} = [];
40 16 $self->{ticks} = [];
41 16 $self->{helps} = {};
42 16 $self->{loaded} = {};
43 16 $self->{numerics} = [];
44  
45 16 ▶ $self->{send_user_nick} ||= 'on_parent';
Condition50%1/2
$self->{"send_user_nick"} ||= "on_parent"
l!l
016
MC/DC0%0/1
$self->{"send_user_nick"} ||= "on_parent"
$self->{"send_user_nick"}
Truth table50%1/2
A
A= $self->{"send_user_nick"}
Aresult
11
00
46 croak('"send_user_nick" optional value set to invalid value') if (
47 $self->{send_user_nick} ne 'on_connect' and
48 $self->{send_user_nick} ne 'on_parent' and
49 16 ▶ $self->{send_user_nick} ne 'on_reply'
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"send_user_nick"} ne "on_connect" and $self->{"send_user_nick"} ne "on_parent" and $self->{"send_user_nick"} ne "on_reply" 0 16 16
Condition33%2/6
$self->{"send_user_nick"} ne "on_connect" and $self->{"send_user_nick"} ne "on_parent" and $self->{"send_user_nick"} ne "on_reply"
!ll&&!rl&&r
1600
$self->{"send_user_nick"} ne "on_connect" and $self->{"send_user_nick"} ne "on_parent"
!ll&&!rl&&r
0160
MC/DC0%0/3
$self->{"send_user_nick"} ne "on_connect" and $self->{"send_user_nick"} ne "on_parent" and $self->{"send_user_nick"} ne "on_reply"
$self->{"send_user_nick"} ne "on_connect" $self->{"send_user_nick"} ne "on_parent" $self->{"send_user_nick"} ne "on_reply"
Truth table25%1/4
A and B and C
A= $self->{"send_user_nick"} ne "on_connect"B= $self->{"send_user_nick"} ne "on_parent"C= $self->{"send_user_nick"} ne "on_reply"
ABCresult
0XX0
10X0
1100
1111
50 );
51  
52 $self->load(
53 2 ( ref $self->{plugins} eq 'ARRAY' ) ? @{ $self->{plugins} } : $self->{plugins}
54 16 ▶ ) if ( $self->{plugins} );
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"plugins"} 2 14 16
ref $self->{'plugins'} eq 'ARRAY' ? : 2 0 2
55  
56 15 return $self;
57 }
58  
59 1 ▶sub run {
Subroutine run: called CC=6 SCAR=22.9
Pod documented
60 1 my $self = shift;
61 1 my $commands = \@_;
62  
63 $self->{socket} = ( ( $self->{connect}{ssl} ) ? 'IO::Socket::SSL' : 'IO::Socket::IP' )->new(
64 PeerAddr => $self->{connect}{server},
65 PeerPort => $self->{connect}{port},
66 Proto => 'tcp',
67 1 ▶ Family => ( $self->{connect}{ipv6} ? AF_INET6 : AF_INET ),
Branch: 3 branches
BranchTrueFalseTotal
$self->{"socket"} = ($self->{"connect"}{"ssl"} ? "IO::Socket::SSL" : "IO::Socket::IP")->new("PeerAddr", $self->{"connect"}{"server"}, "PeerPort", $self->{"connect"}{"port"}, "Proto", "tcp", "Family", $self->{"connect"}{"ipv6"} ? 10 : 2, "Type", 1, "SSL_verify_mode", 0) or die $! 1 0 1
$self->{'connect'}{'ssl'} ? : 0 1 1
$self->{'connect'}{'ipv6'} ? : 0 1 1
68 Type => SOCK_STREAM,
69 SSL_verify_mode => SSL_VERIFY_NONE,
70 ) or die $!;
71  
72 1 ▶ if ( $self->{send_user_nick} eq 'on_connect' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"send_user_nick"} eq "on_connect") 0 1 1
73 0 ▶ $self->{socket}->print("PASS $self->{connect}{password}\r\n") if ( $self->{connect}{password} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"connect"}{"password"} 0 0 0
74 0 $self->{socket}->print("NICK $self->{nick}\r\n");
75 0 $self->{socket}->print("USER $self->{nick} 0 * :$self->{connect}{name}\r\n");
76 }
77  
78 1 try {
79 $self->{device} = Daemon::Device->new(
80 parent => \&_parent,
81 child => \&_child,
82 on_message => \&_on_message,
83 spawn => $self->{spawn},
84 daemon => $self->{daemon},
85 data => {
86 self => $self,
87 commands => $commands,
88 passwd => $self->{passwd},
89 },
90 1 );
91 }
92 catch ($e) {
93 0 croak("Daemon device instantiation failure: $e");
94 }
95  
96 1 $self->{device}->run;
97 }
98  
99 4 ▶sub note {
Subroutine note: called CC=3 SCAR=13.0
Pod documented
100 4 my ( $self, $msg, $err ) = @_;
101 4 chomp($msg);
102 4 $msg = '[' . time2str( '%d/%b/%Y:%H:%M:%S %z', time() ) . '] ' . $msg . "\n";
103  
104 4 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) { } 0 4 4
105 0 ▶ die $msg if ( $err eq 'die' );
Branch: 1 branch
BranchTrueFalseTotal
if $err eq "die" 0 0 0
106 0 warn $msg;
107 }
108 else {
109 4 print decode( $self->{encoding}, $msg );
110 }
111  
112 4 return;
113 }
114  
115 0 ▶sub _parent {
Subroutine _parent: not called CC=22 SCAR=62.3
116 0 my ($device) = @_;
117 0 my $self = $device->data('self');
118 0 my $session = { start => time };
119 0 ▶ my $delegate = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
120 0 my $fresh_children = $device->children;
121 $session->{children} = $fresh_children if (
122 not $session->{children} or
123 0 ▶ join( ',', sort @{ $session->{children} } ) ne join( ',', sort @$fresh_children )
Branch: 1 branch
BranchTrueFalseTotal
if not $session->{"children"} or CORE::join(",", sort(@{$session->{"children"};})) ne CORE::join(",", sort(@$fresh_children)) 0 0 0
Condition0%0/3
not $session->{"children"} or CORE::join(",", sort(@{$session->{"children"};})) ne CORE::join(",", sort(@$fresh_children))
l!l&&r!l&&!r
000
MC/DC0%0/2
not $session->{"children"} or CORE::join(",", sort(@{$session->{"children"};})) ne CORE::join(",", sort(@$fresh_children))
not $session->{"children"} CORE::join(",", sort(@{$session->{"children"};})) ne CORE::join(",", sort(@$fresh_children))
Truth table0%0/3
not(A) or B
A= not $session->{"children"}B= CORE::join(",", sort(@{$session->{"children"};})) ne CORE::join(",", sort(@$fresh_children))
ABresult
1X1
011
000
124 );
125 0 push( @{ $session->{children} }, shift @{ $session->{children} } );
126 0 $device->message( $session->{children}->[0], @_ );
127 0 };
128 0 ▶ my $broadcast = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
129 0 my @messages = @_;
130 0 $device->message( $_, @messages ) for ( @{ $device->children } );
131 0 };
132  
133 0 ▶ local $SIG{ALRM} = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
134 0 alarm 1;
135 0 my $time = time;
136  
137 0 for (
138 grep {
139 ref $_->{timing} and ( $time % 60 == 0 ) and $_->{timing}->match($time) or
140 0 ▶ not ref $_->{timing} and ( ( $time - $session->{start} ) % $_->{timing} == 0 )
Condition0%0/12
ref $_->{'timing'} && $time % 60 == 0 && $_->{'timing'}->match($time) || !ref($_->{'timing'}) && ($time - $session->{'start'}) % $_->{'timing'} == 0
l!l&&r!l&&!r
000
ref $_->{"timing"} and $time % 60 == 0 and $_->{"timing"}->match($time)
!ll&&!rl&&r
000
ref $_->{"timing"} and $time % 60 == 0
!ll&&!rl&&r
000
not ref $_->{"timing"} and ($time - $session->{"start"}) % $_->{"timing"} == 0
!ll&&!rl&&r
000
MC/DC0%0/5
ref $_->{'timing'} && $time % 60 == 0 && $_->{'timing'}->match($time) || !ref($_->{'timing'}) && ($time - $session->{'start'}) % $_->{'timing'} == 0
ref $_->{"timing"} $time % 60 == 0 $_->{"timing"}->match($time) not ref $_->{"timing"} ($time - $session->{"start"}) % $_->{"timing"} == 0
Truth table0%0/10
A and B and C || not(D) and E
A= ref $_->{"timing"}B= $time % 60 == 0C= $_->{"timing"}->match($time)D= not ref $_->{"timing"}E= ($time - $session->{"start"}) % $_->{"timing"} == 0
ABCDEresult
111XX1
0XX111
10X111
110111
0XX0X0
0XX100
10X0X0
10X100
1100X0
110100
141 0 } @{ $self->{ticks} }
142 ) {
143 0 try {
144 0 $_->{code}->($self);
145 }
146 catch ($e) {
147 0 warn "Tick execution failure: $e\n";
148 }
149 }
150 0 };
151  
152 0 ▶ local $SIG{__WARN__} = sub { note( undef, $_[0], 'warn' ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
153 0 ▶ local $SIG{__DIE__} = sub { note( undef, $_[0], 'die' ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
154  
155 0 my @lines;
156  
157 0 try {
158 0 ▶ if ( $self->{send_user_nick} eq 'on_parent' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"send_user_nick"} eq "on_parent") 0 0 0
159 0 ▶ if ( $self->{connect}{password} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"connect"}{"password"}) 0 0 0
160 0 $self->{socket}->print("PASS $self->{connect}{password}\r\n");
161 0 $self->note("<<< PASS ********");
162 }
163 0 $self->say("NICK $self->{nick}");
164 0 $self->say("USER $self->{nick} 0 * :$self->{connect}{name}");
165 }
166  
167 0 ▶ while ( my $line = $self->{socket}->getline ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $self->{"socket"}->getline) 0 0 0
168 0 $line =~ s/\003\d{2}(?:,\d{2})?//g; # remove IRC color codes
169 0 $line =~ tr/\000-\037//d; # remove all control characters
170  
171 0 $self->note($line);
172 0 chomp($line);
173  
174 0 ▶ if ( not $session->{established} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session->{"established"}) 0 0 0
175 0 ▶ if ( not $session->{user} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session->{"user"}) 0 0 0
176 0 ▶ if ( $self->{send_user_nick} eq 'on_reply' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'send_user_nick'} eq 'on_reply') { } 0 0 0
elsif ($self->{'send_user_nick'} eq 'on_connect') { } 0 0 0
177 0 ▶ if ( $self->{connect}{password} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"connect"}{"password"}) 0 0 0
178 0 $self->{socket}->print("PASS $self->{connect}{password}\r\n");
179 0 $self->note("<<< PASS ********");
180 }
181 0 $self->say("NICK $self->{nick}");
182 0 $self->say("USER $self->{nick} 0 * :$self->{connect}{name}");
183 }
184 elsif ( $self->{send_user_nick} eq 'on_connect' ) {
185 0 ▶ $self->note("<<< PASS ********") if ( $self->{connect}{password} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"connect"}{"password"} 0 0 0
186 0 $self->note("<<< NICK $self->{nick}\r\n");
187 0 $self->note("<<< USER $self->{nick} 0 * :$self->{connect}{name}\r\n");
188 }
189 0 $session->{user} = 1;
190 }
191 0 ▶ if ( $line =~ /^ERROR.+onnect\w+ too fast/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($line =~ /^ERROR.+onnect\w+ too fast/u) { } 0 0 0
elsif ($line =~ /^ERROR\s/u) { } 0 0 0
elsif ($line =~ /^:\S+\s433\s/u) { } 0 0 0
elsif ($line =~ /^:\S+\s001\s/u) { } 0 0 0
192 0 warn "$line\n";
193 0 warn "Sleeping 20 and retrying...\n";
194 0 sleep 20;
195 0 $device->daemon->do_restart;
196 }
197 elsif ( $line =~ /^ERROR\s/ ) {
198 0 warn "$line\n";
199 0 $device->daemon->do_stop;
200 }
201 elsif ( $line =~ /^:\S+\s433\s/ ) {
202 0 $self->nick( $self->{nick} . '_' );
203 }
204 elsif ( $line =~ /^:\S+\s001\s/ ) {
205 0 $self->say($_) for ( map {
206 0 my $command = $_;
207 0 $command =~ s|^/msg |PRIVMSG |;
208 0 $command =~ s|^/(\w+)|uc($1)|e;
209 0 $command;
210 0 } @{ $device->data('commands') } );
211  
212 0 $self->join;
213 0 $session->{established} = 1;
214 0 ▶ alarm 1 if ( @{ $self->{ticks} } );
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"ticks"};} 0 0 0
215 }
216 }
217  
218 0 ▶ shift @lines while ( @lines > 10 );
Branch: 1 branch
BranchTrueFalseTotal
@lines > 10 and do { shift @lines } 0 0 0
219 0 my $now = time();
220  
221 0 ▶ unless ( grep { $_->{line} eq $line and $_->{time} + 1 > $now } @lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_->{'line'} eq $line and $_->{'time'} + 1 > $now;} @lines) { } 0 0 0
Condition0%0/3
$_->{'line'} eq $line && $_->{'time'} + 1 > $now
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{'line'} eq $line && $_->{'time'} + 1 > $now
$_->{'line'} eq $line $_->{'time'} + 1 > $now
Truth table0%0/3
A && B
A= $_->{'line'} eq $lineB= $_->{'time'} + 1 > $now
ABresult
0X0
100
111
222 0 ▶ unless ( $line =~ /^:\S+\s\d{3}\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^:\S+\s\d{3}\s/u) { } 0 0 0
223 0 $delegate->($line);
224 }
225 else {
226 0 $broadcast->($line);
227 }
228 }
229 else {
230 0 $self->note("### Skipped repeated line: $line");
231 }
232  
233 0 push @lines, { line => $line, time => $now };
234 }
235 }
236 catch ($e) {
237 0 warn "Daemon parent loop failure: $e\n";
238 }
239  
240 0 kill( 'KILL', $_ ) for ( @{ $device->children } );
241 0 ▶ $self->{disconnect}->($self) if ( ref $self->{disconnect} eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"disconnect"} eq "CODE" 0 0 0
242 }
243  
244 0 ▶sub _child {
Subroutine _child: not called CC=1 SCAR=6.9
245 0 ▶ local $SIG{__WARN__} = sub { note( undef, $_[0], 'warn' ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
246 0 ▶ local $SIG{__DIE__} = sub { note( undef, $_[0], 'die' ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
247  
248 0 sleep 1 while (1);
249 }
250  
251 0 ▶sub _on_message {
Subroutine _on_message: not called CC=42 SCAR=75.0
252 0 my $device = shift;
253 0 my $self = $device->data('self');
254 0 my $passwd = $device->data('passwd');
255 0 my $ppid = $device->ppid;
256  
257 0 for my $line (@_) {
258 0 ▶ if ( $ppid == $$ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ppid == $$) 0 0 0
259 0 $self->{socket}->print( $line . "\r\n" );
260 0 next;
261 }
262  
263 0 push( @{ $self->{numerics} }, $line )
264 0 ▶ if ( $line =~ /^:\S+\s\d{3}\s/ and @{ $self->{numerics} } < 100 );
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^:\S+\s\d{3}\s/u and @{$self->{"numerics"};} < 100 0 0 0
Condition0%0/3
$line =~ /^:\S+\s\d{3}\s/u and @{$self->{"numerics"};} < 100
!ll&&!rl&&r
000
MC/DC0%0/2
$line =~ /^:\S+\s\d{3}\s/u and @{$self->{"numerics"};} < 100
$line =~ /^:\S+\s\d{3}\s/u @{$self->{"numerics"};} < 100
Truth table0%0/3
A and B
A= $line =~ /^:\S+\s\d{3}\s/uB= @{$self->{"numerics"};} < 100
ABresult
0X0
100
111
265  
266 0 ▶ if ( $line =~ /^>>>\sNICK\s(.*)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^>>>\sNICK\s(.*)/u) { } 0 0 0
elsif ($line =~ /^:\S+\s433\s/u) { } 0 0 0
267 0 $self->{nick} = $1;
268 0 next;
269 }
270 elsif ( $line =~ /^:\S+\s433\s/ ) {
271 0 $self->nick( $self->{nick} . '_' );
272 0 next;
273 }
274  
275 0 $self->{in} = { map { $_ => '' } qw( line source nick user server command forum text ) };
276 0 $self->{in}{$_} = 0 for ( qw( private to_me ) );
277 0 $self->{in}{line} = $line;
278  
279 0 ▶ if ( $line =~ /^(ERROR)\s/ ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($line =~ /^(ERROR)\s/u) { } 0 0 0
elsif ($line =~ /^:(\S+?)!~?(\S+?)@(\S+?)\s(\S+)\s(\S+)\s:(.*)/u) { } 0 0 0
elsif ($line =~ /^:(\S+?)!~?(\S+?)@(\S+?)\s(\S+)\s:(.*)/u) { } 0 0 0
elsif ($line =~ /^:(\S+?)!~?(\S+?)@(\S+?)\s(\S+)\s(\S+)\s(.*)/u) { } 0 0 0
elsif ($line =~ /^:(\S+?)!~?(\S+?)@(\S+?)\s(\S+)\s(\S+)/u) { } 0 0 0
elsif ($line =~ /^(PING)\s(.+)/u) { } 0 0 0
elsif ($line =~ /^:(\S+)\s([A-Z]+|\d+)\s(\S+)\s(.*)/u) { } 0 0 0
280 0 warn $line . "\n";
281 }
282 elsif ( $line =~ /^:(\S+?)!~?(\S+?)@(\S+?)\s(\S+)\s(\S+)\s:(.*)/ ) {
283 0 @{ $self->{in} }{ qw( nick user server command forum text ) } = ( $1, $2, $3, $4, $5, $6 );
284 0 $self->{in}{full_text} = $self->{in}{text};
285 }
286 elsif ( $line =~ /^:(\S+?)!~?(\S+?)@(\S+?)\s(\S+)\s:(.*)/ ) {
287 0 @{ $self->{in} }{ qw( nick user server command text ) } = ( $1, $2, $3, $4, $5 );
288 ( $self->{in}{forum} = $self->{in}{text} ) =~ s/^://
289 0 ▶ if ( $self->{in}{command} eq 'JOIN' or $self->{in}{command} eq 'PART' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"in"}{"command"} eq "JOIN" or $self->{"in"}{"command"} eq "PART" 0 0 0
Condition0%0/3
$self->{"in"}{"command"} eq "JOIN" or $self->{"in"}{"command"} eq "PART"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"in"}{"command"} eq "JOIN" or $self->{"in"}{"command"} eq "PART"
$self->{"in"}{"command"} eq "JOIN" $self->{"in"}{"command"} eq "PART"
Truth table0%0/3
A or B
A= $self->{"in"}{"command"} eq "JOIN"B= $self->{"in"}{"command"} eq "PART"
ABresult
1X1
011
000
290 }
291 elsif ( $line =~ /^:(\S+?)!~?(\S+?)@(\S+?)\s(\S+)\s(\S+)\s(.*)/ ) {
292 0 @{ $self->{in} }{ qw( nick user server command forum text ) } = ( $1, $2, $3, $4, $5, $6 );
293 }
294 elsif ( $line =~ /^:(\S+?)!~?(\S+?)@(\S+?)\s(\S+)\s(\S+)/ ) {
295 0 @{ $self->{in} }{ qw( nick user server command forum ) } = ( $1, $2, $3, $4, $5, $6 );
296 }
297 elsif ( $line =~ /^(PING)\s(.+)/ ) {
298 0 @{ $self->{in} }{ qw( command text ) } = ( $1, $2 );
299 0 $self->say( 'PONG ' . $self->{in}{text} );
300 0 next;
301 }
302 elsif ( $line =~ /^:(\S+)\s([A-Z]+|\d+)\s(\S+)\s(.*)/ ) {
303 0 @{ $self->{in} }{ qw( source command forum text ) } = ( $1, $2, $3, $4 );
304 }
305 else {
306 0 warn 'Unparsed line (probably a bug in Bot::IRC; please report it): ', $line . "\n";
307 }
308  
309 0 ▶ next unless ( $self->{in}{nick} ne $self->{nick} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"in"}{"nick"} ne $self->{"nick"} 0 0 0
310  
311 0 ▶ if ( $self->{in}{command} eq 'PRIVMSG' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"in"}{"command"} eq "PRIVMSG") 0 0 0
312 0 ▶ $self->{in}{private} = 1 if ( $self->{in}{forum} and $self->{in}{forum} eq $self->{nick} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"in"}{"forum"} and $self->{"in"}{"forum"} eq $self->{"nick"} 0 0 0
Condition0%0/3
$self->{"in"}{"forum"} and $self->{"in"}{"forum"} eq $self->{"nick"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"in"}{"forum"} and $self->{"in"}{"forum"} eq $self->{"nick"}
$self->{"in"}{"forum"} $self->{"in"}{"forum"} eq $self->{"nick"}
Truth table0%0/3
A and B
A= $self->{"in"}{"forum"}B= $self->{"in"}{"forum"} eq $self->{"nick"}
ABresult
0X0
100
111
313 $self->{in}{to_me} = 1 if (
314 $self->{in}{text} =~ s/^\s*\b$self->{nick}\b[\s\W]*//i or
315 $self->{in}{text} =~ s/[\s\W]*\b$self->{nick}\b[\s\W]*$//i or
316 $self->{in}{private}
317 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"in"}{"text"} =~ s/^\s*\b$self->{"nick"}\b[\s\W]*//iu or $self->{"in"}{"text"} =~ s/[\s\W]*\b$self->{"nick"}\b[\s\W]*$//iu or $self->{"in"}{"private"} 0 0 0
Condition0%0/6
$self->{"in"}{"text"} =~ s/^\s*\b$self->{"nick"}\b[\s\W]*//iu or $self->{"in"}{"text"} =~ s/[\s\W]*\b$self->{"nick"}\b[\s\W]*$//iu or $self->{"in"}{"private"}
l!l&&r!l&&!r
000
$self->{"in"}{"text"} =~ s/^\s*\b$self->{"nick"}\b[\s\W]*//iu or $self->{"in"}{"text"} =~ s/[\s\W]*\b$self->{"nick"}\b[\s\W]*$//iu
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"in"}{"text"} =~ s/^\s*\b$self->{"nick"}\b[\s\W]*//iu or $self->{"in"}{"text"} =~ s/[\s\W]*\b$self->{"nick"}\b[\s\W]*$//iu or $self->{"in"}{"private"}
$self->{"in"}{"text"} =~ s/^\s*\b$self->{"nick"}\b[\s\W]*//iu $self->{"in"}{"text"} =~ s/[\s\W]*\b$self->{"nick"}\b[\s\W]*$//iu $self->{"in"}{"private"}
Truth table0%0/4
A or B or C
A= $self->{"in"}{"text"} =~ s/^\s*\b$self->{"nick"}\b[\s\W]*//iuB= $self->{"in"}{"text"} =~ s/[\s\W]*\b$self->{"nick"}\b[\s\W]*$//iuC= $self->{"in"}{"private"}
ABCresult
1XX1
01X1
0011
0000
318 }
319  
320 0 ▶ if ( $self->{in}{to_me} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"in"}{"to_me"}) 0 0 0
321 0 ▶ if ( $self->{in}{text} =~ /^\s*help\W*$/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'in'}{'text'} =~ /^\s*help\W*$/iu) { } 0 0 0
elsif ($self->{'in'}{'text'} =~ /^\s*help\s+(.+?)\W*$/iu) { } 0 0 0
elsif ($self->{'in'}{'text'} =~ /Sorry. I don't understand./u) { } 0 0 0
322 0 my @sorted_key_helps = sort keys %{ $self->{helps} };
323 0 ▶ $self->reply_to(
Branch: 1 branch
BranchTrueFalseTotal
@sorted_key_helps ? : 0 0 0
324 (@sorted_key_helps)
325 ?
326 'Ask me for help with "help topic" where the topic is one of the following: ' .
327 $self->list( ', ', 'and', @sorted_key_helps ) . '.'
328 : 'I have no help topics from which to provide you help.'
329 );
330 0 next;
331 }
332 elsif ( $self->{in}{text} =~ /^\s*help\s+(.+?)\W*$/i ) {
333 $self->reply_to(
334 0 ▶ ( $self->{helps}{$1} || "Couldn't find the help topic: $1." )
Condition0%0/2
$self->{'helps'}{$1} || "Couldn't find the help topic: $1."
l!l
00
MC/DC0%0/1
$self->{'helps'}{$1} || "Couldn't find the help topic: $1."
$self->{'helps'}{$1}
Truth table0%0/2
A
A= $self->{'helps'}{$1}
Aresult
11
00
335 );
336 0 next;
337 }
338 elsif ( $self->{in}{text} =~ /Sorry. I don't understand./ ) {
339 0 next;
340 }
341 }
342  
343 0 hook: for my $hook (
344 0 @{ $self->{hooks} },
345  
346 {
347 when => {
348 to_me => 1,
349 text => qr/^\s*cmd\s+(?<passwd>\S+)\s+(?<cmd>.+)$/i,
350 },
351 0 ▶ code => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
352 0 my ( $bot, $in, $m ) = @_;
353  
354 0 ▶ if ( $m->{passwd} and $passwd and $m->{passwd} eq $passwd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{"passwd"} and $passwd and $m->{"passwd"} eq $passwd) 0 0 0
Condition0%0/6
$m->{"passwd"} and $passwd and $m->{"passwd"} eq $passwd
!ll&&!rl&&r
000
$m->{"passwd"} and $passwd
!ll&&!rl&&r
000
MC/DC0%0/3
$m->{"passwd"} and $passwd and $m->{"passwd"} eq $passwd
$m->{"passwd"} $passwd $m->{"passwd"} eq $passwd
Truth table0%0/4
A and B and C
A= $m->{"passwd"}B= $passwdC= $m->{"passwd"} eq $passwd
ABCresult
0XX0
10X0
1100
1111
355 0 $bot->say($_) for (
356 map {
357 0 my $command = $_;
358 0 $command =~ s|^/msg |PRIVMSG |;
359 0 $command =~ s|^/(\w+)|uc($1)|e;
360 0 $command;
361 } split( /\s*;\s*/, $m->{cmd} )
362 );
363 }
364  
365 0 return 1;
366 },
367 },
368  
369 {
370 when => {
371 full_text => qr/^\s*$self->{nick}\s*[!\?]\W*$/i,
372 },
373 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
374 0 my ($bot) = @_;
375 0 $bot->reply_to('Yes?');
376 },
377 },
378  
379 {
380 when => {
381 to_me => 1,
382 text => qr/^(?<word>hello|greetings|hi|good\s+\w+)\W*$/i,
383 },
384 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
385 0 my ( $bot, $in, $m ) = @_;
386 0 $bot->reply_to( ucfirst( lc( $m->{word} ) ) . '.' );
387 },
388 },
389  
390 ( map {
391 {
392 when => $_,
393 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
394 0 my ($bot) = @_;
395 0 $bot->reply_to(qq{Sorry. I don't understand. (Try "$self->{nick} help" for help.)});
396 },
397 },
398 0 } (
399 {
400 private => 0,
401 full_text => qr/^\s*$self->{nick}\s*[,:\->~=]/i,
402 },
403 {
404 private => 1,
405 },
406 ) ),
407  
408 ) {
409 0 my $captured_matches = {};
410  
411 0 for my $type ( keys %{ $hook->{when} } ) {
412 next hook unless (
413 ref( $hook->{when}{$type} ) eq 'Regexp' and
414 $self->{in}{$type} and $self->{in}{$type} =~ $hook->{when}{$type} or
415 ref( $hook->{when}{$type} ) eq 'CODE' and $hook->{when}{$type}->(
416 $self,
417 $self->{in}{$type},
418 0 ▶ { %{ $self->{in} } },
Condition0%0/6
defined $self->{"in"}{$type} and defined $hook->{"when"}{$type} and $self->{"in"}{$type} eq $hook->{"when"}{$type}
!ll&&!rl&&r
000
defined $self->{"in"}{$type} and defined $hook->{"when"}{$type}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{"in"}{$type} and defined $hook->{"when"}{$type} and $self->{"in"}{$type} eq $hook->{"when"}{$type}
defined $self->{"in"}{$type} defined $hook->{"when"}{$type} $self->{"in"}{$type} eq $hook->{"when"}{$type}
Truth table0%0/4
A and B and C
A= defined $self->{"in"}{$type}B= defined $hook->{"when"}{$type}C= $self->{"in"}{$type} eq $hook->{"when"}{$type}
ABCresult
0XX0
10X0
1100
1111
419 ) or
420 (
421 defined $self->{in}{$type} and defined $hook->{when}{$type} and
422 0 ▶ $self->{in}{$type} eq $hook->{when}{$type}
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hook->{"when"}{$type} eq "Regexp" and $self->{"in"}{$type} and $self->{"in"}{$type} =~ /$hook->{"when"}{$type}/u or ref $hook->{"when"}{$type} eq "CODE" and $hook->{"when"}{$type}->($self, $self->{"in"}{$type}, {%{$self->{"in"};}}) or defined $self->{"in"}{$type} and defined $hook->{"when"}{$type} and $self->{"in"}{$type} eq $hook->{"when"}{$type} 0 0 0
Condition0%0/15
ref $hook->{"when"}{$type} eq "Regexp" and $self->{"in"}{$type} and $self->{"in"}{$type} =~ /$hook->{"when"}{$type}/u or ref $hook->{"when"}{$type} eq "CODE" and $hook->{"when"}{$type}->($self, $self->{"in"}{$type}, {%{$self->{"in"};}}) or defined $self->{"in"}{$type} and defined $hook->{"when"}{$type} and $self->{"in"}{$type} eq $hook->{"when"}{$type}
l!l&&r!l&&!r
000
ref $hook->{"when"}{$type} eq "Regexp" and $self->{"in"}{$type} and $self->{"in"}{$type} =~ /$hook->{"when"}{$type}/u or ref $hook->{"when"}{$type} eq "CODE" and $hook->{"when"}{$type}->($self, $self->{"in"}{$type}, {%{$self->{"in"};}})
l!l&&r!l&&!r
000
ref $hook->{"when"}{$type} eq "Regexp" and $self->{"in"}{$type} and $self->{"in"}{$type} =~ /$hook->{"when"}{$type}/u
!ll&&!rl&&r
000
ref $hook->{"when"}{$type} eq "Regexp" and $self->{"in"}{$type}
!ll&&!rl&&r
000
ref $hook->{"when"}{$type} eq "CODE" and $hook->{"when"}{$type}->($self, $self->{"in"}{$type}, {%{$self->{"in"};}})
!ll&&!rl&&r
000
MC/DC0%0/6
ref $hook->{"when"}{$type} eq "Regexp" and $self->{"in"}{$type} and $self->{"in"}{$type} =~ /$hook->{"when"}{$type}/u or ref $hook->{"when"}{$type} eq "CODE" and $hook->{"when"}{$type}->($self, $self->{"in"}{$type}, {%{$self->{"in"};}}) or defined $self->{"in"}{$type} and defined $hook->{"when"}{$type} and $self->{"in"}{$type} eq $hook->{"when"}{$type}
ref $hook->{"when"}{$type} eq "Regexp" $self->{"in"}{$type} $self->{"in"}{$type} =~ /$hook->{"when"}{$type}/u ref $hook->{"when"}{$type} eq "CODE" $hook->{"when"}{$type}->($self, $self->{"in"}{$type}, {%{$self->{"in"};}}) defined $self->{"in"}{$type} and defined $hook->{"when"}{$type} and $self->{"in"}{$type} eq $hook->{"when"}{$type}
Truth table0%0/16
A and B and C or D and E or F
A= ref $hook->{"when"}{$type} eq "Regexp"B= $self->{"in"}{$type}C= $self->{"in"}{$type} =~ /$hook->{"when"}{$type}/uD= ref $hook->{"when"}{$type} eq "CODE"E= $hook->{"when"}{$type}->($self, $self->{"in"}{$type}, {%{$self->{"in"};}})F= defined $self->{"in"}{$type} and defined $hook->{"when"}{$type} and $self->{"in"}{$type} eq $hook->{"when"}{$type}
ABCDEFresult
111XXX1
0XX11X1
10X11X1
11011X1
0XX0X11
0XX1011
10X0X11
10X1011
1100X11
1101011
0XX0X00
0XX1000
10X0X00
10X1000
1100X00
1101000
423 )
424 );
425  
426 0 ▶ $captured_matches = { %$captured_matches, %+ } if ( keys %+ );
Branch: 1 branch
BranchTrueFalseTotal
if keys %+ 0 0 0
427 }
428  
429 0 my $rv;
430 0 try {
431 $rv = $hook->{code}->(
432 $self,
433 0 { %{ $self->{in} } },
434 $captured_matches,
435 );
436 }
437 catch ($e) {
438 0 warn "Plugin hook execution failure: $e\n";
439 }
440  
441 0 ▶ last if ($rv);
Branch: 1 branch
BranchTrueFalseTotal
if $rv 0 0 0
442 }
443 }
444 }
445  
446 7 ▶sub load {
Subroutine load: called CC=14 SCAR=29.0
Pod documented
447 7 my $self = shift;
448  
449 7 for my $plugin (@_) {
450 7 ▶ unless ( ref $plugin ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plugin) { } 0 7 7
451 7 ▶ if ( $plugin =~ /^:core$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin =~ /^:core$/iu) 0 7 7
452 0 $self->load(
453 'Ping',
454 'Join',
455 'Seen',
456 'Greeting',
457 'Infobot',
458 'Functions',
459 'Convert',
460 'Karma',
461 'Math',
462 'History',
463 );
464 0 next;
465 }
466  
467 7 my $namespace;
468 7 for (
469 $plugin,
470 __PACKAGE__ . "::Y::$plugin",
471 __PACKAGE__ . "::X::$plugin",
472 __PACKAGE__ . "::$plugin",
473 ) {
474 22 ( my $path = $_ ) =~ s|::|/|g;
475  
476 22 eval "require $_";
477 22 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 16 6 22
478 6 $namespace = $_;
479 6 last;
480 }
481 else {
482 16 ▶ croak("Plugin load failure: $@") unless ( $@ =~ /^Can't locate $path/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $@ =~ /^Can't locate $path/u 0 16 16
483 }
484 }
485 7 ▶ croak("Unable to find or properly load $plugin") unless ($namespace);
Branch: 1 branch
BranchTrueFalseTotal
unless $namespace 1 6 7
486  
487 6 ▶ next if ( $self->{loaded}{$namespace} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"loaded"}{$namespace} 0 6 6
488  
489 6 ▶ $namespace->import if ( $namespace->can('import') );
Branch: 1 branch
BranchTrueFalseTotal
if $namespace->can("import") 6 0 6
490 6 ▶ croak("$namespace does not implement init()") unless ( $namespace->can('init') );
Branch: 1 branch
BranchTrueFalseTotal
unless $namespace->can("init") 0 6 6
491  
492 6 eval "${namespace}::init(\$self)";
493 6 ▶ die("Plugin init failure: $@\n") if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 6 6
494  
495 6 $self->{loaded}{$namespace} = time;
496 }
497 else {
498 0 $self->$_( @{ $plugin->{$_} } ) for ( qw( hooks ticks ) );
499 0 $self->$_( $plugin->{$_} ) for ( qw( helps subs ) );
500 }
501 }
502  
503 6 return $self;
504 }
505  
506 1 ▶sub reload {
Subroutine reload: called CC=2 SCAR=6.9
Pod documented
507 1 my $self = shift;
508 1 delete $self->{loaded}{$_} for (@_);
509 1 return $self->load(@_);
510 }
511  
512 3 ▶sub hook {
Subroutine hook: called CC=4 SCAR=14.8
Pod documented
513 3 my ( $self, $when, $code, $attr ) = @_;
514  
515 push(
516 3 ▶ @{ $self->{hooks} },
Condition100%2/2
$attr // {}
l!l
12
MC/DC100%1/1
$attr // {}
$attr
Truth table100%2/2
A
A= $attr
Aresult
11
00
517 {
518 when => $when,
519 code => $code,
520 attr => ( $attr // {} ),
521 },
522 );
523  
524 0 ▶ $self->subs( %{ $attr->{subs} } ) if ( ref $attr->{subs} eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $attr->{"subs"} eq "HASH" 0 3 3
525 0 ▶ $self->helps( %{ $attr->{helps} } ) if ( ref $attr->{helps} eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $attr->{"helps"} eq "HASH" 0 3 3
526  
527 3 return $self;
528 }
529  
530 1 ▶sub hooks {
Subroutine hooks: called CC=2 SCAR=6.9
Pod documented
531 1 my $self = shift;
532 1 $self->hook(@$_) for (@_);
533 1 return $self;
534 }
535  
536 10 ▶sub helps {
Subroutine helps: called CC=1 SCAR=0.0
Pod documented
537 10 my ( $self, @input ) = @_;
538  
539 10 try {
540 10 $self->{helps} = { %{ $self->{helps} }, @input };
541 }
542 catch ($e) {
543 0 $self->note('Plugin helps called but not properly implemented');
544 }
545  
546 10 return $self;
547 }
548  
549 3 ▶sub tick {
Subroutine tick: called CC=2 SCAR=7.0
Pod documented
550 3 my ( $self, $timing, $code ) = @_;
551  
552 3 ▶ push( @{ $self->{ticks} }, {
Branch: 1 branch
BranchTrueFalseTotal
$timing =~ /^\d+$/u ? : 3 0 3
553 timing => ( $timing =~ /^\d+$/ ) ? $timing : Time::Crontab->new($timing),
554 code => $code,
555 } );
556 3 return $self;
557 }
558  
559 1 ▶sub ticks {
Subroutine ticks: called CC=2 SCAR=6.9
Pod documented
560 1 my $self = shift;
561 1 $self->tick(@$_) for (@_);
562 1 return $self;
563 }
564  
565 9 ▶sub subs {
Subroutine subs: called CC=3 SCAR=11.1
Pod documented
566 9 my $self = shift;
567  
568 9 ▶ if ( @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 0 9 9
569 0 $self->note('Plugin helps called but not properly implemented');
570 0 return $self;
571 }
572  
573 9 my $subs = {@_};
574  
575 9 for my $name ( keys %$subs ) {
576 14 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
577 14 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
578 10 *{ __PACKAGE__ . '::' . $name } = $subs->{$name};
579 }
580  
581 9 return $self;
582 }
583  
584 2 ▶sub register {
Subroutine register: called CC=2 SCAR=6.9
Pod documented
585 2 my $self = shift;
586 2 $self->{loaded}{$_} = time for (@_);
587 2 return $self;
588 }
589  
590 4 ▶sub vars {
Subroutine vars: called CC=3 SCAR=11.1
Pod documented
591 4 my ( $self, $name ) = @_;
592 4 ▶ ( $name = lc( substr( ( caller() )[0], length(__PACKAGE__) + 2 ) ) ) =~ s/::/\-/g unless ($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 2 4
593 4 ▶ return ( defined $self->{vars}{$name} ) ? $self->{vars}{$name} : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'vars'}{$name} ? : 0 4 4
594 }
595  
596 1 ▶sub settings {
Subroutine settings: called CC=2 SCAR=7.2
Pod documented
597 1 my ( $self, $name ) = @_;
598 1 ▶ return ( defined $name ) ? $self->{$name} : { %$self };
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 1 0 1
599 }
600  
601 1 ▶sub reply {
Subroutine reply: called CC=3 SCAR=13.3
Pod documented
602 1 my ( $self, $message ) = @_;
603  
604 1 ▶ if ( $self->{in}{forum} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'in'}{'forum'}) { } 0 1 1
605 $self->msg(
606 0 ▶ ( ( $self->{in}{forum} eq $self->{nick} ) ? $self->{in}{nick} : $self->{in}{forum} ),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'in'}{'forum'} eq $self->{'nick'} ? : 0 0 0
607 $message,
608 );
609 }
610 else {
611 1 warn "Didn't have a target to send reply to.\n";
612 }
613 1 return $self;
614 }
615  
616 0 ▶sub reply_to {
Subroutine reply_to: not called CC=2 SCAR=17.9
Pod documented
617 0 my ( $self, $message ) = @_;
618 0 ▶ return $self->reply( ( ( not $self->{in}{private} ) ? "$self->{in}{nick}: " : '' ) . $message );
Branch: 1 branch
BranchTrueFalseTotal
!$self->{'in'}{'private'} ? : 0 0 0
619 }
620  
621 1 ▶sub msg {
Subroutine msg: called CC=2 SCAR=7.1
Pod documented
622 1 my ( $self, $target, $message ) = @_;
623 1 ▶ $self->say( "PRIVMSG $target :" . ( ( $message =~ s/^\/me\s+// ) ? "\001ACTION $message\001" : $message ) );
Branch: 1 branch
BranchTrueFalseTotal
$message =~ s[^/me\s+][]u ? : 0 1 1
624 1 return $self;
625 }
626  
627 3 ▶sub say {
Subroutine say: called CC=5 SCAR=16.7
Pod documented
628 3 my $self = shift;
629 3 my $device = $self->{device};
630 3 ▶ my $ppid = ($device) ? $device->ppid : 0;
Branch: 1 branch
BranchTrueFalseTotal
$device ? : 3 0 3
631  
632 3 for (@_) {
633 4 my $string = $_;
634 4 ▶ if ( $ppid == $$ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ppid == $$) { } 0 4 4
635 0 $self->{socket}->print( $string . "\r\n" );
636 }
637 else {
638 4 $string = encode( $self->{encoding}, $string );
639 4 ▶ $device->message( $ppid, $string ) if $device;
Branch: 1 branch
BranchTrueFalseTotal
if $device 4 0 4
640 }
641 4 $self->note("<<< $string");
642 }
643 3 return $self;
644 }
645  
646 1 ▶sub nick {
Subroutine nick: called CC=3 SCAR=11.0
Pod documented
647 1 my ( $self, $nick ) = @_;
648  
649 1 ▶ if ($nick) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nick) 1 0 1
650 1 $self->{nick} = $nick;
651 $self->{device}->message( $_, ">>> NICK $self->{nick}" )
652 1 for ( grep { $_ != $$ } $self->{device}->ppid, @{ $self->{device}->children } );
653 1 $self->say("NICK $self->{nick}");
654 }
655 1 return $self->{nick};
656 }
657  
658 0 ▶sub join {
Subroutine join: not called CC=5 SCAR=34.0
Pod documented
659 0 my $self = shift;
660  
661 0 ▶ $self->say("JOIN $_") for (
Branch: 2 branches
BranchTrueFalseTotal
!@_ && $self->{'connect'}{'join'} ? : 0 0 0
ref $self->{'connect'}{'join'} eq 'ARRAY' ? : 0 0 0
Condition0%0/3
not @_ and $self->{"connect"}{"join"}
!ll&&!rl&&r
000
MC/DC0%0/2
not @_ and $self->{"connect"}{"join"}
not @_ $self->{"connect"}{"join"}
Truth table0%0/3
not(A) and B
A= not @_B= $self->{"connect"}{"join"}
ABresult
0X0
100
111
662 ( not @_ and $self->{connect}{join} )
663 ? (
664 ( ref $self->{connect}{join} eq 'ARRAY' )
665 0 ? @{ $self->{connect}{join} }
666 : $self->{connect}{join}
667 )
668 : @_
669 );
670  
671 0 return $self;
672 }
673  
674 0 ▶sub part {
Subroutine part: not called CC=2 SCAR=17.9
Pod documented
675 0 my $self = shift;
676 0 $self->say("PART $_") for (@_);
677 0 return $self;
678 }
679  
680 2 ▶sub list {
Subroutine list: called CC=3 SCAR=11.2
Pod documented
681 2 my ( $self, $separator, $conjunction ) = ( shift, shift, shift );
682 2 my @list = @_;
683  
684 2 ▶ if ( @list > 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@list > 2) { } 1 1 2
elsif (@list > 1) { } 1 0 1
685 1 return CORE::join( $separator, @list[ 0 .. @list - 2 ], $conjunction . ' ' . $list[-1] );
686 }
687 elsif ( @list > 1 ) {
688 1 return $list[0] . ' ' . $conjunction . ' ' . $list[1];
689 }
690 else {
691 0 return $list[0];
692 }
693 }
694  
695 0 ▶sub health {
Subroutine health: not called CC=1 SCAR=6.9
Pod documented
696 0 my ($self) = @_;
697  
698 return {
699 nick => $self->{nick},
700 server => $self->{connect}{server},
701 port => $self->{connect}{port},
702 ssl => $self->{connect}{ssl},
703 spawn => $self->{spawn},
704 0 hooks => scalar( @{ $self->{hooks} } ),
705 0 ticks => scalar( @{ $self->{ticks} } ),
706 0 plugins => scalar( keys %{ $self->{loaded} } ),
707 };
708 }
709  
710 0 ▶sub numerics {
Subroutine numerics: not called CC=1 SCAR=6.9
Pod documented
711 0 my ($self) = @_;
712 0 return $self->{numerics};
713 }
714  
715 14 1;
716  
717 __END__
↑ Summary IRC/History.pm »