TPath/Attributes/Standard.pm

filter: Statementstmt 41.9% 101 / 241 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 53.2% 33 / 62 Podpod 0.0% 0 / 28 totaltotal 33.4% 134 / 401 CC 46 SCAR 24.0
CC
46
Cov
33%
standard_index
42.0
standard_uid
30.0
standard_pick
20.0
CRAP 11.0
« TPath/Test/One.pm ↑ Summary TPath/TypeCheck.pm »
1 package TPath::Attributes::Standard;
2 1 $TPath::Attributes::Standard::VERSION = '1.007';
3 # ABSTRACT: the standard collection of attributes available to any forester by default
4  
5  
6 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶no if $] >= 5.018, warnings => "experimental";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MooseX::MethodAttributes::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 1 requires qw(_kids children parent);
15  
16  
17 0 ▶sub standard_true : Attr(true) {
Subroutine standard_true: not called CC=1 SCAR=6.9
Pod undocumented
18 0 return 1;
19 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 0 ▶sub standard_false : Attr(false) {
Subroutine standard_false: not called CC=1 SCAR=6.9
Pod undocumented
23 0 return undef;
24 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27 0 ▶sub standard_this : Attr(this) {
Subroutine standard_this: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my ( undef, $ctx ) = @_;
29 0 return $ctx->n;
30 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32  
33 0 ▶sub standard_uid : Attr(uid) {
Subroutine standard_uid: not called CC=5 SCAR=34.0
Pod undocumented
34 0 my ( $self, $ctx ) = @_;
35 0 my $original = $ctx;
36 0 my @list;
37 0 my ( $node, $i ) = ( $ctx->n, $ctx->i );
38 0 ▶ while ( !$i->is_root($node) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($i->is_root($node)) 0 0 0
39 0 my $ra = refaddr $node;
40 0 $ctx = $ctx->wrap($node);
41 0 my $parent = $self->parent( $original, $ctx );
42 0 ▶ last unless $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
43 0 my @children = $self->children( $parent->n, $i );
44 0 for my $index ( 0 .. $#children ) {
45 0 ▶ if ( refaddr $children[$index] == $ra ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($children[$index]) == $ra) 0 0 0
46 0 push @list, $index;
47 0 last;
48 }
49 }
50 0 $node = $parent->n;
51 }
52 0 return '/' . join( '/', @list );
53 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55  
56 0 ▶sub standard_echo : Attr(echo) {
Subroutine standard_echo: not called CC=1 SCAR=6.9
Pod undocumented
57 0 my ( undef, undef, $o ) = @_;
58 0 return $o;
59 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61  
62 0 ▶sub standard_is_leaf : Attr(leaf) {
Subroutine standard_is_leaf: not called CC=2 SCAR=17.9
Pod undocumented
63 0 my ( $self, $ctx ) = @_;
64 0 ▶ return $self->is_leaf($ctx) ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_leaf($ctx) ? : 0 0 0
65 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67  
68 0 ▶sub standard_pick : Attr(pick) {
Subroutine standard_pick: not called CC=4 SCAR=30.0
Pod undocumented
69 0 my ( $self, undef, $collection, $index ) = @_;
70 0 ▶ if ( defined $index && $self->one_based ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index and $self->one_based) 0 0 0
Condition0%0/3
defined $index and $self->one_based
!ll&&!rl&&r
000
MC/DC0%0/2
defined $index and $self->one_based
defined $index $self->one_based
Truth table0%0/3
A and B
A= defined $indexB= $self->one_based
ABresult
0X0
100
111
71 0 $index--;
72 }
73 0 ▶ return $collection->[ $index // 0 ];
Condition0%0/2
$index // 0
l!l
00
MC/DC0%0/1
$index // 0
$index
Truth table0%0/2
A
A= $index
Aresult
11
00
74 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76  
77 0 ▶sub standard_size : Attr(size) {
Subroutine standard_size: not called CC=1 SCAR=6.9
Pod undocumented
78 0 my ( undef, undef, $collection ) = @_;
79 0 return scalar @$collection;
80 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82  
83 0 ▶sub standard_tsize : Attr(tsize) {
Subroutine standard_tsize: not called CC=4 SCAR=30.0
Pod undocumented
84 0 my ( $self, $n, $i ) = @_;
85 0 my $size = 1;
86 0 ▶ ( $n, $i ) = ( $n->n, $n->i ) if blessed $n && $n->isa('TPath::Context');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($n) and $n->isa("TPath::Context") 0 0 0
Condition0%0/3
builtin::blessed($n) and $n->isa("TPath::Context")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($n) and $n->isa("TPath::Context")
builtin::blessed($n) $n->isa("TPath::Context")
Truth table0%0/3
A and B
A= builtin::blessed($n)B= $n->isa("TPath::Context")
ABresult
0X0
100
111
87 0 for my $kid ( $self->children( $n, $i ) ) {
88 0 $size += $self->standard_tsize( $kid, $i );
89 }
90 0 return $size;
91 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93  
94 0 ▶sub standard_width : Attr(width) {
Subroutine standard_width: not called CC=3 SCAR=24.8
Pod undocumented
95 0 my ( $self, $ctx ) = @_;
96 0 ▶ return 1 if $self->standard_is_leaf($ctx);
Branch: 1 branch
BranchTrueFalseTotal
if $self->standard_is_leaf($ctx) 0 0 0
97 0 my ( $n, $i ) = ( $ctx->n, $ctx->i );
98 0 my $width = 0;
99 0 for my $kid ( $self->children( $n, $i ) ) {
100 0 $width += $self->standard_width( $ctx->wrap($kid) );
101 }
102 0 return $width;
103 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105  
106 0 ▶sub standard_depth : Attr(depth) {
Subroutine standard_depth: not called CC=3 SCAR=24.8
Pod undocumented
107 0 my ( $self, $ctx ) = @_;
108 0 ▶ return 0 if $self->standard_is_root($ctx);
Branch: 1 branch
BranchTrueFalseTotal
if $self->standard_is_root($ctx) 0 0 0
109 0 my $depth = -1;
110 0 my $original = $ctx;
111 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
defined $ctx and do { do { ++$depth; $ctx = $self->parent($original, $ctx) } } 0 0 0
112 0 $depth++;
113 0 $ctx = $self->parent( $original, $ctx );
114 } while ( defined $ctx );
115 0 return $depth;
116 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118  
119 0 ▶sub standard_height : Attr(height) {
Subroutine standard_height: not called CC=4 SCAR=30.0
Pod undocumented
120 0 my ( $self, $ctx ) = @_;
121 0 ▶ return 1 if $self->standard_is_leaf($ctx);
Branch: 1 branch
BranchTrueFalseTotal
if $self->standard_is_leaf($ctx) 0 0 0
122 0 my ( $n, $i ) = ( $ctx->n, $ctx->i );
123 0 my $max = 0;
124 0 for my $kid ( $self->children( $n, $i ) ) {
125 0 my $m = $self->standard_height( $ctx->wrap($kid) );
126 0 ▶ $max = $m if $m > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $m > $max 0 0 0
127 }
128 0 return $max + 1;
129 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
130  
131  
132 0 ▶sub standard_is_root : Attr(root) {
Subroutine standard_is_root: not called CC=2 SCAR=17.9
Pod undocumented
133 0 my ( $self, $ctx ) = @_;
134 0 ▶ return $ctx->i->is_root( $ctx->n ) ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->i->is_root($ctx->n) ? : 0 0 0
135 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137  
138 0 ▶sub standard_null : Attr(null) {
Subroutine standard_null: not called CC=1 SCAR=6.9
Pod undocumented
139 0 return undef;
140 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
141  
142  
143 0 ▶sub standard_index : Attr(index) {
Subroutine standard_index: not called CC=6 SCAR=37.4
Pod undocumented
144 0 my ( $self, $ctx ) = @_;
145 0 my ( $n, $i ) = ( $ctx->n, $ctx->i );
146 0 ▶ return -1 if $i->is_root($n);
Branch: 1 branch
BranchTrueFalseTotal
if $i->is_root($n) 0 0 0
147 0 my $original = $ctx;
148 0 my $parent = $self->parent( $original, $ctx );
149 0 my $siblings = $self->_kids( $original, $parent );
150 0 my $ra = refaddr $n;
151 0 my $idx;
152  
153 0 for my $index ( 0 .. $#$siblings ) {
154 0 ▶ if ( refaddr $siblings->[$index]->n == $ra ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($siblings->[$index]->n) == $ra) 0 0 0
155 0 $idx = $index;
156 0 last;
157 }
158 }
159 0 ▶ if ( defined $idx ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $idx) 0 0 0
160 0 ▶ $idx++ if $self->one_based;
Branch: 1 branch
BranchTrueFalseTotal
if $self->one_based 0 0 0
161 0 return $idx;
162 }
163 0 confess "$n not among children of its parent";
164 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
165  
166  
167 0 ▶sub standard_log : Attr(log) {
Subroutine standard_log: not called CC=2 SCAR=17.9
Pod undocumented
168 0 my ( $self, undef, @messages ) = @_;
169 0 for my $m (@messages) {
170 0 $self->log_stream->put($m);
171 }
172 0 return 1;
173 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
174  
175  
176 0 ▶sub standard_id : Attr(id) {
Subroutine standard_id: not called CC=1 SCAR=6.9
Pod undocumented
177 0 my ( $self, $ctx ) = @_;
178 0 $self->id( $ctx->n );
179 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
180  
181  
182 0 ▶sub standard_card : Attr(card) {
Subroutine standard_card: not called CC=3 SCAR=24.8
Pod undocumented
183 0 my ( undef, undef, $o ) = @_;
184 0 ▶ return 0 unless defined $o;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 0 0
185 0 for ( ref $o ) {
186 0 when ('HASH') { return scalar keys %$o }
187 0 when ('ARRAY') { return scalar @$o }
188 0 default { return 1 }
189 }
190 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
191  
192  
193 0 ▶sub standard_attr : Attr(at) {
Subroutine standard_attr: not called CC=2 SCAR=17.9
Pod undocumented
194 0 my ( $self, $ctx, $nodes, $attr, @params ) = @_;
195 0 my @nodes = @$nodes;
196 0 ▶ return undef unless @nodes;
Branch: 1 branch
BranchTrueFalseTotal
unless @nodes 0 0 0
197 0 $self->attribute( $ctx->wrap( $nodes[0] ), $attr, @params );
198 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
199  
200  
201 0 ▶sub standard_all : Attr(all) {
Subroutine standard_all: not called CC=3 SCAR=24.8
Pod undocumented
202 0 my ( $self, undef, @params ) = @_;
203 0 for (@params) {
204 0 ▶ return undef unless $self->_booleanize($_);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_booleanize($_) 0 0 0
205 }
206 0 return 1;
207 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
208  
209  
210 0 ▶sub standard_none : Attr(none) {
Subroutine standard_none: not called CC=3 SCAR=24.8
Pod undocumented
211 0 my ( $self, undef, @params ) = @_;
212 0 for (@params) {
213 0 ▶ return undef if $self->_booleanize($_);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_booleanize($_) 0 0 0
214 }
215 0 return 1;
216 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
217  
218  
219 0 ▶sub standard_some : Attr(some) {
Subroutine standard_some: not called CC=3 SCAR=24.8
Pod undocumented
220 0 my ( $self, undef, @params ) = @_;
221 0 for (@params) {
222 0 ▶ return 1 if $self->_booleanize($_);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_booleanize($_) 0 0 0
223 }
224 0 return undef;
225 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
226  
227  
228 0 ▶sub standard_one : Attr(one) {
Subroutine standard_one: not called CC=4 SCAR=30.0
Pod undocumented
229 0 my ( $self, undef, @params ) = @_;
230 0 my $found;
231 0 for (@params) {
232 0 ▶ if ( $self->_booleanize($_) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_booleanize($_)) 0 0 0
233 0 ▶ return undef if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
234 0 $found = 1;
235 }
236 }
237 0 return $found;
238 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
239  
240  
241 0 ▶sub standard_tcount : Attr(tcount) {
Subroutine standard_tcount: not called CC=3 SCAR=24.8
Pod undocumented
242 0 my ( $self, undef, @params ) = @_;
243 0 my $found = 0;
244 0 for (@params) {
245 0 ▶ $found++ if $self->_booleanize($_);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_booleanize($_) 0 0 0
246 }
247 0 return $found;
248 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
249  
250  
251 0 ▶sub standard_fcount : Attr(fcount) {
Subroutine standard_fcount: not called CC=3 SCAR=24.8
Pod undocumented
252 0 my ( $self, undef, @params ) = @_;
253 0 my $found = 0;
254 0 for (@params) {
255 0 ▶ $found++ unless $self->_booleanize($_);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_booleanize($_) 0 0 0
256 }
257 0 return $found;
258 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
259  
260  
261 0 ▶sub standard_var : Attr(var) {
Subroutine standard_var: not called CC=3 SCAR=24.8
Pod undocumented
262 0 my ( undef, $ctx, $key, @values ) = @_;
263 0 my $vars = $ctx->expression->vars;
264 0 ▶ return $vars->{$key} unless @values;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 0 0 0
265 0 ▶ return $vars->{$key} = @values > 1 ? \@values : $values[0];
Branch: 1 branch
BranchTrueFalseTotal
@values > 1 ? : 0 0 0
266 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
267  
268 0 ▶sub standard_v : Attr(v) {
Subroutine standard_v: not called CC=1 SCAR=6.9
Pod undocumented
269 0 goto &standard_var;
270 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
271  
272  
273 0 ▶sub standard_clear_var : Attr(clear_var) {
Subroutine standard_clear_var: not called CC=1 SCAR=6.9
Pod undocumented
274 0 my ( undef, $ctx, $key) = @_;
275 0 return delete $ctx->expression->vars->{$key};
276 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
277  
278 # Converts a scalar to a boolean value, dereferencing hash and array refs.
279 0 ▶sub _booleanize {
Subroutine _booleanize: not called CC=3 SCAR=24.8
280 0 my ( $self, $v ) = @_;
281 0 for ( ref $v ) {
282 0 when ('ARRAY') { $v = @$v }
283 0 when ('HASH') { $v = keys %$v }
284 }
285 0 ▶ return $v && 1;
Condition0%0/2
$v && 1
!ll
00
MC/DC0%0/1
$v && 1
$v
Truth table0%0/2
A
A= $v
Aresult
00
11
286 }
287  
288 1 1;
289  
290 __END__
« TPath/Test/One.pm ↑ Summary TPath/TypeCheck.pm »