WallyHome/Role/Creator.pm

filter: Statementstmt 98.4% 64 / 65 Branchbran 66.6% 8 / 12 Conditioncond 40.7% 11 / 27 MC/DCmcdc 5.8% 1 / 17 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 69.4% 91 / 131 CC 23 SCAR 24.5
CC
23
Cov
80%
instantiateObject
19.3
loadSensorFromApiResponseData
8.1
loadPlaceFromApiResponseData
4.0
CRAP 11.6
↑ Summary WallyHome/Role/REST.pm »
1 package Device::WallyHome::Role::Creator;
2 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use MooseX::AttributeShortcuts;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Module::Loader;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.21.3';
9  
10  
11 #== ATTRIBUTES =================================================================
12  
13 2 has 'callbackObject' => (
14 is => 'ro',
15 weak_ref => 1,
16 writer => '_callbackObject',
17 );
18  
19  
20 #== PUBLIC METHODS =============================================================
21  
22 10 ▶sub instantiateObject {
Subroutine instantiateObject: called CC=13 SCAR=29.6
Pod undocumented
23 10 my ($self, $class, $params) = @_;
24  
25 10 ▶ $params //= {};
Condition50%1/2
$params //= {}
l!l
100
MC/DC0%0/1
$params //= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
26  
27 10 my $restApiRole = 'Device::WallyHome::Role::REST';
28  
29 # Dynamically load class module
30 eval {
31 10 (my $file = $class) =~ s/::/\//g;
32  
33 10 require $file . '.pm';
34  
35 10 $class->import();
36  
37 10 1;
38 10 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { (my $file = $class) =~ s[::][/]g; require $file . '.pm'; $class->import; 1 } } or do { die "Failed to dynamically load class module ($class): " . $@ } 10 0 10
39 0 die "Failed to dynamically load class module ($class): " . $@;
40 };
41  
42 # Pass along REST API information
43 10 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->does($restApiRole) and $class->does($restApiRole)) 2 8 10
Condition66%2/3
$self->does($restApiRole) and $class->does($restApiRole)
!ll&&!rl&&r
082
MC/DC50%1/2
$self->does($restApiRole) and $class->does($restApiRole)
$self->does($restApiRole) $class->does($restApiRole)
Truth table66%2/3
A and B
A= $self->does($restApiRole)B= $class->does($restApiRole)
ABresult
0X0
100
111
44 $self->does($restApiRole)
45 && $class->does($restApiRole)
46 ) {
47 2 ▶ $params->{apiHostname} //= $self->apiHostname();
Condition33%1/3
$params->{"apiHostname"} //= $self->apiHostname
l!l&&r!l&&!r
020
MC/DC0%0/2
$params->{"apiHostname"} //= $self->apiHostname
$params->{"apiHostname"} $self->apiHostname
Truth table33%1/3
A //= B
A= $params->{"apiHostname"}B= $self->apiHostname
ABresult
1X1
011
000
48 2 ▶ $params->{apiUseHttps} //= $self->apiUseHttps();
Condition33%1/3
$params->{"apiUseHttps"} //= $self->apiUseHttps
l!l&&r!l&&!r
020
MC/DC0%0/2
$params->{"apiUseHttps"} //= $self->apiUseHttps
$params->{"apiUseHttps"} $self->apiUseHttps
Truth table33%1/3
A //= B
A= $params->{"apiUseHttps"}B= $self->apiUseHttps
ABresult
1X1
011
000
49 2 ▶ $params->{apiVersion} //= $self->apiVersion();
Condition33%1/3
$params->{"apiVersion"} //= $self->apiVersion
l!l&&r!l&&!r
020
MC/DC0%0/2
$params->{"apiVersion"} //= $self->apiVersion
$params->{"apiVersion"} $self->apiVersion
Truth table33%1/3
A //= B
A= $params->{"apiVersion"}B= $self->apiVersion
ABresult
1X1
011
000
50 2 ▶ $params->{lastApiError} //= $self->lastApiError();
Condition33%1/3
$params->{"lastApiError"} //= $self->lastApiError
l!l&&r!l&&!r
002
MC/DC0%0/2
$params->{"lastApiError"} //= $self->lastApiError
$params->{"lastApiError"} $self->lastApiError
Truth table33%1/3
A //= B
A= $params->{"lastApiError"}B= $self->lastApiError
ABresult
1X1
011
000
51 2 ▶ $params->{token} //= $self->token();
Condition33%1/3
$params->{"token"} //= $self->token
l!l&&r!l&&!r
020
MC/DC0%0/2
$params->{"token"} //= $self->token
$params->{"token"} $self->token
Truth table33%1/3
A //= B
A= $params->{"token"}B= $self->token
ABresult
1X1
011
000
52 2 ▶ $params->{timeout} //= $self->timeout();
Condition33%1/3
$params->{"timeout"} //= $self->timeout
l!l&&r!l&&!r
020
MC/DC0%0/2
$params->{"timeout"} //= $self->timeout
$params->{"timeout"} $self->timeout
Truth table33%1/3
A //= B
A= $params->{"timeout"}B= $self->timeout
ABresult
1X1
011
000
53 }
54  
55 10 ▶ if ($self->_testModeIdentifier()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_testModeIdentifier) 10 0 10
56 10 $params->{_testModeIdentifier} = $self->_testModeIdentifier();
57 }
58  
59 # Use ourself as the callback object
60 10 $params->{callbackObject} = $self;
61  
62 10 Module::Loader->new()->load($class);
63  
64 10 my $obj = $class->new(%$params);
65  
66 10 ▶ die "Failed to instantiate object ($class): " . Dumper($params) unless defined $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 0 10 10
67  
68 10 return $obj;
69 }
70  
71 1 ▶sub loadPlaceFromApiResponseData {
Subroutine loadPlaceFromApiResponseData: called CC=4 SCAR=13.9
Pod undocumented
72 1 my ($self, $placeData) = @_;
73  
74 1 my $initData = {};
75  
76 # Non-Boolean Attributes
77 1 foreach my $attribute (qw{
78 id
79 accountId
80 label
81 fullAddress
82 address
83 sensorIds
84 nestAdjustments
85 rapidResponseSupport
86 }) {
87 8 $initData->{$attribute} = $placeData->{$attribute};
88 }
89  
90 # Boolean Attributes
91 1 foreach my $attribute (qw{
92 suspended
93 buzzerEnabled
94 nestEnabled
95 }) {
96 3 ▶ $initData->{$attribute} = $placeData->{$attribute} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$placeData->{$attribute} ? : 2 1 3
97 }
98  
99 1 return $self->instantiateObject('Device::WallyHome::Place', $initData);
100 }
101  
102 1 ▶sub loadSensorFromApiResponseData {
Subroutine loadSensorFromApiResponseData: called CC=8 SCAR=20.9
Pod undocumented
103 1 my ($self, $sensorData) = @_;
104  
105 1 my $initData = {};
106  
107 # Non-Boolean Attributes
108 1 foreach my $attribute (qw{
109 snid
110 paired
111 updated
112 signalStrength
113 recentSignalStrength
114 hardwareType
115 activities
116 }) {
117 7 $initData->{$attribute} = $sensorData->{$attribute};
118 }
119  
120 # Boolean Attributes
121 1 foreach my $attribute (qw{
122 offline
123 suspended
124 alarmed
125 }) {
126 3 ▶ $initData->{$attribute} = $sensorData->{$attribute} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sensorData->{$attribute} ? : 0 3 3
127 }
128  
129 1 $initData->{location} = $self->instantiateObject('Device::WallyHome::Sensor::Location', $sensorData->{location});
130  
131 1 $initData->{thresholdsByName} = {};
132  
133 1 ▶ foreach my $thresholdDataKey (keys %{ $sensorData->{thresholds} // {} }) {
Condition50%1/2
$sensorData->{"thresholds"} // {}
l!l
10
MC/DC0%0/1
$sensorData->{"thresholds"} // {}
$sensorData->{"thresholds"}
Truth table50%1/2
A
A= $sensorData->{"thresholds"}
Aresult
11
00
134 2 my $thresholdHref = $sensorData->{thresholds}->{$thresholdDataKey};
135  
136 my $thresholdData = {
137 max => $thresholdHref->{max},
138 min => $thresholdHref->{min},
139 2 name => $thresholdDataKey,
140 };
141  
142 2 $initData->{thresholdsByName}->{$thresholdDataKey} = $self->instantiateObject('Device::WallyHome::Sensor::Threshold', $thresholdData);
143 }
144  
145 1 $initData->{statesByName} = {};
146  
147 1 ▶ foreach my $stateDataKey (keys %{ $sensorData->{state} // {} }) {
Condition50%1/2
$sensorData->{"state"} // {}
l!l
10
MC/DC0%0/1
$sensorData->{"state"} // {}
$sensorData->{"state"}
Truth table50%1/2
A
A= $sensorData->{"state"}
Aresult
11
00
148 5 my $stateHref = $sensorData->{state}->{$stateDataKey};
149  
150 my $stateData = {
151 at => $stateHref->{at},
152 name => $stateDataKey,
153 value => $stateHref->{value},
154 5 };
155  
156 5 $initData->{statesByName}->{$stateDataKey} = $self->instantiateObject('Device::WallyHome::Sensor::State', $stateData);
157 }
158  
159 1 my $sensor = $self->instantiateObject('Device::WallyHome::Sensor', $initData);
160 }
161  
162 2 1;
↑ Summary WallyHome/Role/REST.pm »