blib/lib/Circle/RootObj.pm

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