Declarative/Builder.pm

filter: Statementstmt 33.4% 88 / 263 Branchbran 10.1% 14 / 138 Conditioncond 7.6% 6 / 78 MC/DCmcdc 0.0% 0 / 50 Subroutinesub 37.5% 15 / 40 Podpod 0.0% 0 / 3 totaltotal 21.5% 123 / 572 CC 113 SCAR 48.1
CC
113
Cov
23%
_generate_state
501.0
_resolve_target
110.0
_add_state
72.0
CRAP 122.3
↑ Summary Declarative.pm »
1 package Class::StateMachine::Declarative::Builder;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Class::StateMachine;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 *debug = \$Class::StateMachine::debug;
11 1 *_debug = \&Class::StateMachine::Private::_debug;
12 1 our $debug;
13  
14 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
15 1 my ($class, $target_class) = @_;
16 1 my $top = Class::StateMachine::Declarative::Builder::State->_new;
17 1 my $self = { top => $top,
18 states => { '/' => $top },
19 class => $target_class };
20 1 bless $self, $class;
21 1 $self;
22 }
23  
24 0 ▶sub _bad_def {
Subroutine _bad_def: not called CC=1 SCAR=6.9
25 0 my ($self, $state, @msg) = @_;
26 0 croak "@msg on definition of state '$state->{name}' for class '$self->{class}'";
27 }
28  
29 0 ▶sub _is_hash { UNIVERSAL::isa($_[0], 'HASH') }
Subroutine _is_hash: not called CC=1 SCAR=6.9
30 0 ▶sub _is_array { UNIVERSAL::isa($_[0], 'ARRAY') }
Subroutine _is_array: not called CC=1 SCAR=6.9
31  
32 0 ▶sub _ensure_list {
Subroutine _ensure_list: not called CC=2 SCAR=17.9
33 0 my $ref = shift;
34 0 ▶ ( UNIVERSAL::isa($ref, 'ARRAY') ? @$ref : $ref );
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($ref, 'ARRAY') ? : 0 0 0
35 }
36  
37 1 ▶sub parse_state_declarations {
Subroutine parse_state_declarations: called CC=1 SCAR=0.0
Pod undocumented
38 1 my $self = shift;
39 1 $self->_parse_state_declarations($self->{top}, @_);
40 1 $self->_merge_any;
41 1 $self->_resolve_advances($self->{top});
42 1 $self->_resolve_transitions($self->{top}, []);
43 # $self->_propagate_transitions($self->{top});
44 }
45  
46 1 ▶sub _parse_state_declarations {
Subroutine _parse_state_declarations: called CC=4 SCAR=22.9
47 1 my $self = shift;
48 1 my $parent = shift;
49 1 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
50 0 ▶ my $name = shift // $self->_bad_def($parent, "undef is not valid as a state name");
Condition0%0/3
shift() // $self->_bad_def($parent, "undef is not valid as a state name")
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // $self->_bad_def($parent, "undef is not valid as a state name")
shift() $self->_bad_def($parent, "undef is not valid as a state name")
Truth table0%0/3
A // B
A= shift()B= $self->_bad_def($parent, "undef is not valid as a state name")
ABresult
1X1
011
000
51 0 my $decl = shift;
52 0 ▶ _is_hash($decl) or $self->_bad_def($parent, "HASH expected for substate '$name' declaration");
Branch: 1 branch
BranchTrueFalseTotal
_is_hash($decl) or $self->_bad_def($parent, "HASH expected for substate '${name}' declaration") 0 0 0
53 0 $self->_add_state($name, $parent, %$decl);
54 }
55 }
56  
57 0 ▶sub _add_state {
Subroutine _add_state: not called CC=8 SCAR=42.8
58 0 my ($self, $name, $parent, @decl) = @_;
59 0 my $secondary;
60 0 ▶ if ($name =~ /^\((.*)\)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\((.*)\)$/) 0 0 0
61 0 $name = $1;
62 0 $secondary = 1;
63 }
64 0 my $state = Class::StateMachine::Declarative::Builder::State->_new($name, $parent);
65 0 ▶ $self->_handle_attr_secondary($state, 1) if $secondary;
Branch: 1 branch
BranchTrueFalseTotal
if $secondary 0 0 0
66 0 ▶ while (@decl) {
Branch: 1 branch
BranchTrueFalseTotal
if (@decl) 0 0 0
67 0 my $k = shift @decl;
68 0 ▶ my $method = $self->can("_handle_attr_$k") or $self->_bad_def($state, "bad declaration '$k'");
Branch: 1 branch
BranchTrueFalseTotal
my $method = $self->can("_handle_attr_$k") or $self->_bad_def($state, "bad declaration '${k}'") 0 0 0
69 0 ▶ if (defined (my $v = shift @decl)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = shift @decl)) 0 0 0
70 0 ▶ $debug and $debug & 16 and _debug($self, "calling handler for attribute $k with value $v");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 16 and _debug($self, "calling handler for attribute $k with value $v") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 16
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 16
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 16
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 16
ABresult
0X0
100
111
71 0 $method->($self, $state, $v);
72 }
73 }
74 0 $self->{states}{$state->{full_name}} = $state;
75 0 $state;
76 }
77  
78 0 ▶sub _ensure_event_is_free {
Subroutine _ensure_event_is_free: not called CC=8 SCAR=42.8
79 0 my ($self, $state, $event, $current) = @_;
80 0 my $seen;
81 0 for (qw(transitions on)) {
82 0 ▶ $seen = $_ if defined $state->{$_}{$event};
Branch: 1 branch
BranchTrueFalseTotal
if defined $state->{$_}{$event} 0 0 0
83 }
84 0 for (qw(delay ignore)) {
85 0 ▶ $seen = $_ if grep $_ eq $event, @{$state->{$_}};
Branch: 1 branch
BranchTrueFalseTotal
if grep(($_ eq $event), @{$$state{$_};}) 0 0 0
86 }
87 0 ▶ if ($seen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen) 0 0 0
88 0 ▶ unless (defined $current) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $current) 0 0 0
89 0 $current = (caller 1)[3];
90 0 $current =~ s/^_handle_attr_//;
91 }
92 0 ▶ $seen and $self->_bad_def($state, "event '$event' appears on '$seen' and '$current' declarations");
Branch: 1 branch
BranchTrueFalseTotal
$seen and $self->_bad_def($state, "event '${event}' appears on '${seen}' and '${current}' declarations") 0 0 0
93 }
94 }
95  
96 0 ▶sub _handle_attr_enter {
Subroutine _handle_attr_enter: not called CC=1 SCAR=6.9
97 0 my ($self, $state, $v) = @_;
98 0 $state->{enter} = $v;
99 }
100  
101 0 ▶sub _handle_attr_leave {
Subroutine _handle_attr_leave: not called CC=1 SCAR=6.9
102 0 my ($self, $state, $v) = @_;
103 0 $state->{leave} = $v;
104 }
105  
106 0 ▶sub _handle_attr_jump {
Subroutine _handle_attr_jump: not called CC=1 SCAR=6.9
107 0 my ($self, $state, $v) = @_;
108 0 $state->{jump} = $v;
109 }
110  
111 0 ▶sub _handle_attr_advance {
Subroutine _handle_attr_advance: not called CC=1 SCAR=6.9
112 0 my ($self, $state, $v) = @_;
113 0 $state->{advance} = $v;
114 }
115  
116 0 ▶sub _handle_attr_delay {
Subroutine _handle_attr_delay: not called CC=2 SCAR=17.9
117 0 my ($self, $state, $v) = @_;
118 0 my @events = _ensure_list($v);
119 0 $self->_ensure_event_is_free($state, $_) for @events;
120 0 push @{$state->{delay}}, @events;
121 }
122  
123 0 ▶sub _handle_attr_ignore {
Subroutine _handle_attr_ignore: not called CC=2 SCAR=17.9
124 0 my ($self, $state, $v) = @_;
125 0 my @events = _ensure_list($v);
126 0 $self->_ensure_event_is_free($state, $_) for @events;
127 0 push @{$state->{ignore}}, @events;
128 }
129  
130 0 ▶sub _handle_attr_secondary {
Subroutine _handle_attr_secondary: not called CC=1 SCAR=6.9
131 0 my ($self, $state, $v) = @_;
132 0 $state->{secondary} = !!$v;
133 }
134  
135 0 ▶sub _handle_attr_before {
Subroutine _handle_attr_before: not called CC=4 SCAR=30.0
136 0 my ($self, $state, $v) = @_;
137 0 ▶ _is_hash($v) or $self->_bad_def($state, "HASH expected for 'before' declaration");
Branch: 1 branch
BranchTrueFalseTotal
_is_hash($v) or $self->_bad_def($state, "HASH expected for 'before' declaration") 0 0 0
138 0 ▶ while (my ($event, $action) = each %$v) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$v) 0 0 0
139 0 ▶ $state->{before}{$event} = $action if defined $action;
Branch: 1 branch
BranchTrueFalseTotal
if defined $action 0 0 0
140 }
141 }
142  
143 0 ▶sub _handle_attr_on {
Subroutine _handle_attr_on: not called CC=4 SCAR=30.0
144 0 my ($self, $state, $v) = @_;
145 0 ▶ _is_hash($v) or $self->_bad_def($state, "HASH expected for 'on' declaration");
Branch: 1 branch
BranchTrueFalseTotal
_is_hash($v) or $self->_bad_def($state, "HASH expected for 'on' declaration") 0 0 0
146 0 ▶ while (my ($event, $action) = each %$v) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$v) 0 0 0
147 0 ▶ if (defined $action) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $action) 0 0 0
148 0 $self->_ensure_event_is_free($state, $event);
149 0 $state->{on}{$event} = $action;
150 }
151 }
152 }
153  
154 0 ▶sub _handle_attr_transitions {
Subroutine _handle_attr_transitions: not called CC=4 SCAR=30.0
155 0 my ($self, $state, $v) = @_;
156 0 ▶ _is_hash($v) or $self->_bad_def($state, "HASH expected for 'transitions' declaration");
Branch: 1 branch
BranchTrueFalseTotal
_is_hash($v) or $self->_bad_def($state, "HASH expected for 'transitions' declaration") 0 0 0
157 0 ▶ while (my ($event, $target) = each %$v) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$v) 0 0 0
158 0 ▶ if (defined $target) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target) 0 0 0
159 0 $self->_ensure_event_is_free($state, $event);
160 0 $state->{transitions}{$event} = $target;
161 }
162 }
163 }
164  
165 0 ▶sub _handle_attr_substates {
Subroutine _handle_attr_substates: not called CC=3 SCAR=24.8
166 0 my ($self, $state, $v) = @_;
167 0 ▶ $state->{full_name} eq '/__any__' and $self->_bad_def($state, "pseudo state __any__ can not contain substates");
Branch: 1 branch
BranchTrueFalseTotal
$state->{"full_name"} eq "/__any__" and $self->_bad_def($state, "pseudo state __any__ can not contain substates") 0 0 0
168 0 ▶ _is_array($v) or $self->_bad_def($state, "ARRAY expected for substate declarations");
Branch: 1 branch
BranchTrueFalseTotal
_is_array($v) or $self->_bad_def($state, "ARRAY expected for substate declarations") 0 0 0
169 0 $self->_parse_state_declarations($state, @$v);
170 }
171  
172 1 ▶sub _merge_any {
Subroutine _merge_any: called CC=6 SCAR=28.1
173 1 my $self = shift;
174 1 my $top = $self->{top};
175 1 $top->{name} = '__any__';
176 1 ▶ if (defined(my $any = delete $self->{states}{'/__any__'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $any = delete $self->{"states"}{"/__any__"})) 0 1 1
177 0 my $ss = $self->{top}{substates};
178 0 @$ss = grep { $_->{name} ne '__any__' } @$ss;
179 0 delete $top->{$_} for qw(before transitions on);
180 0 ▶ $top->{$_} //= $any->{$_} for keys %$any;
Condition0%0/3
$top->{$_} //= $any->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$top->{$_} //= $any->{$_}
$top->{$_} $any->{$_}
Truth table0%0/3
A //= B
A= $top->{$_}B= $any->{$_}
ABresult
1X1
011
000
181 0 $top->{$_} = $any->{$_} for qw(ignore delay);
182 }
183 }
184  
185 1 ▶sub _resolve_advances {
Subroutine _resolve_advances: called CC=8 SCAR=37.3
186 1 my ($self, $state, $event) = @_;
187 1 my @ss = @{$state->{substates}};
188 1 ▶ if (@ss) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ss) 0 1 1
189 0 ▶ $event = $state->{advance} // $event;
Condition0%0/3
$state->{"advance"} // $event
l!l&&r!l&&!r
000
MC/DC0%0/2
$state->{"advance"} // $event
$state->{"advance"} $event
Truth table0%0/3
A // B
A= $state->{"advance"}B= $event
ABresult
1X1
011
000
190 0 $self->_resolve_advances($_, $event) for @ss;
191 0 ▶ if (defined $event) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $event) 0 0 0
192 0 ▶ while (@ss) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ss) 0 0 0
193 0 my $current_state = shift @ss;
194 0 ▶ if (my ($next_state) = grep { not $_->{secondary} } @ss) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($next_state) = grep({not $_->{"secondary"};} @ss)) 0 0 0
195 0 ▶ $current_state->{transitions}{$event} //= $next_state->{full_name};
Condition0%0/3
$current_state->{"transitions"}{$event} //= $next_state->{"full_name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$current_state->{"transitions"}{$event} //= $next_state->{"full_name"}
$current_state->{"transitions"}{$event} $next_state->{"full_name"}
Truth table0%0/3
A //= B
A= $current_state->{"transitions"}{$event}B= $next_state->{"full_name"}
ABresult
1X1
011
000
196 }
197 }
198 }
199 }
200 }
201  
202 1 ▶sub _resolve_transitions {
Subroutine _resolve_transitions: called CC=10 SCAR=33.3
203 1 my ($self, $state, $path) = @_;
204 1 my @path = (@$path, $state->{short_name});
205 1 my %transitions_abs;
206 my %transitions_rev;
207 1 ▶ while (my ($event, $target) = each %{$state->{transitions}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$state{"transitions"};}) 0 1 1
208 0 my $target_abs = $self->_resolve_target($target, \@path);
209 0 $transitions_abs{$event} = $target_abs;
210 0 ▶ push @{$transitions_rev{$target_abs} ||= []}, $event;
Condition0%0/2
$transitions_rev{$target_abs} ||= []
l!l
00
MC/DC0%0/1
$transitions_rev{$target_abs} ||= []
$transitions_rev{$target_abs}
Truth table0%0/2
A
A= $transitions_rev{$target_abs}
Aresult
11
00
211 }
212 1 $state->{transitions_abs} = \%transitions_abs;
213 1 $state->{transitions_rev} = \%transitions_rev;
214  
215 1 my $jump = $state->{jump};
216 1 my $ss = $state->{substates};
217 1 ▶ if (not defined $jump and not defined $state->{enter} and @$ss) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $jump || defined $state->{"enter"} and @$ss) 0 1 1
Condition33%2/6
not defined $jump || defined $state->{"enter"} and @$ss
!ll&&!rl&&r
010
defined $jump || defined $state->{'enter'}
l!l&&r!l&&!r
001
MC/DC0%0/3
not defined $jump || defined $state->{"enter"} and @$ss
defined $jump defined $state->{'enter'} @$ss
Truth table25%1/4
not(A || B) and C
A= defined $jumpB= defined $state->{'enter'}C= @$ss
ABCresult
1XX0
01X0
0000
0011
218 0 ▶ if (my ($main) = grep { not $_->{secondary} } @$ss) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($main) = grep({not $_->{'secondary'};} @$ss)) { } 0 0 0
219 0 ▶ $jump //= $main->{full_name};
Condition0%0/3
$jump //= $main->{"full_name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$jump //= $main->{"full_name"}
$jump $main->{"full_name"}
Truth table0%0/3
A //= B
A= $jumpB= $main->{"full_name"}
ABresult
1X1
011
000
220 }
221 else {
222 0 $self->_bad_def($state, "all the substates are secondary");
223 }
224 }
225  
226 1 ▶ $state->{jump_abs} = $self->_resolve_target($jump, \@path) if defined $jump;
Branch: 1 branch
BranchTrueFalseTotal
if defined $jump 0 1 1
227  
228 1 $self->_resolve_transitions($_, \@path) for @$ss;
229 }
230  
231 # sub _propagate_transitions {
232 # my ($self, $state) = @_;
233 # my $t = $state->{transitions_abs};
234 # for my $ss (@{$state->{substates}}) {
235 # my $ss_t = $ss->{transitions_abs};
236 # $ss_t->{$_} //= $t->{$_} for keys %$t;
237 # $self->_propagate_transitions($ss);
238 # }
239 # }
240  
241 0 ▶sub _resolve_target {
Subroutine _resolve_target: not called CC=10 SCAR=47.0
242 0 my ($self, $target, $path) = @_;
243 # $debug and $debug & 32 and _debug($self, "resolving target '$target' from '".join('/',@$path)."'");
244 0 ▶ if ($target =~ m|^__(\w+)__$|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target =~ /^__(\w+)__$/) 0 0 0
245 0 return $target;
246 }
247 0 ▶ if ($target =~ m|^/|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target =~ m[^/]) { } 0 0 0
248 0 ▶ return $target if $self->{states}{$target};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"states"}{$target} 0 0 0
249 0 ▶ $debug and $debug & 32 and _debug($self, "absolute target '$target' not found");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32 and _debug($self, "absolute target '${target}' not found") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 32
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 32
ABresult
0X0
100
111
250 }
251 else {
252 0 my @path = @$path;
253 0 ▶ while (@path) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path) 0 0 0
254 0 my $target_abs = join('/', @path, $target);
255 0 ▶ if ($self->{states}{$target_abs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"states"}{$target_abs}) 0 0 0
256 0 ▶ $debug and $debug & 32 and _debug($self, "target '$target' from '".join('/',@$path)."' resolved as '$target_abs'");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32 and _debug($self, "target '${target}' from '" . join("/", @$path) . "' resolved as '${target_abs}'") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 32
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 32
ABresult
0X0
100
111
257 0 return $target_abs;
258 }
259 0 pop @path;
260 }
261 }
262  
263 0 my $name = join('/', @$path);
264 0 $name =~ s|^/+||;
265 0 croak "unable to resolve transition target '$target' from state '$name'";
266 }
267  
268 1 ▶sub generate_class {
Subroutine generate_class: called CC=1 SCAR=0.0
Pod undocumented
269 1 my $self = shift;
270 1 $self->_generate_state($self->{top});
271 }
272  
273 1 ▶sub _generate_state {
Subroutine _generate_state: called CC=29 SCAR=62.2
274 1 my ($self, $state) = @_;
275 1 my $class = $self->{class};
276 1 my $name = $state->{name};
277 1 my $parent = $state->{parent};
278 1 ▶ my $parent_name = ($parent ? $parent->{name} : undef);
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 1 1
279 1 ▶ $debug and $debug & 16 and _debug("generating subs for class $class, state $name, parent: ". ($parent_name // '<undef>'));
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 16 and _debug("generating subs for class $class, state $name, parent: " . ($parent_name // "<undef>")) 0 1 1
Condition20%1/5
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 16
!ll&&!rl&&r
100
$parent_name // "<undef>"
l!l
00
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 16
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 16
MC/DC0%0/1
$parent_name // "<undef>"
$parent_name
Truth table33%1/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 16
ABresult
0X0
100
111
Truth table0%0/2
A
A= $parent_name
Aresult
11
00
280  
281 1 ▶ if ($parent and $parent_name ne '__any__') {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and $parent_name ne "__any__") 0 1 1
Condition33%1/3
$parent and $parent_name ne "__any__"
!ll&&!rl&&r
100
MC/DC0%0/2
$parent and $parent_name ne "__any__"
$parent $parent_name ne "__any__"
Truth table33%1/3
A and B
A= $parentB= $parent_name ne "__any__"
ABresult
0X0
100
111
282 0 Class::StateMachine::set_state_isa($class, $name, $parent_name);
283 }
284  
285 1 for my $when ('enter', 'leave') {
286 2 ▶ if (defined (my $action = $state->{$when})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $action = $state->{$when})) 0 2 2
287 Class::StateMachine::install_method($class,
288 "${when}_state",
289 0 ▶ sub { shift->$action },
Subroutine __ANON__: not called CC=1 SCAR=6.9
290 0 $name);
291 }
292 }
293  
294 1 ▶ if (!defined $state->{enter} and $name ne '__any__') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $state->{"enter"} and $name ne "__any__") 0 1 1
Condition33%1/3
not defined $state->{"enter"} and $name ne "__any__"
!ll&&!rl&&r
010
MC/DC0%0/2
not defined $state->{"enter"} and $name ne "__any__"
not defined $state->{"enter"} $name ne "__any__"
Truth table33%1/3
not(A) and B
A= not defined $state->{"enter"}B= $name ne "__any__"
ABresult
0X0
100
111
295 0 ▶ if (defined (my $jump = $state->{jump_abs})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $jump = $state->{"jump_abs"})) 0 0 0
296 0 my $name = $state->{name};
297 0 my $jump_name = $self->{states}{$jump}{name};
298 0 ▶ $debug and $debug & 32 and _debug(__PACKAGE__, "installing handler for jump(=> $jump_name) at $class/$name");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32 and _debug(__PACKAGE__, "installing handler for jump(=> $jump_name) at $class/$name") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 32
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 32
ABresult
0X0
100
111
299 Class::StateMachine::install_method($class,
300 'enter_state',
301 0 ▶ sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
302 0 my $self = shift;
303 0 ▶ if ($self->state eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->state eq $name) { } 0 0 0
304 0 ▶ $debug and $debug & 64 and _debug($self, "jumping to state $jump_name");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64 and _debug($self, "jumping to state $jump_name") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 64
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 64
ABresult
0X0
100
111
305 0 $self->state($jump_name)
306 }
307 else {
308 0 ▶ $debug and $debug & 64 and
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64 and _debug(64, "skipping jump to state $jump_name set for state $name") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 64
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 64
ABresult
0X0
100
111
309 _debug(64, "skipping jump to state $jump_name set for state $name");
310 }
311 },
312 0 $name);
313 }
314 }
315  
316 1 for my $event (keys %{$state->{before}}) {
317 0 my $action = $state->{before}{$event};
318 0 my $event1 = $event;
319 0 ▶ my $sub = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
320 0 my $self = shift;
321 0 ▶ if (my $method = $self->next::can) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $self->next::can) 0 0 0
322 0 ▶ $self->state_changed_on_call($method, $self) and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->state_changed_on_call($method, $self) and return 0 0 0
323 }
324 0 $self->$action;
325 0 };
326 0 ▶ $debug and $debug & 32 and _debug(__PACKAGE__, "installing handler for before($event1 => $action) at $class/$name");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32 and _debug(__PACKAGE__, "installing handler for before($event1 => $action) at $class/$name") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 32
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 32
ABresult
0X0
100
111
327 0 Class::StateMachine::install_method($class,
328 "$event/before",
329 $sub,
330 $name);
331 }
332  
333 1 for my $event (@{$state->{delay}}) {
334 0 my $event1 = $event;
335 0 ▶ $debug and $debug & 32 and _debug(__PACKAGE__, "installing handler for delay($event1) at $class/$name");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32 and _debug(__PACKAGE__, "installing handler for delay($event1) at $class/$name") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 32
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 32
ABresult
0X0
100
111
336 Class::StateMachine::install_method($class,
337 $event,
338 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
339 0 my $self = shift;
340 0 ▶ $debug and $debug & 64 and _debug($self, "event $event1 received (delay)");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64 and _debug($self, "event $event1 received (delay)") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 64
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 64
ABresult
0X0
100
111
341 0 $self->delay_until_next_state($event1) },
342 0 $name);
343 }
344  
345 1 for my $event (keys %{$state->{on}}) {
346 0 my $action = $state->{on}{$event};
347 0 my $before = "$event/before";
348 0 my $event1 = $event;
349 0 ▶ my $sub = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
350 0 my $self = shift;
351 0 ▶ $debug and $debug & 64 and _debug($self, "event $event1 received (on target: $action)");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64 and _debug($self, "event $event1 received (on target: $action)") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 64
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 64
ABresult
0X0
100
111
352 0 ▶ if (my $method = $self->can($before)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $self->can($before)) 0 0 0
353 0 ▶ $self->state_changed_on_call($method, $self, @_) and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->state_changed_on_call($method, $self, @_) and return 0 0 0
354 }
355 0 $self->$action(@_);
356 0 };
357 0 ▶ $debug and $debug & 32 and _debug(__PACKAGE__, "installing handler for on($event1 => $action) at $class/$name");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32 and _debug(__PACKAGE__, "installing handler for on($event1 => $action) at $class/$name") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 32
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 32
ABresult
0X0
100
111
358 0 Class::StateMachine::install_method($class, $event, $sub, $name);
359 }
360  
361 1 for my $event (@{$state->{ignore}}) {
362 0 my $before = "$event/before";
363 0 my $event1 = $event;
364 0 ▶ my $sub = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
365 0 my $self = shift;
366 0 ▶ $debug and $debug & 64 and _debug($self, "event $event1 received (ignore)");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64 and _debug($self, "event $event1 received (ignore)") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 64
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 64
ABresult
0X0
100
111
367 0 my $method = $self->can($before);
368 0 ▶ $self->$method(@_) if $method;
Branch: 1 branch
BranchTrueFalseTotal
if $method 0 0 0
369 0 };
370 0 Class::StateMachine::install_method($class, $event, $sub, $name);
371 }
372  
373 1 ▶ while (my ($target, $events) = each %{$state->{transitions_rev}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$state{"transitions_rev"};}) 0 1 1
374 0 my $target = $self->{states}{$target}{name};
375 0 for my $event (@$events) {
376 0 my $before = "$event/before";
377 0 my $event1 = $event;
378 0 ▶ my $sub = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
379 0 my $self = shift;
380 0 ▶ $debug and $debug & 64 and _debug($self, "event $event1 received (transition target: $target)");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64 and _debug($self, "event $event1 received (transition target: $target)") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 64
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 64
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 64
ABresult
0X0
100
111
381 0 ▶ if (my $method = $self->can($before)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $self->can($before)) 0 0 0
382 0 ▶ $self->state_changed_on_call($method, $self, @_) and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->state_changed_on_call($method, $self, @_) and return 0 0 0
383 }
384 0 $self->state($target);
385 0 };
386 0 ▶ $debug and $debug & 32 and _debug(__PACKAGE__, "installing handler for transition($event1 => $target) at $class/$name");
Branch: 1 branch
BranchTrueFalseTotal
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32 and _debug(__PACKAGE__, "installing handler for transition($event1 => $target) at $class/$name") 0 0 0
Condition0%0/3
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
!ll&&!rl&&r
000
MC/DC0%0/2
$Class::StateMachine::Declarative::Builder::debug and $Class::StateMachine::Declarative::Builder::debug & 32
$Class::StateMachine::Declarative::Builder::debug $Class::StateMachine::Declarative::Builder::debug & 32
Truth table0%0/3
A and B
A= $Class::StateMachine::Declarative::Builder::debugB= $Class::StateMachine::Declarative::Builder::debug & 32
ABresult
0X0
100
111
387 0 Class::StateMachine::install_method($class, $event, $sub, $name);
388 }
389 }
390  
391 1 $self->_generate_state($_) for @{$state->{substates}};
392 }
393  
394 package Class::StateMachine::Declarative::Builder::State;
395  
396 1 ▶sub _new {
Subroutine _new: called CC=4 SCAR=14.4
397 1 my ($class, $name, $parent) = @_;
398 1 ▶ $name //= '';
Condition50%1/2
$name //= ""
l!l
01
MC/DC0%0/1
$name //= ""
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
399 1 ▶ my $full_name = ($parent ? "$parent->{full_name}/$name" : $name);
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 1 1
400 1 my $final_name = $full_name;
401 1 $final_name =~ s|^/+||;
402 1 my $state = { short_name => $name,
403 full_name => $full_name,
404 name => $final_name,
405 parent => $parent,
406 substates => [],
407 transitions => {},
408 before => {},
409 on => {},
410 ignore => [],
411 delay => [] };
412 1 bless $state, $class;
413 0 ▶ push @{$parent->{substates}}, $state if $parent;
Branch: 1 branch
BranchTrueFalseTotal
if $parent 0 1 1
414 1 Scalar::Util::weaken($state->{parent});
415 1 $state;
416 }
417  
418 1 1;
↑ Summary Declarative.pm »