X10/MacroProc.pm

filter: Statementstmt 19.2% 10 / 52 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 27.2% 3 / 11 Podpod 0.0% 0 / 6 totaltotal 12.1% 13 / 107 CC 16 SCAR 33.6
CC
16
Cov
12%
new
56.0
handle_event
42.0
setup
20.0
CRAP 28.7
« X10/ActiveHome.pm ↑ Summary X10/Scheduler.pm »
1  
2 # Copyright (c) 1999-2017 Rob Fugina <robf@fugina.com>
3 # Distributed under the terms of the GNU Public License, Version 3.0
4  
5 package X10::MacroProc;
6  
7 # this package implements a macro processor using an event callback mechanism
8  
9 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use X10::Event;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub new
16 0 ▶{
Subroutine new: not called CC=7 SCAR=40.3
Pod undocumented
17 0 my $type = shift;
18  
19 0 my $self = bless { @_ }, $type;
20  
21 0 ▶ return undef unless $self->{controller};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"controller"} 0 0 0
22  
23 0 ▶ $self->{logger} ||= sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 shift;
25 0 printf(@_);
26 0 print "\n";
27 0 ▶ };
Condition0%0/3
$self->{"logger"} ||= sub { shift(); printf @_; print "\n"; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"logger"} ||= sub { shift(); printf @_; print "\n"; }
$self->{"logger"} sub { shift(); printf @_; print "\n"; }
Truth table0%0/3
A ||= B
A= $self->{"logger"}B= sub { shift(); printf @_; print "\n"; }
ABresult
1X1
011
000
28  
29 0 ▶ $self->{verbose} = 1 if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
30  
31 0 $self->{controller}->register_listener($self->event_callback);
32 0 $self->{macros} = {};
33  
34 0 ▶ if ($self->{configfile})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"configfile"}) 0 0 0
35 {
36 0 ▶ my $config = eval { require $self->{configfile} } || die $@;
Condition0%0/2
eval { do { require $self->{'configfile'} } } || die($@)
l!l
00
MC/DC0%0/1
eval { do { require $self->{'configfile'} } } || die($@)
eval { do { require $self->{'configfile'} } }
Truth table0%0/2
A
A= eval { do { require $self->{'configfile'} } }
Aresult
11
00
37  
38 0 foreach (keys %$config)
39 {
40 0 $self->add( $_ => $config->{$_} );
41 }
42 }
43  
44 0 return $self;
45 }
46  
47 ###
48  
49 sub add
50 0 ▶{
Subroutine add: not called CC=2 SCAR=17.9
Pod undocumented
51 0 my $self = shift;
52 0 my ($key, $macro) = @_;
53  
54 0 my $nkey = X10::Event->new($key)->as_string;
55  
56 $self->{logger}->('info', "Replacing old macro for %s", $nkey)
57 0 ▶ if exists $self->{macros}->{$nkey};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"macros"}{$nkey} 0 0 0
58  
59 0 $self->{macros}->{$nkey} = $macro;
60 0 $self->{macros}->{$nkey}->controller($self->{controller});
61 }
62  
63 sub setup
64 0 ▶{
Subroutine setup: not called CC=4 SCAR=30.0
Pod undocumented
65 0 my $self = shift;
66  
67 0 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
68 {
69 0 ▶ while (my $key = shift)
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = shift()) 0 0 0
70 {
71 0 my $nkey = X10::Event->new($key)->as_string;
72  
73 0 ▶ if ($nkey)
Branch: 1 branch
BranchTrueFalseTotal
if ($nkey) { } 0 0 0
74 {
75 0 $self->{macros}->{$nkey} = shift;
76 0 $self->{macros}->{$nkey}->controller($self->{controller});
77 }
78 else
79 {
80 0 $self->{logger}->('info', "Throwing away macro for ", $key);
81 0 shift;
82 }
83 }
84  
85 }
86  
87 0 return $self->{macros};
88 }
89  
90 sub event_callback
91 0 ▶{
Subroutine event_callback: not called CC=1 SCAR=6.9
Pod undocumented
92 0 my $self = shift;
93 0 ▶ return sub { $self->handle_event(shift) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 }
95  
96 sub handle_event
97 0 ▶{
Subroutine handle_event: not called CC=6 SCAR=37.4
Pod undocumented
98 0 my $self = shift;
99 0 my $event = shift;
100  
101 0 ▶ if (exists $self->{macros}->{$event->as_string})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'macros'}{$event->as_string}) { } 0 0 0
elsif ($self->{'debug'}) { } 0 0 0
102 {
103 $self->{logger}->('info', "Macro: %s",
104 0 ▶ $self->{macros}->{$event->as_string}->description || $event->as_string
Condition0%0/3
$self->{'macros'}{$event->as_string}->description || $event->as_string
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'macros'}{$event->as_string}->description || $event->as_string
$self->{'macros'}{$event->as_string}->description $event->as_string
Truth table0%0/3
A || B
A= $self->{'macros'}{$event->as_string}->descriptionB= $event->as_string
ABresult
1X1
011
000
105 );
106  
107 $self->{macros}->{$event->as_string}->run
108 || $self->{logger}->('info', "Problem running macro: %s",
109 0 ▶ $self->{macros}->{$event->as_string}->description
Branch: 1 branch
BranchTrueFalseTotal
$self->{"macros"}{$event->as_string}->run or $self->{"logger"}->("info", "Problem running macro: %s", $self->{"macros"}{$event->as_string}->description || $event->as_string) 0 0 0
Condition0%0/3
$self->{'macros'}{$event->as_string}->description || $event->as_string
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'macros'}{$event->as_string}->description || $event->as_string
$self->{'macros'}{$event->as_string}->description $event->as_string
Truth table0%0/3
A || B
A= $self->{'macros'}{$event->as_string}->descriptionB= $event->as_string
ABresult
1X1
011
000
110 || $event->as_string);
111 }
112 elsif ($self->{debug})
113 {
114 0 $self->{logger}->('info', "No macro for %s", $event->as_string);
115 }
116  
117 }
118  
119 sub select_fds
120 0 ▶{
Subroutine select_fds: not called CC=1 SCAR=6.9
Pod undocumented
121 0 return ();
122 }
123  
124  
125 1 1;
126  
« X10/ActiveHome.pm ↑ Summary X10/Scheduler.pm »