blib/lib/Circle/Net/IRC.pm

filter: Statementstmt 16.5% 118 / 714 Branchbran 0.0% 0 / 220 Conditioncond 0.0% 0 / 70 MC/DCmcdc 0.0% 0 / 44 Subroutinesub 25.0% 37 / 148 Podpod 1.3% 1 / 77 totaltotal 12.2% 156 / 1273 SCAR 96.3
CC
148
Cov
12%
format_text_tagged
1122.0
on_message
462.0
connect
72.0
CRAP 15201.0
↑ Summary blib/lib/Circle/GlobalRules.pm »
1 # You may distribute under the terms of the GNU General Public License
2 #
3 # (C) Paul Evans, 2008-2014 -- leonerd@leonerd.org.uk
4  
5 package Circle::Net::IRC;
6  
7 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use base qw( Tangence::Object Circle::WindowItem Circle::Ruleable );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 __PACKAGE__->APPLY_Ruleable;
12  
13 4 ▶use base qw( Circle::Rule::Store ); # for the attributes
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use constant NETTYPE => 'irc';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 ▶use Circle::Net::IRC::Channel;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use Circle::Net::IRC::User;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 4 ▶use Circle::TaggedString;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 4 ▶use Circle::Rule::Store;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 4 ▶use Circle::Widget::Box;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use Circle::Widget::Label;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 4 ▶use Net::Async::IRC 0.09; # IaStream subclass
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶use IO::Async::Timer::Countdown;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 4 ▶use Text::Balanced qw( extract_delimited );
Subroutine BEGIN: called CC=1 SCAR=0.0
31 4 ▶use Scalar::Util qw( weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 sub new
34 {
35 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
36 0 my %args = @_;
37  
38 0 my $self = $class->SUPER::new( %args );
39  
40 0 $self->{root} = $args{root};
41 0 my $loop = $self->{loop} = $args{loop};
42  
43 # For WindowItem
44 0 $self->set_prop_tag( $args{tag} );
45  
46 my $irc = $self->{irc} = Net::Async::IRC->new(
47 # TODO: All these event handler subs should be weaselled
48 on_message => sub {
49 0 ▶ my ( $irc, $command, $message, $hints ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 $self->on_message( $command, $message, $hints );
51 },
52  
53 on_closed => sub {
54 0 ▶ $self->on_closed;
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 },
56  
57 encoding => "UTF-8",
58  
59 pingtime => 120,
60 on_ping_timeout => sub {
61 0 ▶ $self->on_ping_timeout;
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 },
63  
64 pongtime => 60,
65 on_pong_reply => sub {
66 0 ▶ my ( $irc, $lag ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 $self->on_ping_reply( $lag );
68 },
69 0 );
70  
71 0 weaken( my $weakself = $self );
72 $self->{reconnect_timer} = IO::Async::Timer::Countdown->new(
73 delay => 1, # Doesn't matter, as ->enqueue_reconnect will set it before start anyway
74 0 ▶ on_expire => sub { $weakself and $weakself->reconnect },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$weakself and $weakself->reconnect 0 0 0
75 0 );
76 0 $loop->add( $self->{reconnect_timer} );
77  
78 0 $self->{servers} = [];
79  
80 0 $self->{channels} = {};
81 0 $self->{users} = {};
82  
83 0 my $rulestore = $self->init_rulestore( parent => $args{root}->{rulestore} );
84  
85 0 $rulestore->register_cond( matchnick => $self );
86 0 $rulestore->register_cond( fromnick => $self );
87 0 $rulestore->register_cond( channel => $self );
88 0 $rulestore->register_cond( isaction => $self );
89  
90 0 $rulestore->register_action( highlight => $self );
91 0 $rulestore->register_action( display => $self );
92 0 $rulestore->register_action( chaction => $self );
93  
94 0 $rulestore->new_chain( "input" );
95  
96 0 $rulestore->get_chain( "input" )->append_rule( "matchnick: highlight" );
97  
98 0 $rulestore->new_chain( "output" );
99  
100 0 $self->set_network_status( "disconnected" );
101  
102 0 return $self;
103 }
104  
105 sub describe
106 {
107 0 ▶ my $self = shift;
Subroutine describe: not called CC=1 SCAR=6.9
Pod documented
108 0 return __PACKAGE__."[". $self->get_prop_tag . "]";
109 }
110  
111 sub get_prop_users
112 {
113 0 ▶ my $self = shift;
Subroutine get_prop_users: not called CC=1 SCAR=6.9
Pod undocumented
114  
115 0 my $users = $self->{users};
116 0 return [ values %$users ];
117 }
118  
119 sub reify
120 ▶{
Subroutine reify: not called CC=1 SCAR=0.0
Pod undocumented
121 # always real; this is a no-op
122 }
123  
124 sub set_network_status
125 {
126 0 ▶ my $self = shift;
Subroutine set_network_status: not called CC=3 SCAR=24.8
Pod undocumented
127 0 my ( $status ) = @_;
128  
129 0 $self->{status} = $status;
130  
131 0 my $text = $self->get_prop_tag;
132 0 ▶ $text .= "[$self->{status}]" if length $self->{status};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"status"} 0 0 0
133  
134 0 ▶ $self->{widget_netname}->set_prop_text( $text ) if $self->{widget_netname};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"widget_netname"} 0 0 0
135 }
136  
137 sub get_channel_if_exists
138 {
139 0 ▶ my $self = shift;
Subroutine get_channel_if_exists: not called CC=1 SCAR=6.9
Pod undocumented
140 0 my ( $channame ) = @_;
141  
142 0 my $irc = $self->{irc};
143 0 my $channame_folded = $irc->casefold_name( $channame );
144  
145 0 return $self->{channels}->{$channame_folded};
146 }
147  
148 sub get_channel_or_create
149 {
150 0 ▶ my $self = shift;
Subroutine get_channel_or_create: not called CC=2 SCAR=17.9
Pod undocumented
151 0 my ( $channame ) = @_;
152  
153 0 my $irc = $self->{irc};
154 0 my $channame_folded = $irc->casefold_name( $channame );
155  
156 0 ▶ return $self->{channels}->{$channame_folded} if exists $self->{channels}->{$channame_folded};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"channels"}{$channame_folded} 0 0 0
157  
158 0 my $registry = $self->{registry};
159 my $chanobj = $registry->construct(
160 "Circle::Net::IRC::Channel",
161 root => $self->{root},
162 0 net => $self,
163 irc => $irc,
164 name => $channame,
165 );
166  
167 0 my $root = $self->{root};
168  
169 0 $self->{channels}->{$channame_folded} = $chanobj;
170 $chanobj->subscribe_event( destroy => sub {
171 0 ▶ my ( $chanobj ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
172 0 $root->broadcast_sessions( "delete_item", $chanobj );
173 0 $self->del_prop_channels( $chanobj );
174 0 delete $self->{channels}->{$channame_folded};
175 0 } );
176  
177 0 $self->add_prop_channels( $chanobj );
178  
179 0 return $chanobj;
180 }
181  
182 sub get_user_if_exists
183 {
184 0 ▶ my $self = shift;
Subroutine get_user_if_exists: not called CC=1 SCAR=6.9
Pod undocumented
185 0 my ( $nick ) = @_;
186  
187 0 my $irc = $self->{irc};
188 0 my $nick_folded = $irc->casefold_name( $nick );
189  
190 0 return $self->{users}->{$nick_folded};
191 }
192  
193 sub get_user_or_create
194 {
195 0 ▶ my $self = shift;
Subroutine get_user_or_create: not called CC=4 SCAR=30.0
Pod undocumented
196 0 my ( $nick ) = @_;
197  
198 0 ▶ unless( defined $nick and length $nick ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nick and length $nick) 0 0 0
Condition0%0/3
defined $nick and length $nick
!ll&&!rl&&r
000
MC/DC0%0/2
defined $nick and length $nick
defined $nick length $nick
Truth table0%0/3
A and B
A= defined $nickB= length $nick
ABresult
0X0
100
111
199 0 warn "Unable to create a new user with an empty nick\n";
200 0 return undef;
201 }
202  
203 0 my $irc = $self->{irc};
204 0 my $nick_folded = $irc->casefold_name( $nick );
205  
206 0 ▶ return $self->{users}->{$nick_folded} if exists $self->{users}->{$nick_folded};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"users"}{$nick_folded} 0 0 0
207  
208 0 my $registry = $self->{registry};
209 my $userobj = $registry->construct(
210 "Circle::Net::IRC::User",
211 root => $self->{root},
212 0 net => $self,
213 irc => $irc,
214 name => $nick,
215 );
216  
217 0 my $root = $self->{root};
218  
219 0 $self->{users}->{$nick_folded} = $userobj;
220  
221 $userobj->subscribe_event( destroy => sub {
222 0 ▶ my ( $userobj ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
223 0 $root->broadcast_sessions( "delete_item", $userobj );
224 0 $self->del_prop_users( $userobj );
225 0 my $nick_folded = $irc->casefold_name( $userobj->get_prop_name );
226 0 delete $self->{users}->{$nick_folded};
227 0 } );
228  
229 $userobj->subscribe_event( change_nick => sub {
230 0 ▶ my ( undef, $oldnick, $oldnick_folded, $newnick, $newnick_folded ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
231 0 $self->{users}->{$newnick_folded} = delete $self->{users}->{$oldnick_folded};
232 0 } );
233  
234 0 $self->add_prop_users( $userobj );
235  
236 0 return $userobj;
237 }
238  
239 sub get_target_if_exists
240 {
241 0 ▶ my $self = shift;
Subroutine get_target_if_exists: not called CC=3 SCAR=24.8
Pod undocumented
242 0 my ( $name ) = @_;
243  
244 0 my $irc = $self->{irc};
245 0 my $type = $irc->classify_name( $name );
246  
247 0 ▶ if( $type eq "channel" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'channel') { } 0 0 0
elsif ($type eq 'user') { } 0 0 0
248 0 return $self->get_channel_if_exists( $name );
249 }
250 elsif( $type eq "user" ) {
251 0 return $self->get_user_if_exists( $name );
252 }
253 else {
254 0 return undef;
255 }
256 }
257  
258 sub get_target_or_create
259 {
260 0 ▶ my $self = shift;
Subroutine get_target_or_create: not called CC=3 SCAR=24.8
Pod undocumented
261 0 my ( $name ) = @_;
262  
263 0 my $irc = $self->{irc};
264 0 my $type = $irc->classify_name( $name );
265  
266 0 ▶ if( $type eq "channel" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'channel') { } 0 0 0
elsif ($type eq 'user') { } 0 0 0
267 0 return $self->get_channel_or_create( $name );
268 }
269 elsif( $type eq "user" ) {
270 0 return $self->get_user_or_create( $name );
271 }
272 else {
273 0 return undef;
274 }
275 }
276  
277 sub connect
278 {
279 0 ▶ my $self = shift;
Subroutine connect: not called CC=8 SCAR=42.8
Pod undocumented
280 0 my %args = @_;
281  
282 0 my $irc = $self->{irc};
283  
284 0 my $host = $args{host};
285 0 ▶ my $nick = $args{nick} || $self->get_prop_nick || $self->{configured_nick};
Condition0%0/6
$args{'nick'} || $self->get_prop_nick || $self->{'configured_nick'}
l!l&&r!l&&!r
000
$args{"nick"} or $self->get_prop_nick
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'nick'} || $self->get_prop_nick || $self->{'configured_nick'}
$args{"nick"} $self->get_prop_nick $self->{'configured_nick'}
Truth table0%0/4
A or B || C
A= $args{"nick"}B= $self->get_prop_nickC= $self->{'configured_nick'}
ABCresult
1XX1
01X1
0011
0000
286  
287 0 ▶ if( $args{SSL} and not eval { require IO::Async::SSL } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"SSL"} and not eval { do { require IO::Async::SSL } }) 0 0 0
Condition0%0/3
$args{"SSL"} and not eval { do { require IO::Async::SSL } }
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"SSL"} and not eval { do { require IO::Async::SSL } }
$args{"SSL"} not eval { do { require IO::Async::SSL } }
Truth table0%0/3
A and not(B)
A= $args{"SSL"}B= not eval { do { require IO::Async::SSL } }
ABresult
0X0
100
111
288 0 return Future->new->fail( "SSL is set but IO::Async::SSL is not available" );
289 }
290  
291 0 ▶ $self->{loop}->add( $irc ) if !$irc->loop;
Branch: 1 branch
BranchTrueFalseTotal
unless $irc->loop 0 0 0
292 my $f = $irc->login(
293 host => $host,
294 service => $args{port},
295 nick => $nick,
296 user => $args{ident},
297 pass => $args{pass},
298  
299 ( $args{SSL} ? (
300 extensions => [qw( SSL )],
301 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
302 ) : () ),
303  
304 local_host => $args{local_host} || $self->{local_host},
305  
306 on_login => sub {
307 0 ▶ foreach my $target ( values %{ $self->{channels} }, values %{ $self->{users} } ) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
308 0 $target->on_connected;
309 }
310  
311 0 $self->set_prop_nick( $nick );
312  
313 0 $self->set_network_status( "" );
314  
315 0 $self->fire_event( "connected" );
316 },
317  
318 on_error => $args{on_error},
319 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$args{'SSL'} ? : 0 0 0
Condition0%0/3
$args{'local_host'} || $self->{'local_host'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'local_host'} || $self->{'local_host'}
$args{'local_host'} $self->{'local_host'}
Truth table0%0/3
A || B
A= $args{'local_host'}B= $self->{'local_host'}
ABresult
1X1
011
000
320  
321 0 $self->set_network_status( "connecting" );
322  
323 0 ▶ $f->on_fail( sub { $self->set_network_status( "disconnected" ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
324  
325 0 return $f;
326 }
327  
328 sub connected
329 {
330 0 ▶ my $self = shift;
Subroutine connected: not called CC=1 SCAR=6.9
Pod undocumented
331  
332 # Consider we're "connected" if the underlying IRC object is logged in
333 0 my $irc = $self->{irc};
334 0 return $irc->is_loggedin;
335 }
336  
337 # Map mIRC's colours onto an approximation of ANSI terminal
338 4 my @irc_colour_map = (
339 15, 0, 4, 2, # white black blue green
340 9, 1, 5, 3, # red [brown=darkred] [purple=darkmagenta] [orange=darkyellow]
341 11, 10, 6, 14, # yellow lightgreen cyan lightcyan
342 12, 13, 8, 7 # lightblue [pink=magenta] grey lightgrey
343 );
344  
345 sub format_colour
346 {
347 0 ▶ my $self = shift;
Subroutine format_colour: not called CC=5 SCAR=34.0
Pod undocumented
348 0 my ( $colcode ) = @_;
349  
350 0 ▶ return $colcode if $colcode =~ m/^#[0-9a-f]{6}/i;
Branch: 1 branch
BranchTrueFalseTotal
if $colcode =~ /^#[0-9a-f]{6}/i 0 0 0
351 0 ▶ return "#$1$1$2$2$3$3" if $colcode =~ m/^#([0-9a-f])([0-9a-f])([0-9a-f])/i;
Branch: 1 branch
BranchTrueFalseTotal
if $colcode =~ /^#([0-9a-f])([0-9a-f])([0-9a-f])/i 0 0 0
352  
353 0 ▶ return sprintf( "ansi.col%02d", $irc_colour_map[$1] ) if $colcode =~ m/^(\d\d?)/ and defined $irc_colour_map[$1];
Branch: 1 branch
BranchTrueFalseTotal
if $colcode =~ /^(\d\d?)/ and defined $irc_colour_map[$1] 0 0 0
Condition0%0/3
$colcode =~ /^(\d\d?)/ and defined $irc_colour_map[$1]
!ll&&!rl&&r
000
MC/DC0%0/2
$colcode =~ /^(\d\d?)/ and defined $irc_colour_map[$1]
$colcode =~ /^(\d\d?)/ defined $irc_colour_map[$1]
Truth table0%0/3
A and B
A= $colcode =~ /^(\d\d?)/B= defined $irc_colour_map[$1]
ABresult
0X0
100
111
354  
355 0 return undef;
356 }
357  
358 sub format_text_tagged
359 {
360 0 ▶ my $self = shift;
Subroutine format_text_tagged: not called CC=33 SCAR=70.2
Pod undocumented
361 0 my ( $text ) = @_;
362  
363 # IRC [well, technically mIRC but other clients have adopted it] uses Ctrl
364 # characters to toggle formatting
365 # ^B = bold
366 # ^U = underline
367 # ^_ = underline
368 # ^R = reverse or italic - we'll use italic
369 # ^V = reverse
370 # ^] = italics
371 # ^O = reset
372 # ^C = colour; followed by a code
373 # ^C = reset colours
374 # ^Cff = foreground
375 # ^Cff,bb = background
376 #
377 # irssi uses the following
378 # ^D$$ = foreground/background, in chr('0'+$colour),
379 # ^Db = underline
380 # ^Dc = bold
381 # ^Dd = reverse or italic - we'll use italic
382 # ^Dg = reset colours
383 #
384 # As a side effect we'll also strip all the other Ctrl chars
385  
386 # We'll also look for "poor-man's" highlighting
387 # *bold*
388 # _underline_
389 # /italic/
390  
391 0 my $ret = Circle::TaggedString->new();
392  
393 0 my %format;
394  
395 0 ▶ while( length $text ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text) 0 0 0
396 0 ▶ if( $text =~ s/^([\x00-\x1f])// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^([\x00-\x1f])//) { } 0 0 0
397 0 my $ctrl = chr(ord($1)+0x40);
398  
399 0 ▶ if( $ctrl eq "B" ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($ctrl eq 'B') { } 0 0 0
elsif ($ctrl eq 'U' or $ctrl eq '_') { } 0 0 0
elsif ($ctrl eq 'R' or $ctrl eq ']') { } 0 0 0
elsif ($ctrl eq 'V') { } 0 0 0
elsif ($ctrl eq 'O') { } 0 0 0
elsif ($ctrl eq 'C') { } 0 0 0
elsif ($ctrl eq 'D') { } 0 0 0
400 0 ▶ $format{b} ? delete $format{b} : ( $format{b} = 1 );
Branch: 1 branch
BranchTrueFalseTotal
$format{'b'} ? : 0 0 0
401 }
402 ▶ elsif( $ctrl eq "U" or $ctrl eq "_" ) {
Condition0%0/3
$ctrl eq "U" or $ctrl eq "_"
l!l&&r!l&&!r
000
MC/DC0%0/2
$ctrl eq "U" or $ctrl eq "_"
$ctrl eq "U" $ctrl eq "_"
Truth table0%0/3
A or B
A= $ctrl eq "U"B= $ctrl eq "_"
ABresult
1X1
011
000
403 0 ▶ $format{u} ? delete $format{u} : ( $format{u} = 1 );
Branch: 1 branch
BranchTrueFalseTotal
$format{'u'} ? : 0 0 0
404 }
405 ▶ elsif( $ctrl eq "R" or $ctrl eq "]" ) {
Condition0%0/3
$ctrl eq "R" or $ctrl eq "]"
l!l&&r!l&&!r
000
MC/DC0%0/2
$ctrl eq "R" or $ctrl eq "]"
$ctrl eq "R" $ctrl eq "]"
Truth table0%0/3
A or B
A= $ctrl eq "R"B= $ctrl eq "]"
ABresult
1X1
011
000
406 0 ▶ $format{i} ? delete $format{i} : ( $format{i} = 1 );
Branch: 1 branch
BranchTrueFalseTotal
$format{'i'} ? : 0 0 0
407 }
408 elsif( $ctrl eq "V" ) {
409 0 ▶ $format{rv} ? delete $format{rv} : ( $format{rv} = 1 );
Branch: 1 branch
BranchTrueFalseTotal
$format{'rv'} ? : 0 0 0
410 }
411 elsif( $ctrl eq "O" ) {
412 0 undef %format;
413 }
414 elsif( $ctrl eq "C" ) {
415 0 my $colourre = qr/#[0-9a-f]{6}|#[0-9a-f]{3}|\d\d?/i;
416  
417 0 ▶ if( $text =~ s/^($colourre),($colourre)// ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($text =~ s/^($colourre),($colourre)//) { } 0 0 0
elsif ($text =~ s/^($colourre)//) { } 0 0 0
418 0 ▶ $format{fg} = $self->format_colour( $1 ) if $self->{use_mirc_colours};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"use_mirc_colours"} 0 0 0
419 0 ▶ $format{bg} = $self->format_colour( $2 ) if $self->{use_mirc_colours};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"use_mirc_colours"} 0 0 0
420 }
421 elsif( $text =~ s/^($colourre)// ) {
422 0 ▶ $format{fg} = $self->format_colour( $1 ) if $self->{use_mirc_colours};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"use_mirc_colours"} 0 0 0
423 }
424 else {
425 0 delete $format{fg};
426 0 delete $format{bg};
427 }
428 }
429 elsif( $ctrl eq "D" ) {
430 0 ▶ if( $text =~ s/^b// ) { # underline
Branch: 4 branches
BranchTrueFalseTotal
if ($text =~ s/^b//) { } 0 0 0
elsif ($text =~ s/^c//) { } 0 0 0
elsif ($text =~ s/^d//) { } 0 0 0
elsif ($text =~ s/^g//) { } 0 0 0
431 0 ▶ $format{u} ? delete $format{u} : ( $format{u} = 1 );
Branch: 1 branch
BranchTrueFalseTotal
$format{'u'} ? : 0 0 0
432 }
433 elsif( $text =~ s/^c// ) { # bold
434 0 ▶ $format{b} ? delete $format{b} : ( $format{b} = 1 );
Branch: 1 branch
BranchTrueFalseTotal
$format{'b'} ? : 0 0 0
435 }
436 elsif( $text =~ s/^d// ) { # revserse/italic
437 0 ▶ $format{i} ? delete $format{i} : ( $format{i} = 1 );
Branch: 1 branch
BranchTrueFalseTotal
$format{'i'} ? : 0 0 0
438 }
439 elsif( $text =~ s/^g// ) {
440 0 undef %format
441 }
442 else {
443 0 $text =~ s/^(.)(.)//;
444 0 my ( $fg, $bg ) = map { ord( $_ ) - ord('0') } ( $1, $2 );
445 0 ▶ if( $fg > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fg > 0) 0 0 0
446 0 $format{fg} = sprintf( "ansi.col%02d", $fg );
447 }
448 0 ▶ if( $bg > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bg > 0) 0 0 0
449 0 $format{bg} = sprintf( "ansi.col%02d", $bg );
450 }
451 }
452 }
453 else {
454 0 print STDERR "Unhandled Ctrl code ^$ctrl\n";
455 }
456 }
457 else {
458 0 $text =~ s/^([^\x00-\x1f]+)//;
459 0 my $piece = $1;
460  
461 # Now scan this piece for the text-based ones
462 0 ▶ while( length $piece ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $piece) 0 0 0
463 # Look behind/ahead asserts to ensure we don't capture e.g.
464 # /usr/bin/perl by mistake
465 0 ▶ if( $piece =~ s/^(.*?)(?<!\w)(([\*_\/])\w+\3)(?!\w)// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($piece =~ s[^(.*?)(?<!\w)(([\*_/])\w+\3)(?!\w)][]) { } 0 0 0
466 0 my ( $pre, $inner, $type ) = ( $1, $2, $3 );
467  
468 0 ▶ $ret->append_tagged( $pre, %format ) if length $pre;
Branch: 1 branch
BranchTrueFalseTotal
if length $pre 0 0 0
469  
470 0 my %innerformat = %format;
471  
472 0 $type =~ tr{*_/}{bui};
473 0 $innerformat{$type} = 1;
474  
475 0 $ret->append_tagged( $inner, %innerformat );
476 }
477 else {
478 0 $ret->append_tagged( $piece, %format );
479 0 $piece = "";
480 }
481 }
482 }
483 }
484  
485 0 return $ret;
486 }
487  
488 sub format_text
489 {
490 0 ▶ my $self = shift;
Subroutine format_text: not called CC=1 SCAR=6.9
Pod undocumented
491 0 my ( $text ) = @_;
492  
493 0 return $self->format_text_tagged( $text );
494 }
495  
496 ###
497 # Rule subs
498 ###
499  
500 sub parse_cond_matchnick
501 : Rule_description("Look for my IRC nick in the text")
502 : Rule_format('')
503 {
504 0 ▶ my $self = shift;
Subroutine parse_cond_matchnick: not called CC=1 SCAR=6.9
Pod undocumented
505 0 return;
506 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
507  
508 sub deparse_cond_matchnick
509 {
510 0 ▶ my $self = shift;
Subroutine deparse_cond_matchnick: not called CC=1 SCAR=6.9
Pod undocumented
511 0 return;
512 }
513  
514 sub eval_cond_matchnick
515 {
516 0 ▶ my $self = shift;
Subroutine eval_cond_matchnick: not called CC=2 SCAR=17.9
Pod undocumented
517 0 my ( $event, $results ) = @_;
518  
519 0 my $text = $event->{text}->str;
520  
521 0 my $nick = $self->{irc}->nick;
522  
523 0 pos( $text ) = 0;
524  
525 0 my $matched;
526  
527 0 ▶ while( $text =~ m/(\Q$nick\E)/gi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /(\Q$nick\E)/gi) 0 0 0
528 0 my ( $start, $end ) = ( $-[0], $+[0] );
529 0 my $len = $end - $start;
530  
531 0 $results->push_result( "matchgroups", [ [ $start, $len ] ] );
532 0 $matched = 1;
533 }
534  
535 0 return $matched;
536 }
537  
538 sub parse_cond_fromnick
539 : Rule_description("Match the message originating nick against a regexp or string")
540 : Rule_format('/regexp/ or "literal"')
541 {
542 0 ▶ my $self = shift;
Subroutine parse_cond_fromnick: not called CC=7 SCAR=40.3
Pod undocumented
543 0 my ( $spec ) = @_;
544  
545 0 ▶ if( $spec =~ m/^"/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec =~ /^"/) { } 0 0 0
elsif ($spec =~ m[^/]) { } 0 0 0
546 # Literal
547 0 my $nick = extract_delimited( $spec, q{"} );
548 0 s/^"//, s/"$// for $nick;
549  
550 0 return literal => $nick;
551 }
552 elsif( $spec =~ m{^/} ) {
553 # Regexp
554 0 my $re = extract_delimited( $spec, q{/} );
555 0 s{^/}{}, s{/$}{} for $re;
556  
557 0 ▶ my $iflag = 1 if $spec =~ s/^i//;
Branch: 1 branch
BranchTrueFalseTotal
if $spec =~ s/^i// 0 0 0
558  
559 0 ▶ return re => qr/$re/i if $iflag;
Branch: 1 branch
BranchTrueFalseTotal
if $iflag 0 0 0
560 0 return re => qr/$re/;
561 }
562 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
563  
564 sub deparse_cond_fromnick
565 {
566 0 ▶ my $self = shift;
Subroutine deparse_cond_fromnick: not called CC=5 SCAR=34.0
Pod undocumented
567 0 my ( $type, $pattern ) = @_;
568  
569 0 ▶ if( $type eq "literal" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'literal') { } 0 0 0
elsif ($type eq 're') { } 0 0 0
570 0 return qq{"$pattern"};
571 }
572 elsif( $type eq "re" ) {
573 # Perl tries to put (?-ixsm:RE) around our pattern. Lets attempt to remove
574 # it if we can
575 0 ▶ return "/$1/" if $pattern =~ m/^\(\?-xism:(.*)\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $pattern =~ /^\(\?-xism:(.*)\)$/ 0 0 0
576 0 ▶ return "/$1/i" if $pattern =~ m/^\(\?i-xsm:(.*)\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $pattern =~ /^\(\?i-xsm:(.*)\)$/ 0 0 0
577  
578 # Failed. Lets just be safe then
579 0 return "/$pattern/";
580 }
581 }
582  
583 sub eval_cond_fromnick
584 {
585 0 ▶ my $self = shift;
Subroutine eval_cond_fromnick: not called CC=3 SCAR=24.8
Pod undocumented
586 0 my ( $event, $results, $type, $pattern ) = @_;
587  
588 0 my $src = $event->{prefix_name_folded};
589  
590 0 ▶ if( $type eq "literal" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'literal') { } 0 0 0
elsif ($type eq 're') { } 0 0 0
591 0 my $irc = $self->{irc};
592  
593 0 return $src eq $irc->casefold_name( $pattern );
594 }
595 elsif( $type eq "re" ) {
596 0 return $src =~ $pattern;
597 }
598 }
599  
600 sub parse_cond_channel
601 : Rule_description("Event comes from a (named) channel")
602 : Rule_format('"name"?')
603 {
604 0 ▶ my $self = shift;
Subroutine parse_cond_channel: not called CC=4 SCAR=30.0
Pod undocumented
605 0 my ( $spec ) = @_;
606  
607 0 ▶ if( defined $spec and $spec =~ m/^"/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec and $spec =~ /^"/) 0 0 0
Condition0%0/3
defined $spec and $spec =~ /^"/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $spec and $spec =~ /^"/
defined $spec $spec =~ /^"/
Truth table0%0/3
A and B
A= defined $specB= $spec =~ /^"/
ABresult
0X0
100
111
608 0 my $name = extract_delimited( $spec, q{"} );
609 0 s/^"//, s/"$// for $name;
610  
611 0 return $name;
612 }
613  
614 0 return undef;
615 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
616  
617 sub deparse_cond_channel
618 {
619 0 ▶ my $self = shift;
Subroutine deparse_cond_channel: not called CC=2 SCAR=17.9
Pod undocumented
620 0 my ( $name ) = @_;
621  
622 0 ▶ return qq{"$name"} if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
623 0 return;
624 }
625  
626 sub eval_cond_channel
627 {
628 0 ▶ my $self = shift;
Subroutine eval_cond_channel: not called CC=4 SCAR=30.0
Pod undocumented
629 0 my ( $event, $results, $name ) = @_;
630  
631 0 ▶ return 0 unless ( $event->{target_type} || "" ) eq "channel";
Branch: 1 branch
BranchTrueFalseTotal
unless ($event->{"target_type"} || "") eq "channel" 0 0 0
Condition0%0/2
$event->{'target_type'} || ''
l!l
00
MC/DC0%0/1
$event->{'target_type'} || ''
$event->{'target_type'}
Truth table0%0/2
A
A= $event->{'target_type'}
Aresult
11
00
632  
633 0 ▶ return 1 unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
634  
635 0 my $irc = $self->{irc};
636 0 return $event->{target_name_folded} eq $irc->casefold_name( $name );
637 }
638  
639 sub parse_cond_isaction
640 : Rule_description("Event is a CTCP ACTION")
641 : Rule_format('')
642 {
643 0 ▶ my $self = shift;
Subroutine parse_cond_isaction: not called CC=1 SCAR=6.9
Pod undocumented
644 0 return undef;
645 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
646  
647 sub deparse_cond_isaction
648 {
649 0 ▶ my $self = shift;
Subroutine deparse_cond_isaction: not called CC=1 SCAR=6.9
Pod undocumented
650 0 return;
651 }
652  
653 sub eval_cond_isaction
654 {
655 0 ▶ my $self = shift;
Subroutine eval_cond_isaction: not called CC=1 SCAR=6.9
Pod undocumented
656 0 my ( $event, $results, $name ) = @_;
657  
658 0 return $event->{is_action};
659 }
660  
661 sub parse_action_highlight
662 : Rule_description("Highlight matched regions and set activity level to 3")
663 : Rule_format('')
664 {
665 0 ▶ my $self = shift;
Subroutine parse_action_highlight: not called CC=1 SCAR=6.9
Pod undocumented
666 0 return;
667 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
668  
669 sub deparse_action_highlight
670 {
671 0 ▶ my $self = shift;
Subroutine deparse_action_highlight: not called CC=1 SCAR=6.9
Pod undocumented
672 0 return;
673 }
674  
675 sub eval_action_highlight
676 {
677 0 ▶ my $self = shift;
Subroutine eval_action_highlight: not called CC=2 SCAR=17.9
Pod undocumented
678 0 my ( $event, $results ) = @_;
679  
680 0 my $str = $event->{text};
681  
682 0 foreach my $matchgroup ( @{ $results->get_result( "matchgroups" ) } ) {
683 0 my ( $start, $len ) = @{$matchgroup->[0]}[0,1];
684  
685 0 $str->apply_tag( $start, $len, b => 1 );
686 0 $str->apply_tag( $start, $len, fg => "highlight" );
687 }
688  
689 0 $event->{level} = 3;
690 }
691  
692 sub parse_action_display
693 : Rule_description("Set the display window to display an event")
694 : Rule_format('self|server')
695 {
696 0 ▶ my $self = shift;
Subroutine parse_action_display: not called CC=3 SCAR=24.8
Pod undocumented
697 0 my ( $spec ) = @_;
698  
699 0 ▶ if( $spec eq "self" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec eq 'self') { } 0 0 0
elsif ($spec eq 'server') { } 0 0 0
700 0 return "self";
701 }
702 elsif( $spec eq "server" ) {
703 0 return "server";
704 }
705 else {
706 0 die "Unrecognised display spec\n";
707 }
708 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
709  
710 sub deparse_action_display
711 {
712 0 ▶ my $self = shift;
Subroutine deparse_action_display: not called CC=1 SCAR=6.9
Pod undocumented
713 0 my ( $display ) = @_;
714  
715 0 return $display;
716 }
717  
718 sub eval_action_display
719 {
720 0 ▶ my $self = shift;
Subroutine eval_action_display: not called CC=1 SCAR=6.9
Pod undocumented
721 0 my ( $event, $results, $display ) = @_;
722  
723 0 $event->{display} = $display;
724 }
725  
726 sub parse_action_chaction
727 : Rule_description("Change an event to or from being a CTCP ACTION")
728 : Rule_format('0|1')
729 {
730 0 ▶ my $self = shift;
Subroutine parse_action_chaction: not called CC=1 SCAR=6.9
Pod undocumented
731 0 my ( $spec ) = @_;
732  
733 0 return !!$spec;
734 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
735  
736 sub deparse_action_chaction
737 {
738 0 ▶ my $self = shift;
Subroutine deparse_action_chaction: not called CC=1 SCAR=6.9
Pod undocumented
739 0 my ( $action ) = @_;
740  
741 0 return $action;
742 }
743  
744 sub eval_action_chaction
745 {
746 0 ▶ my $self = shift;
Subroutine eval_action_chaction: not called CC=1 SCAR=6.9
Pod undocumented
747 0 my ( $event, $results, $action ) = @_;
748  
749 0 $event->{is_action} = $action;
750 }
751  
752 ###
753 # IRC message handlers
754 ###
755  
756 sub on_message
757 {
758 0 ▶ my $self = shift;
Subroutine on_message: not called CC=21 SCAR=61.4
Pod undocumented
759 0 my ( $command, $message, $hints ) = @_;
760  
761 0 ▶ if( defined $hints->{target_name} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $hints->{'target_name'}) { } 0 0 0
elsif (grep {$command eq $_;} 'NICK', 'QUIT') { } 0 0 0
elsif ($self->can("on_message_$command")) { } 0 0 0
762 0 my $target;
763  
764 0 ▶ if( $hints->{target_type} eq "channel" ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($hints->{'target_type'} eq 'channel') { } 0 0 0
elsif ($hints->{'target_is_me'} and defined $hints->{'prefix_name'} and not $hints->{'prefix_is_me'}) { } 0 0 0
elsif ($hints->{'target_type'} eq 'user') { } 0 0 0
765 0 $target = $self->get_channel_or_create( $hints->{target_name} );
766 }
767 ▶ elsif( $hints->{target_is_me} and
Condition0%0/6
$hints->{"target_is_me"} and defined $hints->{"prefix_name"} and not $hints->{"prefix_is_me"}
!ll&&!rl&&r
000
$hints->{"target_is_me"} and defined $hints->{"prefix_name"}
!ll&&!rl&&r
000
MC/DC0%0/3
$hints->{"target_is_me"} and defined $hints->{"prefix_name"} and not $hints->{"prefix_is_me"}
$hints->{"target_is_me"} defined $hints->{"prefix_name"} not $hints->{"prefix_is_me"}
Truth table0%0/4
A and B and not(C)
A= $hints->{"target_is_me"}B= defined $hints->{"prefix_name"}C= not $hints->{"prefix_is_me"}
ABCresult
0XX0
10X0
1100
1111
768 defined $hints->{prefix_name} and
769 not $hints->{prefix_is_me} ) {
770 # Handle PRIVMSG and similar from the user
771 0 $target = $self->get_user_or_create( $hints->{prefix_name} );
772 }
773 elsif( $hints->{target_type} eq "user" ) {
774 # Handle numerics about the user - Net::Async::IRC has filled in the target
775 0 $target = $self->get_user_or_create( $hints->{target_name} );
776 }
777  
778 0 ▶ if( $target ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target) 0 0 0
779 0 ▶ return 1 if $target->on_message( $command, $message, $hints );
Branch: 1 branch
BranchTrueFalseTotal
if $target->on_message($command, $message, $hints) 0 0 0
780 }
781 }
782 0 elsif( grep { $command eq $_ } qw( NICK QUIT ) ) {
783 # Target all of them
784 0 my $handled = 0;
785  
786 0 my $method = "on_message_$command";
787  
788 0 ▶ $handled = 1 if $self->can( $method ) and $self->$method( $message, $hints );
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($method) and $self->$method($message, $hints) 0 0 0
Condition0%0/3
$self->can($method) and $self->$method($message, $hints)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->can($method) and $self->$method($message, $hints)
$self->can($method) $self->$method($message, $hints)
Truth table0%0/3
A and B
A= $self->can($method)B= $self->$method($message, $hints)
ABresult
0X0
100
111
789  
790 0 foreach my $target ( values %{ $self->{channels} } ) {
791 0 ▶ $handled = 1 if $target->$method( $message, $hints );
Branch: 1 branch
BranchTrueFalseTotal
if $target->$method($message, $hints) 0 0 0
792 }
793  
794 0 my $nick_folded = $hints->{prefix_nick_folded};
795  
796 0 ▶ if( my $userobj = $self->get_user_if_exists( $hints->{prefix_nick} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $userobj = $self->get_user_if_exists($hints->{"prefix_nick"})) 0 0 0
797 0 ▶ $handled = 1 if $userobj->$method( $message, $hints );
Branch: 1 branch
BranchTrueFalseTotal
if $userobj->$method($message, $hints) 0 0 0
798 }
799  
800 0 ▶ return 1 if $handled;
Branch: 1 branch
BranchTrueFalseTotal
if $handled 0 0 0
801 }
802 elsif( $self->can( "on_message_$command" ) ) {
803 0 my $method = "on_message_$command";
804 0 my $handled = $self->$method( $message, $hints );
805  
806 0 ▶ return 1 if $handled;
Branch: 1 branch
BranchTrueFalseTotal
if $handled 0 0 0
807 }
808  
809 0 ▶ if( not $hints->{handled} and not $hints->{synthesized} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $hints->{"handled"} || $hints->{"synthesized"}) 0 0 0
Condition0%0/3
$hints->{'handled'} || $hints->{'synthesized'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hints->{'handled'} || $hints->{'synthesized'}
$hints->{'handled'} $hints->{'synthesized'}
Truth table0%0/3
A || B
A= $hints->{'handled'}B= $hints->{'synthesized'}
ABresult
1X1
011
000
810 $self->push_displayevent( "irc.irc", {
811 command => $command,
812 prefix => $message->prefix,
813 0 args => join( " ", map { "'$_'" } $message->args ),
814 } );
815 0 $self->bump_level( 1 );
816 }
817 }
818  
819 sub on_message_NICK
820 {
821 0 ▶ my $self = shift;
Subroutine on_message_NICK: not called CC=2 SCAR=17.9
Pod undocumented
822 0 my ( $message, $hints ) = @_;
823  
824 0 ▶ if( $hints->{prefix_is_me} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hints->{"prefix_is_me"}) 0 0 0
825 0 $self->set_prop_nick( $hints->{new_nick} );
826 }
827  
828 0 return 1;
829 }
830  
831 sub on_message_motd
832 {
833 0 ▶ my $self = shift;
Subroutine on_message_motd: not called CC=2 SCAR=17.9
Pod undocumented
834 0 my ( $message, $hints ) = @_;
835  
836 0 my $motd = $hints->{motd};
837 0 $self->push_displayevent( "irc.motd", { text => $self->format_text($_) } ) for @$motd;
838 0 $self->bump_level( 1 );
839  
840 0 return 1;
841 }
842  
843 sub on_message_RPL_UNAWAY
844 {
845 0 ▶ my $self = shift;
Subroutine on_message_RPL_UNAWAY: not called CC=1 SCAR=6.9
Pod undocumented
846 0 my ( $message, $hints ) = @_;
847  
848 0 $self->set_prop_away( 0 );
849  
850 0 $self->push_displayevent( "irc.text", { server => $hints->{prefix_host}, text => $hints->{text} } );
851 0 $self->bump_level( 1 );
852  
853 0 return 1;
854 }
855  
856 sub on_message_RPL_NOWAWAY
857 {
858 0 ▶ my $self = shift;
Subroutine on_message_RPL_NOWAWAY: not called CC=1 SCAR=6.9
Pod undocumented
859 0 my ( $message, $hints ) = @_;
860  
861 0 $self->set_prop_away( 1 );
862  
863 0 $self->push_displayevent( "irc.text", { server => $hints->{prefix_host}, text => $hints->{text} } );
864 0 $self->bump_level( 1 );
865  
866 0 return 1;
867 }
868  
869 sub on_message_whois
870 {
871 0 ▶ my $self = shift;
Subroutine on_message_whois: not called CC=2 SCAR=17.9
Pod undocumented
872 0 my ( $message, $hints ) = @_;
873  
874 my $f = delete $self->{whois_gate_f}{$hints->{target_name_folded}}
875 0 ▶ or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $f = delete $self->{"whois_gate_f"}{$hints->{"target_name_folded"}} or return 1 0 0 0
876  
877 0 $f->done( $hints->{whois} );
878 }
879  
880 sub on_closed
881 {
882 0 ▶ my $self = shift;
Subroutine on_closed: not called CC=5 SCAR=34.0
Pod undocumented
883 0 my ( $message ) = @_;
884  
885 0 ▶ $message ||= "Server is disconnected";
Condition0%0/2
$message ||= "Server is disconnected"
l!l
00
MC/DC0%0/1
$message ||= "Server is disconnected"
$message
Truth table0%0/2
A
A= $message
Aresult
11
00
886 0 $self->set_network_status( "disconnected" );
887  
888 0 $self->push_displayevent( "status", { text => $message } );
889  
890 0 foreach my $target ( values %{ $self->{channels} }, values %{ $self->{users} } ) {
891 0 $target->on_disconnected( $message );
892 }
893  
894 0 $self->fire_event( "disconnected" );
895  
896 0 ▶ unless( $self->{no_reconnect_on_close} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"no_reconnect_on_close"}) 0 0 0
897 0 $self->{reconnect_delay_idx} = 0;
898 0 $self->{reconnect_host_idx} = 0;
899 0 ▶ $self->enqueue_reconnect if !$self->{reconnect_timer}->is_running;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"reconnect_timer"}->is_running 0 0 0
900 }
901 0 undef $self->{no_reconnect_on_close};
902 }
903  
904 4 my @reconnect_delays = ( 5, 5, 10, 30, 60 );
905 sub enqueue_reconnect
906 {
907 0 ▶ my $self = shift;
Subroutine enqueue_reconnect: not called CC=2 SCAR=17.9
Pod undocumented
908 0 ▶ my $delay = $reconnect_delays[ $self->{reconnect_delay_idx}++ ] // $reconnect_delays[-1];
Condition0%0/3
$reconnect_delays[$self->{"reconnect_delay_idx"}++] // $reconnect_delays[-1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$reconnect_delays[$self->{"reconnect_delay_idx"}++] // $reconnect_delays[-1]
$reconnect_delays[$self->{"reconnect_delay_idx"}++] $reconnect_delays[-1]
Truth table0%0/3
A // B
A= $reconnect_delays[$self->{"reconnect_delay_idx"}++]B= $reconnect_delays[-1]
ABresult
1X1
011
000
909  
910 0 my $timer = $self->{reconnect_timer};
911 0 $timer->configure( delay => $delay );
912 0 $timer->start;
913  
914 0 $self->set_network_status( "reconnect pending..." );
915 }
916  
917 sub reconnect
918 {
919 0 ▶ my $self = shift;
Subroutine reconnect: not called CC=1 SCAR=6.9
Pod undocumented
920  
921 0 my $s = $self->{servers}->[ $self->{reconnect_host_idx}++ ];
922 0 $self->{reconnect_host_idx} %= @{ $self->{servers} };
923  
924 my $f = $self->connect(
925 host => $s->{host},
926 port => $s->{port},
927 user => $s->{user},
928 pass => $s->{pass},
929 SSL => $s->{SSL},
930 0 ▶ on_error => sub { warn "TODO: Empty closure" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
931 0 );
932  
933 0 ▶ $f->on_fail( sub { $self->enqueue_reconnect } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
934 }
935  
936 sub on_ping_timeout
937 {
938 0 ▶ my $self = shift;
Subroutine on_ping_timeout: not called CC=1 SCAR=6.9
Pod undocumented
939  
940 0 $self->on_closed( "Ping timeout" );
941 0 $self->{irc}->close;
942 }
943  
944 sub on_ping_reply
945 {
946 0 ▶ my $self = shift;
Subroutine on_ping_reply: not called CC=2 SCAR=17.9
Pod undocumented
947 0 my ( $lag ) = @_;
948  
949 0 ▶ if( $lag > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lag > 1) { } 0 0 0
950 0 $self->set_network_status( sprintf "lag:%.2f", $lag );
951 }
952 else {
953 0 $self->set_network_status( "" );
954 }
955 }
956  
957 sub method_get_isupport
958 {
959 0 ▶ my $self = shift;
Subroutine method_get_isupport: not called CC=1 SCAR=6.9
Pod undocumented
960 0 my ( $ctx, $key ) = @_;
961  
962 0 my $irc = $self->{irc};
963 0 return $irc->isupport( $key );
964 }
965  
966 use Circle::Collection
967 name => 'servers',
968 storage => 'array',
969 attrs => [
970 host => { desc => "hostname" },
971 port => { desc => "alternative port",
972 0 ▶ show => sub { $_ || "6667" },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ or 6667 0 0 0
973 },
974 SSL => { desc => "use SSL",
975 0 ▶ show => sub { $_ ? "SSL" : "" },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
976 },
977 ident => { desc => "alternative ident",
978 0 ▶ show => sub { $_ || '$USER' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ or "\$USER" 0 0 0
979 },
980 pass => { desc => "connection password",
981 0 ▶ show => sub { $_ ? "set" : "" },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
982 },
983 4 ],
984 4 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
985  
986 sub command_nick
987 : Command_description("Change nick")
988 : Command_arg('nick?')
989 {
990 0 ▶ my $self = shift;
Subroutine command_nick: not called CC=2 SCAR=17.9
Pod undocumented
991 0 my ( $newnick ) = @_;
992  
993 0 my $irc = $self->{irc};
994  
995 0 ▶ if( defined $newnick ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newnick) 0 0 0
996 0 $irc->change_nick( $newnick );
997 0 $self->set_prop_nick( $newnick );
998 }
999  
1000 0 return;
1001 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1002  
1003 sub command_connect
1004 : Command_description("Connect to an IRC server")
1005 : Command_arg('host?')
1006 : Command_opt('port=$', desc => "alternative port (default '6667')")
1007 : Command_opt('SSL=+', desc => "use SSL")
1008 : Command_opt('nick=$', desc => "initial nick")
1009 : Command_opt('ident=$', desc => "alternative ident (default '\$USER')")
1010 : Command_opt('pass=$', desc => "connection password")
1011 : Command_opt('local_host=$', desc => "local host to bind")
1012 {
1013 0 ▶ my $self = shift;
Subroutine command_connect: not called CC=8 SCAR=42.8
Pod undocumented
1014 0 my ( $host, $opts, $cinv ) = @_;
1015  
1016 0 my $s;
1017  
1018 0 ▶ if( !defined $host ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $host) { } 0 0 0
1019 0 ▶ if( !@{ $self->{servers} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"servers"};}) 0 0 0
1020 0 $cinv->responderr( "Cannot connect - no servers defined" );
1021 0 return;
1022 }
1023  
1024 # TODO: Pick one - for now just the first
1025 0 $s = $self->{servers}->[0];
1026  
1027 0 $host = $s->{host};
1028 }
1029 else {
1030 0 ( $s ) = grep { $_->{host} eq $host } @{ $self->{servers} };
1031 0 ▶ $s or return $cinv->responderr( "No definition for $host" );
Branch: 1 branch
BranchTrueFalseTotal
$s or return $cinv->responderr("No definition for $host") 0 0 0
1032 }
1033  
1034 0 $self->{reconnect_timer}->stop;
1035  
1036 my $f = $self->connect(
1037 host => $host,
1038 nick => $opts->{nick},
1039 port => $opts->{port} || $s->{port},
1040 SSL => $opts->{SSL} || $s->{SSL},
1041 ident => $opts->{ident} || $s->{ident},
1042 pass => $opts->{pass} || $s->{pass},
1043 local_host => $opts->{local_host},
1044 0 ▶ on_error => sub { warn "Empty closure" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1045 0 ▶ );
Condition0%0/12
$opts->{'port'} || $s->{'port'}
l!l&&r!l&&!r
000
$opts->{'SSL'} || $s->{'SSL'}
l!l&&r!l&&!r
000
$opts->{'ident'} || $s->{'ident'}
l!l&&r!l&&!r
000
$opts->{'pass'} || $s->{'pass'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'port'} || $s->{'port'}
$opts->{'port'} $s->{'port'}
MC/DC0%0/2
$opts->{'SSL'} || $s->{'SSL'}
$opts->{'SSL'} $s->{'SSL'}
MC/DC0%0/2
$opts->{'ident'} || $s->{'ident'}
$opts->{'ident'} $s->{'ident'}
MC/DC0%0/2
$opts->{'pass'} || $s->{'pass'}
$opts->{'pass'} $s->{'pass'}
Truth table0%0/3
A || B
A= $opts->{'port'}B= $s->{'port'}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $opts->{'SSL'}B= $s->{'SSL'}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $opts->{'ident'}B= $s->{'ident'}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $opts->{'pass'}B= $s->{'pass'}
ABresult
1X1
011
000
1046  
1047 0 ▶ $f->on_done( sub { $cinv->respond( "Connected to $host", level => 1 ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1048 0 ▶ $f->on_fail( sub { $cinv->responderr( "Unable to connect to $host - $_[0]", level => 3 ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1049  
1050 0 return ( "Connecting to $host ..." );
1051 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1052  
1053 sub command_reconnect
1054 : Command_description("Disconnect then reconnect to the IRC server")
1055 : Command_arg('message', eatall => 1)
1056 {
1057 0 ▶ my $self = shift;
Subroutine command_reconnect: not called CC=1 SCAR=6.9
Pod undocumented
1058 0 my ( $message ) = @_;
1059  
1060 0 my $irc = $self->{irc};
1061  
1062 0 $irc->send_message( "QUIT", undef, $message );
1063  
1064 0 $irc->close;
1065  
1066 0 $self->{no_reconnect_on_close} = 1;
1067  
1068 $self->reconnect
1069 0 ▶ ->on_done( sub { undef $self->{no_reconnect_on_close} });
Subroutine __ANON__: not called CC=1 SCAR=6.9
1070  
1071 0 return;
1072 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1073  
1074 sub command_disconnect
1075 : Command_description("Disconnect from the IRC server")
1076 : Command_arg('message?', eatall => 1)
1077 {
1078 0 ▶ my $self = shift;
Subroutine command_disconnect: not called CC=4 SCAR=30.0
Pod undocumented
1079 0 my ( $message ) = @_;
1080  
1081 0 my $irc = $self->{irc};
1082  
1083 0 ▶ if( $irc->read_handle ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($irc->read_handle) { } 0 0 0
1084 0 ▶ $irc->send_message( "QUIT", undef, defined $message ? ( $message ) : () );
Branch: 1 branch
BranchTrueFalseTotal
defined $message ? : 0 0 0
1085 0 $irc->close;
1086  
1087 0 $self->{no_reconnect_on_close} = 1;
1088 }
1089 else {
1090 0 my $timer = $self->{reconnect_timer};
1091 0 ▶ $timer->stop if $timer->is_running;
Branch: 1 branch
BranchTrueFalseTotal
if $timer->is_running 0 0 0
1092 0 $self->set_network_status( "disconnected" );
1093 }
1094  
1095 0 return;
1096 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1097  
1098 sub command_join
1099 : Command_description("Join a channel")
1100 : Command_arg('channel')
1101 : Command_opt('key=$', desc => "join key")
1102 {
1103 0 ▶ my $self = shift;
Subroutine command_join: not called CC=1 SCAR=6.9
Pod undocumented
1104 0 my ( $channel, $opts, $cinv ) = @_;
1105  
1106 0 my $irc = $self->{irc};
1107  
1108 0 my $chanobj = $self->get_channel_or_create( $channel );
1109  
1110 0 $chanobj->reify;
1111  
1112 $chanobj->join(
1113 key => $opts->{key},
1114 on_joined => sub {
1115 0 ▶ $cinv->respond( "Joined $channel", level => 1 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1116 },
1117 on_join_error => sub {
1118 0 ▶ $cinv->responderr( "Cannot join $channel - $_[0]", level => 3 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1119 },
1120 0 );
1121  
1122 0 return;
1123 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1124  
1125 sub command_part
1126 : Command_description("Part a channel")
1127 : Command_arg('channel')
1128 : Command_arg('message?', eatall => 1)
1129 {
1130 0 ▶ my $self = shift;
Subroutine command_part: not called CC=2 SCAR=17.9
Pod undocumented
1131 0 my ( $channel, $message, $cinv ) = @_;
1132  
1133 0 ▶ my $chanobj = $self->get_channel_if_exists( $channel )
Branch: 1 branch
BranchTrueFalseTotal
my $chanobj = $self->get_channel_if_exists($channel) or return "No such channel $channel" 0 0 0
1134 or return "No such channel $channel";
1135  
1136 $chanobj->part(
1137 message => $message,
1138  
1139 on_parted => sub {
1140 0 ▶ $cinv->respond( "Parted $channel", level => 1 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1141 0 $chanobj->destroy;
1142 },
1143 on_part_error => sub {
1144 0 ▶ $cinv->respond( "Cannot part $channel - $_[0]", level => 3 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1145 },
1146 0 );
1147  
1148 0 return;
1149 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1150  
1151 sub command_query
1152 : Command_description("Open a private message window to a user")
1153 : Command_arg('nick')
1154 {
1155 0 ▶ my $self = shift;
Subroutine command_query: not called CC=1 SCAR=6.9
Pod undocumented
1156 0 my ( $nick, $cinv ) = @_;
1157  
1158 0 my $userobj = $self->get_user_or_create( $nick );
1159  
1160 0 $userobj->reify;
1161  
1162 # TODO: Focus it
1163  
1164 0 return;
1165 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1166  
1167 sub command_msg
1168 : Command_description("Send a PRIVMSG to a target")
1169 : Command_arg('target')
1170 : Command_arg('text', eatall => 1)
1171 {
1172 0 ▶ my $self = shift;
Subroutine command_msg: not called CC=2 SCAR=17.9
Pod undocumented
1173 0 my ( $target, $text ) = @_;
1174  
1175 0 ▶ if( my $targetobj = $self->get_target_if_exists( $target ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $targetobj = $self->get_target_if_exists($target)) { } 0 0 0
1176 0 $targetobj->msg( $text );
1177 }
1178 else {
1179 0 my $irc = $self->{irc};
1180 0 $irc->send_message( "PRIVMSG", undef, $target, $text );
1181 }
1182  
1183 0 return;
1184 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1185  
1186 sub command_notice
1187 : Command_description("Send a NOTICE to a target")
1188 : Command_arg('target')
1189 : Command_arg('text', eatall => 1)
1190 {
1191 0 ▶ my $self = shift;
Subroutine command_notice: not called CC=2 SCAR=17.9
Pod undocumented
1192 0 my ( $target, $text ) = @_;
1193  
1194 0 ▶ if( my $targetobj = $self->get_target_if_exists( $target ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $targetobj = $self->get_target_if_exists($target)) { } 0 0 0
1195 0 $targetobj->notice( $text );
1196 }
1197 else {
1198 0 my $irc = $self->{irc};
1199 0 $irc->send_message( "NOTICE", undef, $target, $text );
1200 }
1201  
1202 0 return;
1203 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1204  
1205 sub command_quote
1206 : Command_description("Send a raw IRC command")
1207 : Command_arg('cmd')
1208 : Command_arg('args', collect => 1)
1209 {
1210 0 ▶ my $self = shift;
Subroutine command_quote: not called CC=1 SCAR=6.9
Pod undocumented
1211 0 my ( $cmd, $args ) = @_;
1212  
1213 0 my $irc = $self->{irc};
1214  
1215 0 $irc->send_message( $cmd, undef, @$args );
1216  
1217 0 return;
1218 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1219  
1220 sub command_away
1221 : Command_description("Set AWAY message")
1222 : Command_arg('message', eatall => 1)
1223 {
1224 0 ▶ my $self = shift;
Subroutine command_away: not called CC=2 SCAR=17.9
Pod undocumented
1225 0 my ( $message ) = @_;
1226  
1227 0 my $irc = $self->{irc};
1228  
1229 0 ▶ length $message or $message = "away";
Branch: 1 branch
BranchTrueFalseTotal
length $message or $message = "away" 0 0 0
1230  
1231 0 $irc->send_message( "AWAY", undef, $message );
1232  
1233 0 return;
1234 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1235  
1236 sub command_unaway
1237 : Command_description("Remove AWAY message")
1238 {
1239 0 ▶ my $self = shift;
Subroutine command_unaway: not called CC=1 SCAR=6.9
Pod undocumented
1240  
1241 0 my $irc = $self->{irc};
1242  
1243 0 $irc->send_message( "AWAY", undef );
1244  
1245 0 return;
1246 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1247  
1248 sub command_whois
1249 : Command_description("Send a WHOIS query")
1250 : Command_arg('user')
1251 {
1252 0 ▶ my $self = shift;
Subroutine command_whois: not called CC=2 SCAR=17.9
Pod undocumented
1253 0 my ( $user, $cinv ) = @_;
1254  
1255 0 my $irc = $self->{irc};
1256 0 my $user_folded = $irc->casefold_name( $user );
1257  
1258 0 $irc->send_message( "WHOIS", undef, $user );
1259  
1260 0 ▶ my $f = ( $self->{whois_gate_f}{$user_folded} ||= Future->new );
Condition0%0/3
$self->{"whois_gate_f"}{$user_folded} ||= "Future"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"whois_gate_f"}{$user_folded} ||= "Future"->new
$self->{"whois_gate_f"}{$user_folded} "Future"->new
Truth table0%0/3
A ||= B
A= $self->{"whois_gate_f"}{$user_folded}B= "Future"->new
ABresult
1X1
011
000
1261 $f->on_done( sub {
1262 0 ▶ my ( $data ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
1263  
1264 0 $cinv->respond( "WHOIS $user:" );
1265 0 foreach my $datum ( @$data ) {
1266 0 my %d = %$datum;
1267 0 my $whois = delete $d{whois};
1268  
1269 $cinv->respond( " $whois - " . join( " ",
1270 0 map { my $val = $d{$_};
1271 # 'channels' comes as an ARRAY
1272 0 ▶ ref($val) eq "ARRAY" ? "$_=@{$d{$_}}" : "$_=$d{$_}"
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 0 0 0
1273 } sort keys %d
1274 ) );
1275 }
1276 0 });
1277 $f->on_fail( sub {
1278 0 ▶ my ( $failure ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1279 0 $cinv->responderr( "Cannot WHOIS $user - $failure" );
1280 0 });
1281  
1282 0 return ();
1283 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1284  
1285 use Circle::Collection
1286 name => 'channels',
1287 storage => 'methods',
1288 attrs => [
1289 name => { desc => "name" },
1290 joined => { desc => "currently JOINed?",
1291 transient => 1,
1292 0 ▶ show => sub { $_ ? "yes" : "no" },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
1293 },
1294 autojoin => { desc => "JOIN automatically when connected",
1295 0 ▶ show => sub { $_ ? "yes" : "no" },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
1296 },
1297 4 key => { desc => "join key" },
1298 ],
1299 4 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
1300  
1301 sub channels_list
1302 {
1303 0 ▶ my $self = shift;
Subroutine channels_list: not called CC=1 SCAR=6.9
Pod undocumented
1304 0 return map { $self->channels_get( $_ ) } sort keys %{ $self->{channels} };
1305 }
1306  
1307 sub channels_get
1308 {
1309 0 ▶ my $self = shift;
Subroutine channels_get: not called CC=2 SCAR=17.9
Pod undocumented
1310 0 my ( $name ) = @_;
1311  
1312 0 ▶ my $chan = $self->get_channel_if_exists( $name ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $chan = $self->get_channel_if_exists($name) or return undef 0 0 0
1313  
1314 return {
1315 name => $chan->get_prop_name,
1316 joined => $chan->{state} == Circle::Net::IRC::Channel::STATE_JOINED,
1317 0 ( map { $_ => $chan->{$_} } qw( autojoin key ) ),
1318 };
1319 }
1320  
1321 sub channels_set
1322 {
1323 0 ▶ my $self = shift;
Subroutine channels_set: not called CC=4 SCAR=30.0
Pod undocumented
1324 0 my ( $name, $def ) = @_;
1325  
1326 0 ▶ my $chanobj = $self->get_channel_if_exists( $name ) or die "Missing channel $name for channels_set";
Branch: 1 branch
BranchTrueFalseTotal
my $chanobj = $self->get_channel_if_exists($name) or die "Missing channel $name for channels_set" 0 0 0
1327  
1328 0 foreach (qw( autojoin key )) {
1329 0 ▶ $chanobj->{$_} = $def->{$_} if exists $def->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{$_} 0 0 0
1330 }
1331 }
1332  
1333 sub channels_add
1334 {
1335 0 ▶ my $self = shift;
Subroutine channels_add: not called CC=3 SCAR=24.8
Pod undocumented
1336 0 my ( $name, $def ) = @_;
1337  
1338 0 my $chanobj = $self->get_channel_or_create( $name );
1339  
1340 0 $chanobj->reify;
1341  
1342 0 foreach (qw( autojoin key )) {
1343 0 ▶ $chanobj->{$_} = $def->{$_} if exists $def->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{$_} 0 0 0
1344 }
1345 }
1346  
1347 sub channels_del
1348 {
1349 0 ▶ my $self = shift;
Subroutine channels_del: not called CC=1 SCAR=6.9
Pod undocumented
1350 0 die "TODO: delete channel @_\n";
1351 }
1352  
1353 sub commandable_parent
1354 {
1355 0 ▶ my $self = shift;
Subroutine commandable_parent: not called CC=1 SCAR=6.9
Pod undocumented
1356 0 return $self->{root};
1357 }
1358  
1359 sub enumerable_name
1360 {
1361 0 ▶ my $self = shift;
Subroutine enumerable_name: not called CC=1 SCAR=6.9
Pod undocumented
1362 0 return $self->get_prop_tag;
1363 }
1364  
1365 sub parent
1366 {
1367 0 ▶ my $self = shift;
Subroutine parent: not called CC=1 SCAR=6.9
Pod undocumented
1368 0 return $self->{root};
1369 }
1370  
1371 sub enumerate_items
1372 {
1373 0 ▶ my $self = shift;
Subroutine enumerate_items: not called CC=3 SCAR=24.8
Pod undocumented
1374  
1375 0 my %all = ( %{ $self->{channels} }, %{ $self->{users} } );
1376  
1377 # Filter only the real ones
1378 0 ▶ $all{$_}->get_prop_real or delete $all{$_} for keys %all;
Branch: 1 branch
BranchTrueFalseTotal
$all{$_}->get_prop_real or delete $all{$_} 0 0 0
1379  
1380 0 return { map { $_->enumerable_name => $_ } values %all };
1381 }
1382  
1383 sub get_item
1384 {
1385 0 ▶ my $self = shift;
Subroutine get_item: not called CC=5 SCAR=34.0
Pod undocumented
1386 0 my ( $name, $create ) = @_;
1387  
1388 0 foreach my $items ( $self->{channels}, $self->{users} ) {
1389 0 ▶ return $items->{$name} if exists $items->{$name} and $items->{$name}->get_prop_real;
Branch: 1 branch
BranchTrueFalseTotal
if exists $items->{$name} and $items->{$name}->get_prop_real 0 0 0
Condition0%0/3
exists $items->{$name} and $items->{$name}->get_prop_real
!ll&&!rl&&r
000
MC/DC0%0/2
exists $items->{$name} and $items->{$name}->get_prop_real
exists $items->{$name} $items->{$name}->get_prop_real
Truth table0%0/3
A and B
A= exists $items->{$name}B= $items->{$name}->get_prop_real
ABresult
0X0
100
111
1390 }
1391  
1392 0 ▶ return $self->get_target_or_create( $name ) if $create;
Branch: 1 branch
BranchTrueFalseTotal
if $create 0 0 0
1393  
1394 0 return undef;
1395 }
1396  
1397 4 __PACKAGE__->APPLY_Setting( local_host =>
1398 description => "Local bind address",
1399 type => 'str',
1400 );
1401  
1402 4 __PACKAGE__->APPLY_Setting( nick =>
1403 description => "Initial connection nick",
1404 type => 'str',
1405 storage => 'configured_nick',
1406 );
1407  
1408 4 __PACKAGE__->APPLY_Setting( use_mirc_colours =>
1409 description => "Use mIRC colouring information",
1410 type => 'bool',
1411 default => 1,
1412 );
1413  
1414 ###
1415 # Widgets
1416 ###
1417  
1418 sub get_widget_statusbar
1419 {
1420 0 ▶ my $self = shift;
Subroutine get_widget_statusbar: not called CC=1 SCAR=6.9
Pod undocumented
1421  
1422 0 my $registry = $self->{registry};
1423  
1424 0 my $statusbar = $registry->construct(
1425 "Circle::Widget::Box",
1426 classes => [qw( status )],
1427 orientation => "horizontal",
1428 );
1429  
1430 0 $statusbar->add( $self->get_widget_netname );
1431  
1432 0 my $nicklabel = $registry->construct(
1433 "Circle::Widget::Label",
1434 classes => [qw( nick )],
1435 );
1436 $self->watch_property( "nick",
1437 0 ▶ on_updated => sub { $nicklabel->set_prop_text( $_[1] ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1438 0 );
1439  
1440 0 $statusbar->add( $nicklabel );
1441  
1442 0 my $awaylabel = $registry->construct(
1443 "Circle::Widget::Label",
1444 classes => [qw( away )],
1445 );
1446 $self->watch_property( "away",
1447 0 ▶ on_updated => sub { $awaylabel->set_prop_text( $_[1] ? "[AWAY]" : "" ) }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
1448 0 );
1449  
1450 0 $statusbar->add( $awaylabel );
1451  
1452 0 return $statusbar;
1453 }
1454  
1455 sub get_widget_netname
1456 {
1457 0 ▶ my $self = shift;
Subroutine get_widget_netname: not called CC=2 SCAR=17.9
Pod undocumented
1458  
1459 0 ▶ return $self->{widget_netname} ||= do {
Condition0%0/3
$self->{"widget_netname"} ||= do { my $registry = $self->{"registry"}; my $widget = $registry->construct("Circle::Widget::Label", "classes", ["netname"]); $self->watch_property("tag", "on_updated", sub { my $text = $_[1]; $text .= qq[[$self->{"status"}]] if length $self->{"status"}; $widget->set_prop_text($text); } ); $widget }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"widget_netname"} ||= do { my $registry = $self->{"registry"}; my $widget = $registry->construct("Circle::Widget::Label", "classes", ["netname"]); $self->watch_property("tag", "on_updated", sub { my $text = $_[1]; $text .= qq[[$self->{"status"}]] if length $self->{"status"}; $widget->set_prop_text($text); } ); $widget }
$self->{"widget_netname"} do { my $registry = $self->{"registry"}; my $widget = $registry->construct("Circle::Widget::Label", "classes", ["netname"]); $self->watch_property("tag", "on_updated", sub { my $text = $_[1]; $text .= qq[[$self->{"status"}]] if length $self->{"status"}; $widget->set_prop_text($text); } ); $widget }
Truth table0%0/3
A ||= B
A= $self->{"widget_netname"}B= do { my $registry = $self->{"registry"}; my $widget = $registry->construct("Circle::Widget::Label", "classes", ["netname"]); $self->watch_property("tag", "on_updated", sub { my $text = $_[1]; $text .= qq[[$self->{"status"}]] if length $self->{"status"}; $widget->set_prop_text($text); } ); $widget }
ABresult
1X1
011
000
1460 0 my $registry = $self->{registry};
1461  
1462 0 my $widget = $registry->construct(
1463 "Circle::Widget::Label",
1464 classes => [qw( netname )],
1465 );
1466 $self->watch_property( "tag",
1467 on_updated => sub {
1468 0 ▶ my $text = $_[1];
Subroutine __ANON__: not called CC=2 SCAR=17.9
1469 0 ▶ $text .= "[$self->{status}]" if length $self->{status};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"status"} 0 0 0
1470 0 $widget->set_prop_text( $text );
1471 }
1472 0 );
1473 0 $widget;
1474 };
1475 }
1476  
1477 sub get_widget_channel_completegroup
1478 {
1479 0 ▶ my $self = shift;
Subroutine get_widget_channel_completegroup: not called CC=2 SCAR=17.9
Pod undocumented
1480  
1481 0 ▶ return $self->{widget_channel_completegroup} ||= do {
Condition0%0/3
$self->{"widget_channel_completegroup"} ||= do { my $registry = $self->{"registry"}; my $widget = $registry->construct("Circle::Widget::Entry::CompleteGroup"); my %id_to_name; $self->watch_property("channels", "on_set", sub { my(undef, $channels) = @_; $widget->set(map({$id_to_name{$_->id} = $_->name;} values %$channels)); } , "on_add", sub { my(undef, $added) = @_; $widget->add($id_to_name{$added->id} = $added->name); } , "on_del", sub { my(undef, $deleted_id) = @_; $widget->remove(delete $id_to_name{$deleted_id}); } ); $widget->set(keys %{$$self{"channels"};}); $widget }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"widget_channel_completegroup"} ||= do { my $registry = $self->{"registry"}; my $widget = $registry->construct("Circle::Widget::Entry::CompleteGroup"); my %id_to_name; $self->watch_property("channels", "on_set", sub { my(undef, $channels) = @_; $widget->set(map({$id_to_name{$_->id} = $_->name;} values %$channels)); } , "on_add", sub { my(undef, $added) = @_; $widget->add($id_to_name{$added->id} = $added->name); } , "on_del", sub { my(undef, $deleted_id) = @_; $widget->remove(delete $id_to_name{$deleted_id}); } ); $widget->set(keys %{$$self{"channels"};}); $widget }
$self->{"widget_channel_completegroup"} do { my $registry = $self->{"registry"}; my $widget = $registry->construct("Circle::Widget::Entry::CompleteGroup"); my %id_to_name; $self->watch_property("channels", "on_set", sub { my(undef, $channels) = @_; $widget->set(map({$id_to_name{$_->id} = $_->name;} values %$channels)); } , "on_add", sub { my(undef, $added) = @_; $widget->add($id_to_name{$added->id} = $added->name); } , "on_del", sub { my(undef, $deleted_id) = @_; $widget->remove(delete $id_to_name{$deleted_id}); } ); $widget->set(keys %{$$self{"channels"};}); $widget }
Truth table0%0/3
A ||= B
A= $self->{"widget_channel_completegroup"}B= do { my $registry = $self->{"registry"}; my $widget = $registry->construct("Circle::Widget::Entry::CompleteGroup"); my %id_to_name; $self->watch_property("channels", "on_set", sub { my(undef, $channels) = @_; $widget->set(map({$id_to_name{$_->id} = $_->name;} values %$channels)); } , "on_add", sub { my(undef, $added) = @_; $widget->add($id_to_name{$added->id} = $added->name); } , "on_del", sub { my(undef, $deleted_id) = @_; $widget->remove(delete $id_to_name{$deleted_id}); } ); $widget->set(keys %{$$self{"channels"};}); $widget }
ABresult
1X1
011
000
1482 0 my $registry = $self->{registry};
1483  
1484 0 my $widget = $registry->construct(
1485 "Circle::Widget::Entry::CompleteGroup",
1486 );
1487  
1488 # Have to cache id->name so we can delete properly
1489 # TODO: Consider fixing on_del
1490 0 my %id_to_name;
1491 $self->watch_property( "channels",
1492 on_set => sub {
1493 0 ▶ my ( undef, $channels ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1494 0 $widget->set( map { $id_to_name{$_->id} = $_->name } values %$channels );
1495 },
1496 on_add => sub {
1497 0 ▶ my ( undef, $added ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1498 0 $widget->add( $id_to_name{$added->id} = $added->name );
1499 },
1500 on_del => sub {
1501 0 ▶ my ( undef, $deleted_id ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1502 0 $widget->remove( delete $id_to_name{$deleted_id} );
1503 },
1504 0 );
1505  
1506 0 $widget->set( keys %{ $self->{channels} } );
1507  
1508 0 $widget;
1509 };
1510 }
1511  
1512 sub add_entry_widget_completegroups
1513 {
1514 0 ▶ my $self = shift;
Subroutine add_entry_widget_completegroups: not called CC=1 SCAR=6.9
Pod undocumented
1515 0 my ( $entry ) = @_;
1516  
1517 0 $entry->add_prop_completions( $self->get_widget_channel_completegroup );
1518 }
1519  
1520 sub get_widget_commandentry
1521 {
1522 0 ▶ my $self = shift;
Subroutine get_widget_commandentry: not called CC=1 SCAR=6.9
Pod undocumented
1523 0 my $widget = $self->SUPER::get_widget_commandentry;
1524  
1525 0 $self->add_entry_widget_completegroups( $widget );
1526  
1527 0 return $widget;
1528 }
1529  
1530 4 0x55AA;
↑ Summary blib/lib/Circle/GlobalRules.pm »