X10/Event.pm

filter: Statementstmt 20.7% 11 / 53 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 30.0% 3 / 10 Podpod 0.0% 0 / 7 totaltotal 9.0% 14 / 155 CC 26 SCAR 45.0
CC
26
Cov
10%
compile
182.0
parse_string
72.0
new
30.0
CRAP 89.6
« X10/Server.pm ↑ Summary X10/SchedEvent.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::Event;
6  
7 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 @ISA = qw(Storable);
12  
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub new
16 0 ▶{
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
17 0 my $type = shift;
18  
19 0 my $self;
20  
21 0 ▶ if (@_ == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
22 {
23 0 my ($hc, $uc, $func) = &parse_string(shift);
24  
25 0 ▶ return undef unless ($hc && $uc && $func);
Branch: 1 branch
BranchTrueFalseTotal
unless $hc and $uc and $func 0 0 0
Condition0%0/6
$hc and $uc and $func
!ll&&!rl&&r
000
$hc and $uc
!ll&&!rl&&r
000
MC/DC0%0/3
$hc and $uc and $func
$hc $uc $func
Truth table0%0/4
A and B and C
A= $hcB= $ucC= $func
ABCresult
0XX0
10X0
1100
1111
26  
27 0 $self = {
28 house_code => $hc,
29 unit_code => $uc,
30 func => $func,
31 }
32 }
33  
34 0 bless $self, $type;
35  
36 0 return $self;
37 }
38  
39 sub house_code
40 0 ▶{
Subroutine house_code: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my $self = shift;
42 0 return $self->{house_code};
43 }
44  
45 sub unit_code
46 0 ▶{
Subroutine unit_code: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my $self = shift;
48 0 return $self->{unit_code};
49 }
50  
51 sub func
52 0 ▶{
Subroutine func: not called CC=1 SCAR=6.9
Pod undocumented
53 0 my $self = shift;
54 0 return $self->{func};
55 }
56  
57 sub as_string
58 0 ▶{
Subroutine as_string: not called CC=3 SCAR=24.8
Pod undocumented
59 0 my $self = shift;
60  
61 0 ▶ if ($self->unit_code eq 'ALL' || $self->unit_code eq 'LIGHTS')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->unit_code eq 'ALL' or $self->unit_code eq 'LIGHTS') { } 0 0 0
Condition0%0/3
$self->unit_code eq "ALL" or $self->unit_code eq "LIGHTS"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->unit_code eq "ALL" or $self->unit_code eq "LIGHTS"
$self->unit_code eq "ALL" $self->unit_code eq "LIGHTS"
Truth table0%0/3
A or B
A= $self->unit_code eq "ALL"B= $self->unit_code eq "LIGHTS"
ABresult
1X1
011
000
62 {
63 0 return join(' ', $self->house_code, $self->unit_code, $self->func);
64 }
65 else
66 {
67 0 return sprintf("%s%02s %s", $self->house_code, $self->unit_code, $self->func);
68 }
69 }
70  
71 ###
72  
73 # build a string of words that implement this event
74 sub compile
75 0 ▶{
Subroutine compile: not called CC=13 SCAR=52.0
Pod undocumented
76 0 my $self = shift;
77  
78 0 my @words = ();
79  
80 0 ▶ if ($self->func eq 'ON' || $self->func eq 'OFF')
Branch: 2 branches
BranchTrueFalseTotal
if ($self->func eq 'ON' or $self->func eq 'OFF') { } 0 0 0
elsif ($self->func eq 'DIM' or $self->func eq 'BRIGHT') { } 0 0 0
Condition0%0/3
$self->func eq "ON" or $self->func eq "OFF"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->func eq "ON" or $self->func eq "OFF"
$self->func eq "ON" $self->func eq "OFF"
Truth table0%0/3
A or B
A= $self->func eq "ON"B= $self->func eq "OFF"
ABresult
1X1
011
000
81 {
82 0 ▶ if ($self->unit_code eq 'LIGHTS' && $self->func eq 'ON')
Branch: 3 branches
BranchTrueFalseTotal
if ($self->unit_code eq 'LIGHTS' and $self->func eq 'ON') { } 0 0 0
elsif ($self->unit_code eq 'ALL' and $self->func eq 'OFF') { } 0 0 0
elsif ($self->unit_code > 0 and $self->unit_code <= 16) { } 0 0 0
Condition0%0/3
$self->unit_code eq "LIGHTS" and $self->func eq "ON"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->unit_code eq "LIGHTS" and $self->func eq "ON"
$self->unit_code eq "LIGHTS" $self->func eq "ON"
Truth table0%0/3
A and B
A= $self->unit_code eq "LIGHTS"B= $self->func eq "ON"
ABresult
0X0
100
111
83 {
84 0 push @words, sprintf("%sL1", $self->house_code);
85 }
86 ▶ elsif ($self->unit_code eq 'ALL' && $self->func eq 'OFF')
Condition0%0/3
$self->unit_code eq "ALL" and $self->func eq "OFF"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->unit_code eq "ALL" and $self->func eq "OFF"
$self->unit_code eq "ALL" $self->func eq "OFF"
Truth table0%0/3
A and B
A= $self->unit_code eq "ALL"B= $self->func eq "OFF"
ABresult
0X0
100
111
87 {
88 0 push @words, sprintf("%sA0", $self->house_code);
89 }
90 ▶ elsif ($self->unit_code > 0 && $self->unit_code <= 16)
Condition0%0/3
$self->unit_code > 0 and $self->unit_code <= 16
!ll&&!rl&&r
000
MC/DC0%0/2
$self->unit_code > 0 and $self->unit_code <= 16
$self->unit_code > 0 $self->unit_code <= 16
Truth table0%0/3
A and B
A= $self->unit_code > 0B= $self->unit_code <= 16
ABresult
0X0
100
111
91 {
92 0 push @words,
93 sprintf("%s%02s", $self->house_code, $self->unit_code),
94 sprintf("%s%2s", $self->house_code, substr($self->func, 0, 2));
95 }
96 else
97 {
98 0 warn sprintf "Unknown command: %s %s %s (%s)",
99 $self->house_code, $self->unit_code, $self->func, $_;
100 }
101 }
102 ▶ elsif ($self->func eq 'DIM' || $self->func eq 'BRIGHT')
Condition0%0/3
$self->func eq "DIM" or $self->func eq "BRIGHT"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->func eq "DIM" or $self->func eq "BRIGHT"
$self->func eq "DIM" $self->func eq "BRIGHT"
Truth table0%0/3
A or B
A= $self->func eq "DIM"B= $self->func eq "BRIGHT"
ABresult
1X1
011
000
103 {
104 0 ▶ if ($self->unit_code > 0 && $self->unit_code <= 16)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->unit_code > 0 and $self->unit_code <= 16) { } 0 0 0
Condition0%0/3
$self->unit_code > 0 and $self->unit_code <= 16
!ll&&!rl&&r
000
MC/DC0%0/2
$self->unit_code > 0 and $self->unit_code <= 16
$self->unit_code > 0 $self->unit_code <= 16
Truth table0%0/3
A and B
A= $self->unit_code > 0B= $self->unit_code <= 16
ABresult
0X0
100
111
105 {
106 0 push @words,
107 sprintf("%s%02s", $self->house_code, $self->unit_code),
108 sprintf("%s%2s", $self->house_code, substr($self->func, 0, 2));
109 }
110 else
111 {
112 0 warn sprintf "Unknown command: %s %s %s (%s)",
113 $self->house_code, $self->unit_code, $self->func, $_;
114 }
115 }
116 else
117 {
118 0 warn sprintf "Unknown command: %s %s %s (%s)",
119 $self->house_code, $self->unit_code, $self->func, $_;
120 }
121  
122 0 return map {uc} @words;
123 }
124  
125  
126 ###
127  
128 sub parse_string
129 0 ▶{
Subroutine parse_string: not called CC=8 SCAR=42.8
Pod undocumented
130 0 my $string = uc(shift);
131  
132 0 ▶ if ( $string =~ /^\s*([a-p])\s*(\d+|all|lights)\s*(on|off|dim|bright)\s*$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^\s*([a-p])\s*(\d+|all|lights)\s*(on|off|dim|bright)\s*$/i) { } 0 0 0
133 {
134 0 ▶ if ( lc($2) eq 'all' && lc($3) eq 'off' )
Branch: 3 branches
BranchTrueFalseTotal
if (lc $2 eq 'all' and lc $3 eq 'off') { } 0 0 0
elsif (lc $2 eq 'lights' and lc $3 eq 'on') { } 0 0 0
elsif ($2 > 0 and $2 <= 16) { } 0 0 0
Condition0%0/3
lc $2 eq "all" and lc $3 eq "off"
!ll&&!rl&&r
000
MC/DC0%0/2
lc $2 eq "all" and lc $3 eq "off"
lc $2 eq "all" lc $3 eq "off"
Truth table0%0/3
A and B
A= lc $2 eq "all"B= lc $3 eq "off"
ABresult
0X0
100
111
135 {
136 0 return map {uc} ($1, $2, $3);
137 }
138 ▶ elsif ( lc($2) eq 'lights' && lc($3) eq 'on' )
Condition0%0/3
lc $2 eq "lights" and lc $3 eq "on"
!ll&&!rl&&r
000
MC/DC0%0/2
lc $2 eq "lights" and lc $3 eq "on"
lc $2 eq "lights" lc $3 eq "on"
Truth table0%0/3
A and B
A= lc $2 eq "lights"B= lc $3 eq "on"
ABresult
0X0
100
111
139 {
140 0 return map {uc} ($1, $2, $3);
141 }
142 ▶ elsif ( $2 > 0 && $2 <= 16 )
Condition0%0/3
$2 > 0 and $2 <= 16
!ll&&!rl&&r
000
MC/DC0%0/2
$2 > 0 and $2 <= 16
$2 > 0 $2 <= 16
Truth table0%0/3
A and B
A= $2 > 0B= $2 <= 16
ABresult
0X0
100
111
143 {
144 0 return (uc($1), $2 * 1, uc($3));
145 }
146 else
147 {
148 0 return ();
149 }
150 }
151 else
152 {
153 0 return ();
154 }
155 }
156  
157  
158 1 1;
159  
« X10/Server.pm ↑ Summary X10/SchedEvent.pm »