Circle/Net/IRC/User.pm

filter: Statementstmt 18.1% 24 / 132 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 26.9% 7 / 26 Podpod 0.0% 0 / 17 totaltotal 15.2% 31 / 204 CC 10 SCAR 19.9
CC
10
Cov
16%
on_message_RPL_AWAY
30.0
update_ident
12.0
on_message
6.0
CRAP 7.3
« Circle/Rule/Store.pm ↑ Summary Circle/RootObj.pm »
1 # You may distribute under the terms of the GNU General Public License
2 #
3 # (C) Paul Evans, 2008-2016 -- leonerd@leonerd.org.uk
4  
5 package Circle::Net::IRC::User;
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 4 ▶use base qw( Circle::Net::IRC::Target );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 our $VERSION = '0.173320';
12  
13 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Don't reprint RPL_USERISAWAY message within 1 hour
16 # TODO: Some sort of config setting system
17 4 my $awaytime_print = 3600;
18  
19 sub default_message_level
20 0 ▶{
Subroutine default_message_level: not called CC=1 SCAR=6.9
Pod undocumented
21 0 my $self = shift;
22 0 my ( $hints ) = @_;
23  
24 0 return 3;
25 }
26  
27 sub on_message
28 0 ▶{
Subroutine on_message: not called CC=2 SCAR=17.9
Pod undocumented
29 0 my $self = shift;
30 0 my ( $command, $message, $hints ) = @_;
31  
32 # Messages from the user will have a prefix_user hint, server messages will not.
33 0 ▶ if( defined( my $ident = $hints->{prefix_user} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ident = $hints->{"prefix_user"})) 0 0 0
34 0 my $hostname = $hints->{prefix_host};
35  
36 0 $self->update_ident( "$ident\@$hostname" );
37 }
38  
39 0 return $self->SUPER::on_message( @_ );
40 }
41  
42 sub update_ident
43 0 ▶{
Subroutine update_ident: not called CC=3 SCAR=24.8
Pod undocumented
44 0 my $self = shift;
45 0 my ( $ident ) = @_;
46  
47 0 ▶ return if defined $self->get_prop_ident and $self->get_prop_ident eq $ident;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->get_prop_ident and $self->get_prop_ident eq $ident 0 0 0
Condition0%0/3
defined $self->get_prop_ident and $self->get_prop_ident eq $ident
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->get_prop_ident and $self->get_prop_ident eq $ident
defined $self->get_prop_ident $self->get_prop_ident eq $ident
Truth table0%0/3
A and B
A= defined $self->get_prop_identB= $self->get_prop_ident eq $ident
ABresult
0X0
100
111
48 0 $self->set_prop_ident( $ident );
49 }
50  
51 sub on_message_NICK
52 0 ▶{
Subroutine on_message_NICK: not called CC=1 SCAR=6.9
Pod undocumented
53 0 my $self = shift;
54 0 my ( $message, $hints ) = @_;
55  
56 0 my $oldnick = $self->name;
57 0 my $newnick = $hints->{new_nick};
58  
59 0 $self->push_displayevent( "irc.nick", { oldnick => $oldnick, newnick => $newnick } );
60 0 $self->bump_level( 1 );
61  
62 0 $self->set_prop_name( $newnick );
63 0 $self->set_prop_tag( $newnick );
64  
65 0 my $oldnick_folded = $self->{irc}->casefold_name( $oldnick );
66  
67 0 $self->fire_event( "change_nick", $oldnick, $oldnick_folded, $newnick, $hints->{new_nick_folded} );
68  
69 0 return 1;
70 }
71  
72 sub on_message_QUIT
73 0 ▶{
Subroutine on_message_QUIT: not called CC=2 SCAR=17.9
Pod undocumented
74 0 my $self = shift;
75 0 my ( $message, $hints ) = @_;
76  
77 0 my $nick = $self->name;
78 0 my $quitmsg = $hints->{text};
79  
80 0 ▶ defined $quitmsg or $quitmsg = "";
Branch: 1 branch
BranchTrueFalseTotal
defined $quitmsg or $quitmsg = "" 0 0 0
81  
82 0 my $net = $self->{net};
83 0 my $quitmsg_formatted = $net->format_text( $quitmsg );
84  
85 0 my $userhost = "$hints->{prefix_user}\@$hints->{prefix_host}";
86  
87 0 $self->push_displayevent( "irc.quit", { nick => $nick, userhost => $userhost, quitmsg => $quitmsg_formatted } );
88 0 $self->bump_level( 1 );
89  
90 0 return 1;
91 }
92  
93 sub on_message_RPL_AWAY
94 0 ▶{
Subroutine on_message_RPL_AWAY: not called CC=5 SCAR=34.0
Pod undocumented
95 0 my $self = shift;
96 0 my ( $message, $hints ) = @_;
97  
98 0 my $nick = $self->name;
99 0 my $awaymsg = $hints->{text};
100  
101 0 ▶ defined $awaymsg or $awaymsg = "";
Branch: 1 branch
BranchTrueFalseTotal
defined $awaymsg or $awaymsg = "" 0 0 0
102  
103 # Surpress the message if it's already been printed and it's quite soon
104 0 my $now = time;
105 0 ▶ if( defined $self->{printed_awaymsg} and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"printed_awaymsg"} and $self->{"printed_awaymsg"} eq $awaymsg and $now < $self->{"printed_awaytime"} + $awaytime_print) 0 0 0
Condition0%0/6
defined $self->{"printed_awaymsg"} and $self->{"printed_awaymsg"} eq $awaymsg and $now < $self->{"printed_awaytime"} + $awaytime_print
!ll&&!rl&&r
000
defined $self->{"printed_awaymsg"} and $self->{"printed_awaymsg"} eq $awaymsg
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{"printed_awaymsg"} and $self->{"printed_awaymsg"} eq $awaymsg and $now < $self->{"printed_awaytime"} + $awaytime_print
defined $self->{"printed_awaymsg"} $self->{"printed_awaymsg"} eq $awaymsg $now < $self->{"printed_awaytime"} + $awaytime_print
Truth table0%0/4
A and B and C
A= defined $self->{"printed_awaymsg"}B= $self->{"printed_awaymsg"} eq $awaymsgC= $now < $self->{"printed_awaytime"} + $awaytime_print
ABCresult
0XX0
10X0
1100
1111
106 $self->{printed_awaymsg} eq $awaymsg and
107 $now < $self->{printed_awaytime} + $awaytime_print ) {
108 0 return 1;
109 }
110  
111 0 my $net = $self->{net};
112 0 my $awaymsg_formatted = $net->format_text( $awaymsg );
113  
114 0 my $userhost = "$hints->{prefix_user}\@$hints->{prefix_host}";
115  
116 0 $self->push_displayevent( "irc.away", { nick => $nick, userhost => $userhost, text => $awaymsg_formatted } );
117 0 $self->bump_level( 1 );
118  
119 0 $self->{printed_awaymsg} = $awaymsg;
120 0 $self->{printed_awaytime} = $now;
121  
122 0 return 1;
123 }
124  
125 sub on_message_RPL_LOGON
126 0 ▶{
Subroutine on_message_RPL_LOGON: not called CC=1 SCAR=6.9
Pod undocumented
127 0 my $self = shift;
128 0 $self->on_message_RPL_NOWON( @_ );
129  
130 0 my $nick = $self->name;
131  
132 0 $self->push_displayevent( "irc.online", { nick => $nick } );
133 0 $self->bump_level( 1 );
134  
135 0 return 1;
136 }
137  
138 sub on_message_RPL_LOGOFF
139 0 ▶{
Subroutine on_message_RPL_LOGOFF: not called CC=1 SCAR=6.9
Pod undocumented
140 0 my $self = shift;
141 0 $self->on_message_RPL_NOWOFF( @_ );
142  
143 0 my $nick = $self->name;
144  
145 0 $self->push_displayevent( "irc.offline", { nick => $nick } );
146 0 $self->bump_level( 1 );
147  
148 0 return 1;
149 }
150  
151 sub on_message_RPL_NOWON
152 0 ▶{
Subroutine on_message_RPL_NOWON: not called CC=1 SCAR=6.9
Pod undocumented
153 0 my $self = shift;
154  
155 0 $self->set_prop_presence( "online" );
156  
157 0 return 1;
158 }
159  
160 sub on_message_RPL_NOWOFF
161 0 ▶{
Subroutine on_message_RPL_NOWOFF: not called CC=1 SCAR=6.9
Pod undocumented
162 0 my $self = shift;
163  
164 0 $self->set_prop_presence( "offline" );
165  
166 0 return 1;
167 }
168  
169 # Send it back
170 sub on_message_whois
171 0 ▶{
Subroutine on_message_whois: not called CC=1 SCAR=6.9
Pod undocumented
172 0 my $self = shift;
173 0 my ( $message, $hints ) = @_;
174  
175 0 my $net = $self->{net};
176 0 $net->on_message_whois( $message, $hints );
177 }
178  
179 sub command_close
180 0 ▶ : Command_description("Close the window")
Subroutine command_close: not called CC=1 SCAR=6.9
Pod undocumented
181 {
182 0 my $self = shift;
183  
184 0 $self->destroy;
185 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
186  
187 sub command_requery
188 0 ▶ : Command_description("Change the target nick for this user query")
Subroutine command_requery: not called CC=1 SCAR=6.9
Pod undocumented
189 : Command_arg('newnick')
190 {
191 0 my $self = shift;
192 0 my ( $newnick ) = @_;
193  
194 0 my $oldnick = $self->name;
195  
196 0 $self->set_prop_name( $newnick );
197 0 $self->set_prop_tag( $newnick );
198  
199 0 my $oldnick_folded = $self->{irc}->casefold_name( $oldnick );
200 0 my $newnick_folded = $self->{irc}->casefold_name( $newnick );
201  
202 0 $self->fire_event( "change_nick", $oldnick, $oldnick_folded, $newnick, $newnick_folded );
203  
204 0 return ( "Now talking to $newnick" );
205 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
206  
207 sub command_whois
208 0 ▶ : Command_description("Send a WHOIS query")
Subroutine command_whois: not called CC=2 SCAR=17.9
Pod undocumented
209 : Command_arg('user?')
210 {
211 0 my $self = shift;
212 0 my ( $user, $cinv ) = @_;
213  
214 0 ▶ $user //= $self->name;
Condition0%0/3
$user //= $self->name
l!l&&r!l&&!r
000
MC/DC0%0/2
$user //= $self->name
$user $self->name
Truth table0%0/3
A //= B
A= $userB= $self->name
ABresult
1X1
011
000
215  
216 0 $self->{net}->command_whois( $user, $cinv );
217 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
218  
219 sub make_widget_pre_scroller
220 0 ▶{
Subroutine make_widget_pre_scroller: not called CC=1 SCAR=6.9
Pod undocumented
221 0 my $self = shift;
222 0 my ( $box ) = @_;
223  
224 0 my $registry = $self->{registry};
225  
226 0 my $identlabel = $registry->construct(
227 "Circle::Widget::Label",
228 classes => [qw( ident )],
229 );
230 $self->watch_property( "ident",
231 0 ▶ on_updated => sub { $identlabel->set_prop_text( $_[1] ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
232 0 );
233  
234 0 $box->add( $identlabel );
235 }
236  
237 sub get_widget_presence
238 0 ▶{
Subroutine get_widget_presence: not called CC=1 SCAR=6.9
Pod undocumented
239 0 my $self = shift;
240  
241 0 my $registry = $self->{registry};
242 0 my $presencelabel = $registry->construct(
243 "Circle::Widget::Label",
244 classes => [qw( presence )],
245 );
246 $self->watch_property( "presence",
247 0 ▶ on_updated => sub { $presencelabel->set_prop_text( "($_[1])" ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
248 0 );
249  
250 0 return $presencelabel;
251 }
252  
253 sub get_widget_statusbar
254 0 ▶{
Subroutine get_widget_statusbar: not called CC=1 SCAR=6.9
Pod undocumented
255 0 my $self = shift;
256  
257 0 my $registry = $self->{registry};
258 0 my $net = $self->{net};
259  
260 0 my $statusbar = $registry->construct(
261 "Circle::Widget::Box",
262 classes => [qw( status )],
263 orientation => "horizontal",
264 );
265  
266 0 $statusbar->add( $net->get_widget_netname );
267  
268 0 $statusbar->add( $self->get_widget_presence );
269  
270 0 return $statusbar;
271 }
272  
273 4 0x55AA;
« Circle/Rule/Store.pm ↑ Summary Circle/RootObj.pm »