Circle/RootObj.pm

filter: Statementstmt 52.0% 169 / 325 Branchbran 24.2% 17 / 70 Conditioncond 38.4% 5 / 13 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 59.0% 36 / 61 Podpod 0.0% 0 / 21 totaltotal 45.7% 228 / 498 CC 47 SCAR 19.7
CC
47
Cov
47%
command_session_clonefrom
30.0
command_rerequire
24.4
__ANON__
20.0
CRAP 7.1
« Circle/Net/IRC/User.pm ↑ Summary Circle/Widget/Entry.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::RootObj;
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( Tangence::Object Circle::WindowItem );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 our $VERSION = '0.173320';
12  
13 4 ▶use Class::Method::Modifiers;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use YAML (); # 'Dump' and 'Load' are a bit generic; we'll call by FQN
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 ▶use Circle::Rule::Store;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 require Circle::GlobalRules;
20  
21 4 ▶use Circle::CommandInvocation;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 4 ▶use Module::Pluggable sub_name => "net_types",
Subroutine BEGIN: called CC=1 SCAR=0.0
24 search_path => [ "Circle::Net" ],
25 only => qr/^Circle::Net::\w+$/, # Not inner ones
26 4 force_search_all_paths => 1;
27  
28 {
29 4 foreach my $class ( net_types ) {
30 8 ( my $file = "$class.pm" ) =~ s{::}{/}g;
31 8 require $file;
32 }
33 }
34  
35 4 ▶use Data::Dump;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 4 ▶use constant CIRCLERC => $ENV{CIRCLERC} || "$ENV{HOME}/.circlerc";
Subroutine BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{'CIRCLERC'} || "$ENV{'HOME'}/.circlerc"
l!l
04
MC/DC0%0/1
$ENV{'CIRCLERC'} || "$ENV{'HOME'}/.circlerc"
$ENV{'CIRCLERC'}
Truth table50%1/2
A
A= $ENV{'CIRCLERC'}
Aresult
11
00
38  
39 sub _nettype2class
40 2 ▶{
Subroutine _nettype2class: called CC=4 SCAR=14.0
41 2 my ( $type ) = @_;
42  
43 2 foreach ( __PACKAGE__->net_types ) {
44 4 my $thistype = eval { $_->NETTYPE };
45 4 ▶ if( defined $thistype and $thistype eq $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $thistype and $thistype eq $type) 2 2 4
Condition66%2/3
defined $thistype and $thistype eq $type
!ll&&!rl&&r
022
MC/DC50%1/2
defined $thistype and $thistype eq $type
defined $thistype $thistype eq $type
Truth table66%2/3
A and B
A= defined $thistypeB= $thistype eq $type
ABresult
0X0
100
111
46 2 return $_;
47 }
48 }
49  
50 0 return undef;
51 }
52  
53 sub new
54 3 ▶{
Subroutine new: called CC=4 SCAR=14.7
Pod undocumented
55 3 my $class = shift;
56 3 my %args = @_;
57  
58 3 ▶ my $loop = delete $args{loop} or croak "Need a loop";
Branch: 1 branch
BranchTrueFalseTotal
my $loop = delete $args{"loop"} or croak("Need a loop") 3 0 3
59  
60 3 my $self = $class->SUPER::new( %args );
61  
62 3 $self->{loop} = $loop;
63  
64 3 my $rulestore = $self->{rulestore} = Circle::Rule::Store->new();
65 3 Circle::GlobalRules::register( $rulestore );
66  
67 3 ▶ my $file = $args{config} // CIRCLERC;
Condition50%1/2
$args{"config"} // "/home/cpancover/.circlerc"
l!l
03
MC/DC0%0/1
$args{"config"} // "/home/cpancover/.circlerc"
$args{"config"}
Truth table50%1/2
A
A= $args{"config"}
Aresult
11
00
68 3 ▶ if( -r $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $file) 0 3 3
69 0 my $config = YAML::LoadFile( $file );
70 0 $self->load_configuration( $config );
71 }
72  
73 3 return $self;
74 }
75  
76 sub add_network
77 2 ▶{
Subroutine add_network: called CC=3 SCAR=12.0
Pod undocumented
78 2 my $self = shift;
79 2 my ( $class, $name ) = @_;
80  
81 2 my $loop = $self->{loop};
82  
83 # Late-loading to support out-of-tree classes so they don't have to declare
84 # in the .tan file
85 2 eval { Tangence::Class->for_perlname( $class ) } or
86 0 ▶ eval { $class->DECLARE_TANGENCE } or
Branch: 1 branch
BranchTrueFalseTotal
eval { do { "Tangence::Class"->for_perlname($class) } } or eval { do { $class->DECLARE_TANGENCE } } or croak("Unknown Tangence::Class for '${class}' and can't lazy-load it") 2 0 2
Condition33%1/3
eval { do { "Tangence::Class"->for_perlname($class) } } or eval { do { $class->DECLARE_TANGENCE } }
l!l&&r!l&&!r
200
MC/DC0%0/2
eval { do { "Tangence::Class"->for_perlname($class) } } or eval { do { $class->DECLARE_TANGENCE } }
eval { do { "Tangence::Class"->for_perlname($class) } } eval { do { $class->DECLARE_TANGENCE } }
Truth table33%1/3
A or B
A= eval { do { "Tangence::Class"->for_perlname($class) } }B= eval { do { $class->DECLARE_TANGENCE } }
ABresult
1X1
011
000
87 croak "Unknown Tangence::Class for '$class' and can't lazy-load it";
88  
89 2 my $registry = $self->{registry};
90 2 my $newnet = $registry->construct(
91 $class,
92 tag => $name,
93 root => $self,
94 loop => $loop,
95 );
96  
97 0 ▶ $newnet->subscribe_event( destroy => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
98 0 my ( $newnet ) = @_;
99 0 $self->broadcast_sessions( "delete_item", $newnet );
100 0 $self->del_prop_networks( $name );
101 2 } );
102  
103 2 $self->fire_event( "network_added", $newnet );
104 2 $self->add_prop_networks( $name => $newnet );
105  
106 2 $self->broadcast_sessions( "new_item", $newnet );
107  
108 2 return $newnet;
109 }
110  
111 sub del_network
112 0 ▶{
Subroutine del_network: not called CC=1 SCAR=6.9
Pod undocumented
113 0 my $self = shift;
114 0 my ( $network ) = @_;
115  
116 0 $network->destroy;
117 }
118  
119 use Circle::Collection
120 4 ▶ name => 'networks',
Subroutine BEGIN: called CC=1 SCAR=2.2
121 storage => {
122 0 ▶ list => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
123 0 my $self = shift;
124 0 my $networks = $self->get_prop_networks;
125 0 return map { { name => $_, type => $networks->{$_}->NETTYPE } } sort keys %$networks;
126 },
127  
128 2 ▶ get => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
129 2 my $self = shift;
130 2 my ( $name ) = @_;
131 2 ▶ my $network = $self->get_prop_networks->{$name} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $network = $self->get_prop_networks->{$name} or return undef 0 2 2
132 0 return { name => $name, type => $network->NETTYPE };
133 },
134  
135 2 ▶ add => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
136 2 my $self = shift;
137 2 my ( $name, $item ) = @_;
138  
139 2 my $class = _nettype2class( $item->{type} );
140  
141 2 ▶ defined $class or die "unrecognised network type '$item->{type}'\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $class or die qq[unrecognised network type '$item->{"type"}'\n] 2 0 2
142  
143 2 $self->add_network( $class, $name );
144 },
145  
146 0 ▶ del => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
147 0 my $self = shift;
148 0 my ( $name ) = @_;
149 0 ▶ my $network = $self->get_prop_networks->{$name} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $network = $self->get_prop_networks->{$name} or return 0 0 0
150  
151 0 ▶ $network->connected and die "still connected\n";
Branch: 1 branch
BranchTrueFalseTotal
$network->connected and die "still connected\n" 0 0 0
152  
153 0 $self->del_network( $network );
154 },
155 },
156 attrs => [
157 name => {},
158 type => { nomod => 1, default => "irc" },
159 ],
160 config => {
161 type => "hash",
162 0 ▶ load => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
163 0 my $self = shift;
164 0 my ( $name, $ynode ) = @_;
165 0 $self->get_prop_networks->{$name}->load_configuration( $ynode );
166 },
167 0 ▶ store => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
168 0 my $self = shift;
169 0 my ( $name, $ynode ) = @_;
170 0 $self->get_prop_networks->{$name}->store_configuration( $ynode );
171 },
172 },
173 4 ;
174  
175 4 our %sessions;
176  
177 sub add_session
178 2 ▶{
Subroutine add_session: called CC=2 SCAR=7.0
Pod undocumented
179 2 my $self = shift;
180 2 my ( $identity, $type ) = @_;
181  
182 2 eval "require $type";
183 2 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
184  
185 2 my $registry = $self->{registry};
186  
187 2 my $session = $registry->construct(
188 $type,
189 root => $self,
190 identity => $identity,
191 );
192  
193 2 return $sessions{$identity} = $session;
194 }
195  
196 sub method_get_session
197 2 ▶{
Subroutine method_get_session: called CC=3 SCAR=11.2
Pod undocumented
198 2 my $self = shift;
199 2 my ( $ctx, $opts ) = @_;
200  
201 2 my $identity = $ctx->stream->identity;
202  
203 2 ▶ return $sessions{$identity} if exists $sessions{$identity};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Circle::RootObj::sessions{$identity} 0 2 2
204
205 2 my $type = _session_type( $opts );
206  
207 2 ▶ defined $type or die "Cannot identify a session type\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $type or die "Cannot identify a session type\n" 2 0 2
208  
209 2 return $self->add_session( $identity, $type );
210 }
211  
212 sub broadcast_sessions
213 2 ▶{
Subroutine broadcast_sessions: called CC=3 SCAR=11.1
Pod undocumented
214 2 my $self = shift;
215 2 my ( $method, @args ) = @_;
216  
217 2 foreach my $session ( values %sessions ) {
218 2 ▶ $session->$method( @args ) if $session->can( $method );
Branch: 1 branch
BranchTrueFalseTotal
if $session->can($method) 2 0 2
219 }
220 }
221  
222 sub invoke_session
223 0 ▶{
Subroutine invoke_session: not called CC=3 SCAR=24.8
Pod undocumented
224 0 my $self = shift;
225 0 my ( $conn, $method, @args ) = @_;
226  
227 0 my $session = $sessions{$conn->identity};
228 0 ▶ return unless $session;
Branch: 1 branch
BranchTrueFalseTotal
unless $session 0 0 0
229  
230 0 ▶ $session->$method( @args ) if $session->can( $method );
Branch: 1 branch
BranchTrueFalseTotal
if $session->can($method) 0 0 0
231 }
232  
233 sub _session_type
234 2 ▶{
Subroutine _session_type: called CC=2 SCAR=7.6
235 2 my ( $opts ) = @_;
236 2 my %opts = map { $_ => 1 } @$opts;
237  
238 2 ▶ if( $opts{tabs} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"tabs"}) 2 0 2
239 2 delete $opts{tabs};
240 2 require Circle::Session::Tabbed;
241 2 return Circle::Session::Tabbed::_session_type( \%opts );
242 }
243  
244 0 print STDERR "Need Session for options\n";
245 0 print STDERR " ".join( "|", sort keys %opts )."\n";
246  
247 0 return undef;
248 }
249  
250 use Circle::Collection
251 4 ▶ name => 'sessions',
Subroutine BEGIN: called CC=1 SCAR=1.7
252 storage => {
253 0 ▶ list => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
254 0 map { my $class = ref $sessions{$_}; $class =~ s/^Circle::Session:://;
255 0 { name => $_, type => $class } } sort keys %sessions;
256 },
257 },
258 4 attrs => [
259 name => {},
260 type => { nomod => 1 },
261 ],
262 commands => {
263 # Disable add modify del
264 add => undef, mod => undef, del => undef,
265 },
266 config => 0,
267 4 ;
268  
269 sub command_session
270 0 ▶ : Command_description("Manage the current session")
Subroutine command_session: not called CC=1 SCAR=0.0
Pod undocumented
271 {
272 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
273  
274 sub command_session_info
275 0 ▶ : Command_description("Show information about the session")
Subroutine command_session_info: not called CC=3 SCAR=24.8
Pod undocumented
276 : Command_subof('session')
277 : Command_default()
278 {
279 0 my $self = shift;
280 0 my ( $cinv ) = @_;
281  
282 0 my $identity = $cinv->connection->identity;
283 0 ▶ my $session = defined $identity ? $sessions{$identity} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $identity ? : 0 0 0
284  
285 0 ▶ unless( defined $session ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $session) 0 0 0
286 0 $cinv->responderr( "Cannot find a session for this identity" );
287 0 return;
288 }
289  
290 0 ( my $type = ref $session ) =~ s/^Circle::Session:://;
291  
292 0 $cinv->respond_table(
293 [
294 [ Type => $type ],
295 [ Identity => $identity ],
296 [ Items => scalar $session->items ],
297 ],
298 colsep => ": ",
299 );
300  
301 0 return;
302 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
303  
304 sub command_session_clonefrom
305 0 ▶ : Command_description("Clone items from another session")
Subroutine command_session_clonefrom: not called CC=5 SCAR=34.0
Pod undocumented
306 : Command_subof('session')
307 : Command_arg('name')
308 {
309 0 my $self = shift;
310 0 my ( $name, $cinv ) = @_;
311  
312 0 my $identity = $cinv->connection->identity;
313  
314 0 ▶ my $destsession = defined $identity ? $sessions{$identity} : undef or
Branch: 2 branches
BranchTrueFalseTotal
my $destsession = defined $identity ? $Circle::RootObj::sessions{$identity} : undef or return $cinv->responderr("Cannot find a session for this identity") 0 0 0
defined $identity ? : 0 0 0
315 return $cinv->responderr( "Cannot find a session for this identity" );
316  
317 0 ▶ my $srcsession = $sessions{$name} or
Branch: 1 branch
BranchTrueFalseTotal
my $srcsession = $Circle::RootObj::sessions{$name} or return $cinv->responderr("Cannot find a session called '${name}'") 0 0 0
318 return $cinv->responderr( "Cannot find a session called '$name'" );
319  
320 0 ▶ eval { $destsession->clonefrom( $srcsession ); 1 } or
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $destsession->clonefrom($srcsession); 1 } } or return $cinv->responderr("Cannot clone $name into $identity - $@") 0 0 0
321 return $cinv->responderr( "Cannot clone $name into $identity - $@" );
322  
323 0 return;
324 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
325  
326 sub command_eval
327 2 ▶ : Command_description("Evaluate a perl expression")
Subroutine command_eval: called CC=7 SCAR=23.5
Pod undocumented
328 : Command_arg('expr', eatall => 1)
329 {
330 2 my $self = shift;
331 2 my ( $expr, $cinv ) = @_;
332  
333 2 my $connection = $cinv->connection;
334  
335 2 my $identity = $connection->identity;
336 2 ▶ my $session = defined $identity ? $sessions{$identity} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $identity ? : 2 0 2
337  
338 my %pad = (
339 ROOT => $self,
340 LOOP => $self->{loop},
341 2 CONN => $connection,
342 ITEM => $cinv->invocant,
343 SESSION => $session,
344 );
345  
346 2 my $result = do {
347 0 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
348 0 my $msg = $_[0];
349 0 $msg =~ s/ at \(eval \d+\) line \d+\.$//;
350 0 chomp $msg;
351 0 $cinv->respondwarn( $msg, level => 2 );
352 2 };
353  
354 2 eval join( "", map { "my \$$_ = \$pad{$_}; " } keys %pad ) . "$expr";
355 };
356  
357 2 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 2 2
358 0 my $err = $@; chomp $err;
359 0 $cinv->responderr( "Died: $err" );
360 }
361 else {
362 2 my @lines;
363  
364 my $timedout;
365 0 ▶ local $SIG{ALRM} = sub { $timedout = 1; die };
Subroutine __ANON__: not called CC=1 SCAR=2.6
366 2 eval {
367 2 alarm(5);
368 2 @lines = split m/\n/, Data::Dump::dump($result);
369 2 alarm(0);
370 };
371  
372 2 ▶ if( $timedout ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timedout) 0 2 2
373 0 $cinv->responderr( "Failed - took too long to render results. Try something more specific" );
374 0 return;
375 }
376  
377 2 ▶ if( @lines > 20 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines > 20) 0 2 2
378 0 @lines = ( @lines[0..18], "...", $lines[-1] );
379 }
380  
381 2 ▶ if( @lines == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines == 1) { } 2 0 2
382 2 $cinv->respond( "Result: $lines[0]" );
383 }
384 else {
385 0 $cinv->respond( "Result:" );
386 0 $cinv->respond( " $_" ) for @lines;
387 }
388 }
389  
390 2 return;
391 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
392  
393 sub command_rerequire
394 0 ▶ : Command_description("Rerequire a perl module")
Subroutine command_rerequire: not called CC=5 SCAR=31.9
Pod undocumented
395 : Command_arg('module')
396 {
397 0 my $self = shift;
398 0 my ( $module, $cinv ) = @_;
399  
400 # This might be a module name Foo::Bar or a filename Foo/Bar.pm
401 0 my $filename;
402  
403 0 ▶ if( $module =~ m/::/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($module =~ /::/) { } 0 0 0
elsif ($module =~ /^(.*)\.pm$/) { } 0 0 0
404 0 ( $filename = $module ) =~ s{::}{/}g;
405 0 $filename .= ".pm";
406 }
407 elsif( $module =~ m/^(.*)\.pm$/ ) {
408 0 $filename = $module;
409 0 ( $module = $1 ) =~ s{/}{::}g;
410 }
411 else {
412 0 return $cinv->responderr( "Unable to recognise if $module is a module name or a file name" );
413 }
414  
415 0 ▶ if( !exists $INC{$filename} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $INC{$filename}) 0 0 0
416 0 return $cinv->responderr( "Module $module in file $filename isn't loaded" );
417 }
418  
419 {
420 0 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
421 0 my $msg = $_[0];
422 0 $msg =~ s/ at \(eval \d+\) line \d+\.$//;
423 0 chomp $msg;
424 0 $cinv->respondwarn( $msg, level => 2 );
425 0 };
426  
427 4 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
428  
429 0 delete $INC{$filename};
430 0 eval { require $filename };
431 }
432  
433 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
434 0 my $err = $@; chomp $err;
435 0 $cinv->responderr( "Died: $err" );
436 }
437 else {
438 0 $cinv->respond( "Reloaded $module from $filename" );
439 }
440  
441 0 return;
442 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
443  
444 sub commandable_parent
445 12 ▶{
Subroutine commandable_parent: called CC=1 SCAR=0.0
Pod undocumented
446 12 my $self = shift;
447 12 my ( $cinv ) = @_;
448  
449 12 return $sessions{$cinv->connection->identity};
450 }
451  
452 sub enumerate_items
453 0 ▶{
Subroutine enumerate_items: not called CC=1 SCAR=6.9
Pod undocumented
454 0 my $self = shift;
455 0 my $networks = $self->get_prop_networks;
456 0 return { map { $_->enumerable_name => $_ } values %$networks };
457 }
458  
459 sub enumerable_name
460 0 ▶{
Subroutine enumerable_name: not called CC=1 SCAR=6.9
Pod undocumented
461 0 return "";
462 }
463  
464 sub parent
465 8 ▶{
Subroutine parent: called CC=1 SCAR=0.0
Pod undocumented
466 8 return undef;
467 }
468  
469 sub command_delay
470 0 ▶ : Command_description("Run command after some delay")
Subroutine command_delay: not called CC=2 SCAR=17.9
Pod undocumented
471 : Command_arg('seconds')
472 : Command_arg('command', eatall => 1)
473 {
474 0 my $self = shift;
475 0 my ( $seconds, $text, $cinv ) = @_;
476  
477 # TODO: A CommandInvocant subclass that somehow prefixes its output so we
478 # know it's delayed output from earlier, so as not to confuse
479 0 my $subinv = $cinv->nest( $text );
480  
481 0 ▶ my $cmdname = $subinv->peek_token or
Branch: 1 branch
BranchTrueFalseTotal
my $cmdname = $subinv->peek_token or return $cinv->responderr("No command given") 0 0 0
482 return $cinv->responderr( "No command given" );
483  
484 0 my $loop = $self->{loop};
485  
486 my $id = $loop->enqueue_timer(
487 delay => $seconds,
488 0 ▶ code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
489 0 eval {
490 0 $subinv->invocant->do_command( $subinv );
491 };
492 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
493 0 my $err = $@; chomp $err;
494 0 $cinv->responderr( "Delayed command $cmdname failed - $err" );
495 }
496 },
497 0 );
498  
499 # TODO: Store ID, allow list, cancel, etc...
500  
501 0 return;
502 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
503  
504 ###
505 # Configuration management
506 ###
507  
508 sub command_config
509 0 ▶ : Command_description("Save configuration or change details about it")
Subroutine command_config: not called CC=1 SCAR=0.0
Pod undocumented
510 {
511 # The body doesn't matter as it never gets run
512 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
513  
514 sub command_config_show
515 0 ▶ : Command_description("Show the configuration that would be saved")
Subroutine command_config_show: not called CC=3 SCAR=24.8
Pod undocumented
516 : Command_subof('config')
517 : Command_default()
518 {
519 0 my $self = shift;
520 0 my ( $cinv ) = @_;
521  
522 # Since we're only showing config, only fetch it for the invocant
523 0 my $obj = $cinv->invocant;
524  
525 0 ▶ unless( $obj->can( "get_configuration" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->can("get_configuration")) 0 0 0
526 0 $cinv->respond( "No configuration" );
527 0 return;
528 }
529  
530 0 my $config = YAML::Dump( $obj->get_configuration );
531  
532 0 $cinv->respond( $_ ) for split m/\n/, $config;
533 0 return;
534 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
535  
536 sub command_config_save
537 0 ▶ : Command_description("Save configuration to disk")
Subroutine command_config_save: not called CC=1 SCAR=6.9
Pod undocumented
538 : Command_subof('config')
539 {
540 0 my $self = shift;
541 0 my ( $cinv ) = @_;
542  
543 0 my $file = CIRCLERC;
544 0 YAML::DumpFile( $file, $self->get_configuration );
545  
546 0 $cinv->respond( "Configuration written to $file" );
547 0 return;
548 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
549  
550 sub command_config_reload
551 0 ▶ : Command_description("Reload configuration from disk")
Subroutine command_config_reload: not called CC=1 SCAR=6.9
Pod undocumented
552 : Command_subof('config')
553 {
554 0 my $self = shift;
555 0 my ( $cinv ) = @_;
556  
557 0 my $file = CIRCLERC;
558 0 $self->load_configuration( YAML::LoadFile( $file ) );
559  
560 0 $cinv->respond( "Configuration loaded from $file" );
561 0 return;
562 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
563  
564 # For Configurable role
565 0 ▶after load_configuration => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
566 0 my $self = shift;
567 0 my ( $ynode ) = @_;
568  
569 0 ▶ if( my $sessions_ynode = $ynode->{sessions} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sessions_ynode = $ynode->{"sessions"}) 0 0 0
570 0 foreach my $sessionname ( keys %$sessions_ynode ) {
571 0 my $sessionnode = $sessions_ynode->{$sessionname};
572 0 my $type = $sessionnode->{type};
573  
574 0 my $session = $self->add_session( $sessionname, "Circle::Session::$type" );
575 0 $session->load_configuration( $sessionnode );
576 }
577 }
578 4 };
579  
580 0 ▶after store_configuration => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
581 0 my $self = shift;
582 0 my ( $ynode ) = @_;
583  
584 0 ▶ my $sessions_ynode = $ynode->{sessions} ||= YAML::Node->new({});
Condition0%0/3
$ynode->{"sessions"} ||= "YAML::Node"->new({})
l!l&&r!l&&!r
000
MC/DC0%0/2
$ynode->{"sessions"} ||= "YAML::Node"->new({})
$ynode->{"sessions"} "YAML::Node"->new({})
Truth table0%0/3
A ||= B
A= $ynode->{"sessions"}B= "YAML::Node"->new({})
ABresult
1X1
011
000
585 0 %$sessions_ynode = ();
586  
587 0 foreach my $identity ( keys %sessions ) {
588 0 my $session = $sessions{$identity};
589  
590 0 my $sessionnode = $session->get_configuration;
591 0 $sessions_ynode->{$identity} = $sessionnode;
592  
593 0 ▶ unless( $sessionnode->{type} ) { # exists doesn't quite play ball
Branch: 1 branch
BranchTrueFalseTotal
unless ($sessionnode->{"type"}) 0 0 0
594 # Ensure it's first
595 0 unshift @{ tied(%$sessionnode)->keys }, 'type'; # I am going to hell for this
596 0 ( $sessionnode->{type} ) = (ref $session) =~ m/^Circle::Session::(.*)$/;
597 }
598 }
599 4 };
600  
601 4 0x55AA;
« Circle/Net/IRC/User.pm ↑ Summary Circle/Widget/Entry.pm »