Graph/AdjacencyMap.pm

filter: Statementstmt 99.3% 298 / 300 Branchbran 91.5% 163 / 178 Conditioncond 83.3% 85 / 102 MC/DCmcdc 65.5% 40 / 61 Subroutinesub 96.6% 57 / 59 Podpod 100% 20 / 20 totaltotal 92.0% 663 / 720 CC 136 SCAR 21.0
CC
136
Cov
94%
get_ids_by_paths
24.0
__set_path
18.0
stringify
11.0
CRAP 8.1
« Graph/Traversal.pm ↑ Summary Graph/TransitiveClosure.pm »
1 package Graph::AdjacencyMap;
2  
3 84 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 84 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # $SIG{__DIE__ } = \&Graph::__carp_confess;
7 # $SIG{__WARN__} = \&Graph::__carp_confess;
8  
9 84 my $empty = {};
10 90 ▶sub _empty () { $empty }
Subroutine _empty: called CC=1 SCAR=0.0
11  
12 84 my (@FLAGS, %FLAG_COMBOS, %FLAG2I, @FIELDS);
13 84 ▶BEGIN {
Subroutine BEGIN: called CC=5 SCAR=16.1
14 84 @FLAGS = qw(_COUNT _MULTI _UNORD _REF _UNIONFIND _LIGHT _STR);
15 84 %FLAG_COMBOS = (
16 _COUNTMULTI => [qw(_COUNT _MULTI)],
17 _REFSTR => [qw(_REF _STR)],
18 );
19 # Next id, Flags, Arity, Index to path, path to index,
20 # successors, predecessors: 2-level hashes to array-ref of path IDs
21 # attributes - two-level for MULTI, node/multi count
22 84 @FIELDS = qw(_n _f _arity _i _pi _s _p _attr _count);
23 84 for my $i (0..$#FLAGS) {
24 588 my $n = $FLAGS[$i];
25 588 my $f = 1 << $i;
26 588 $FLAG2I{$n} = $f;
27 84 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 0 ▶ *$n = sub () { $f };
Subroutine __ANON__: not called CC=1 SCAR=1.2
29 588 ▶ *{"_is$n"} = sub { $_[0]->[ 1 ] & $f }; # 1 = _f
Subroutine __ANON__: called CC=1 SCAR=0.0
30 }
31 84 for my $k (keys %FLAG_COMBOS) {
32 168 my $f = 0;
33 168 $f |= $_ for map $FLAG2I{$_}, @{ $FLAG_COMBOS{$k} };
34 84 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 168 ▶ *$k = sub () { return $f }; # return to dodge pointless 5.22 stricture
Subroutine __ANON__: called CC=1 SCAR=0.0
36 168 ▶ *{"_is$k"} = sub { $_[0]->[ 1 ] & $f }; # 1 = _f
Subroutine __ANON__: called CC=1 SCAR=0.0
37 }
38 84 for my $i (0..$#FIELDS) {
39 84 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 0 ▶ *{ $FIELDS[$i] }= sub () { $i };
Subroutine __ANON__: not called CC=1 SCAR=0.4
41 }
42 }
43  
44 4580 ▶sub _new {
Subroutine _new: called CC=4 SCAR=13.9
45 4580 my ($class, $flags, $arity) = @_;
46 4580 my $hyper = !$arity;
47 4580 my $need_s = $arity != 1;
48 4580 ▶ my $need_p = $need_s && !($flags & _UNORD);
Condition100%3/3
$need_s && !($flags & 4)
!ll&&!rl&&r
22881744548
MC/DC100%2/2
$need_s && !($flags & 4)
$need_s !($flags & 4)
Truth table100%3/3
A && not(B)
A= $need_sB= !($flags & 4)
ABresult
0X0
100
111
49 4580 ▶ bless [
Branch: 2 branches
BranchTrueFalseTotal
$need_s ? : 2292 2288 4580
$need_p ? : 548 4032 4580
50 0, $flags, $arity, [], {},
51 ($need_s ? {} : undef), ($need_p ? {} : undef),
52 [], [],
53 ], $class;
54 }
55  
56 84 require Exporter;
57 84 ▶use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
58 84 @ISA = qw(Exporter);
59 84 %EXPORT_TAGS =
60 (flags => [@FLAGS, keys %FLAG_COMBOS, qw(_GEN_ID)],
61 fields => \@FIELDS);
62 84 @EXPORT_OK = map @$_, values %EXPORT_TAGS;
63  
64 84 my $_GEN_ID = 0;
65  
66 299 ▶sub _GEN_ID () { \$_GEN_ID }
Subroutine _GEN_ID: called CC=1 SCAR=0.0
67  
68 24 ▶sub stringify {
Subroutine stringify: called CC=11 SCAR=24.0
Pod documented
69 24 my ($f, $arity, $m) = (@{ $_[0] }[ _f, _arity ], $_[0]);
70 24 my ($multi, @rows) = $f & _MULTI;
71 24 my @p = $m->paths;
72 @p = $arity == 1 ? sort @p :
73 24 ▶ map $_->[0], sort { $a->[1] cmp $b->[1] }
Branch: 2 branches
BranchTrueFalseTotal
$arity == 1 ? : 9 15 24
$arity == 0 && !($f & 4) ? : 3 12 15
Condition100%3/3
$arity == 0 and not $f & 4
!ll&&!rl&&r
1023
MC/DC100%2/2
$arity == 0 and not $f & 4
$arity == 0 not $f & 4
Truth table100%3/3
A and not(B)
A= $arity == 0B= not $f & 4
ABresult
0X0
100
111
74 ($arity == 0 && !($f & _UNORD))
75 ? map [$_, join '|', map "@$_", @$_], @p
76 : map [$_,"@$_"], @p; # use the Schwartz
77 24 ▶ if ($arity == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arity == 2) { } 10 14 24
78 10 require Set::Object;
79 10 my ($pre, $suc, @s) = (Set::Object->new(map $_->[0], @p), Set::Object->new(map $_->[1], @p));
80 @rows = ([ 'to:', @s = sort $suc->members ], map {
81 10 my $p = $_;
82 [ $p, map {
83 24 ▶ my $text = defined(my $id = $m->has_path([$p, $_])) ? 1 : '';
Branch: 1 branch
BranchTrueFalseTotal
defined(my $id = $m->has_path([$p, $_])) ? : 61 32 93
84 93 ▶ my $attrs = !$text ? undef :
Branch: 2 branches
BranchTrueFalseTotal
!$text ? : 32 61 93
$multi ? : 3 58 61
85 $multi ? $m->[ _attr ][$id] : $m->_get_path_attrs([$p, $_]);
86 93 ▶ defined $attrs ? $m->_dumper($attrs) : $text;
Branch: 1 branch
BranchTrueFalseTotal
defined $attrs ? : 4 89 93
87 } @s ];
88 } sort $pre->members);
89 } else {
90 @rows = map {
91 14 ▶ my $attrs = $multi
Branch: 1 branch
BranchTrueFalseTotal
$multi ? : 4 29 33
92 ? $m->[ _attr ][ $m->has_path($_) ] : $m->_get_path_attrs($_);
93 33 ▶ [ $m->_dumper($_),
Branch: 1 branch
BranchTrueFalseTotal
!defined($attrs) ? : 26 7 33
94 ($m->get_ids_by_paths([ $_ ], 0))[0].
95 (!defined $attrs ? '' : ",".$m->_dumper($attrs)) ];
96 } @p;
97 }
98 24 join '',
99 map "$_\n",
100 24 "@{[ref $m]} arity=$arity flags: @{[_stringify_fields($m->[ _f ])]}",
101 map join(' ', map sprintf('%4s', $_), @$_),
102 @rows;
103 }
104  
105 38 ▶sub _stringify_fields {
Subroutine _stringify_fields: called CC=2 SCAR=6.9
106 38 ▶ return '0' if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 8 30 38
107 30 join '|', grep $_[0] & $FLAG2I{$_}, @FLAGS;
108 }
109  
110 58 ▶sub _dumper {
Subroutine _dumper: called CC=4 SCAR=14.0
111 58 my (undef, $got) = @_;
112 58 ▶ return $got if defined $got and !ref $got;
Branch: 1 branch
BranchTrueFalseTotal
if defined $got and not ref $got 27 31 58
Condition66%2/3
defined $got and not ref $got
!ll&&!rl&&r
03127
MC/DC50%1/2
defined $got and not ref $got
defined $got not ref $got
Truth table66%2/3
A and not(B)
A= defined $gotB= not ref $got
ABresult
0X0
100
111
113 31 require Data::Dumper;
114 31 my $dumper = Data::Dumper->new([$got]);
115 31 $dumper->Indent(0)->Terse(1);
116 31 ▶ $dumper->Sortkeys(1) if $dumper->can("Sortkeys");
Branch: 1 branch
BranchTrueFalseTotal
if $dumper->can("Sortkeys") 31 0 31
117 31 $dumper->Dump;
118 }
119  
120 90 ▶sub has_any_paths {
Subroutine has_any_paths: called CC=1 SCAR=0.0
Pod documented
121 90 scalar keys %{ $_[0]->[ _pi ] };
122 }
123  
124 162 ▶sub _set_path_attr_common {
Subroutine _set_path_attr_common: called CC=2 SCAR=6.9
125 162 push @_, 0;
126 162 my ($i) = &__set_path;
127 162 my $attr = (my $m = $_[0])->[ _attr ];
128 162 ▶ ($m->[ _f ] & _MULTI) ? \$attr->[ $i ]{ $_[2] } : \$attr->[ $i ];
Branch: 1 branch
BranchTrueFalseTotal
$m->[1] & 2 ? : 99 63 162
129 }
130  
131 1171 ▶sub _set_path_attrs {
Subroutine _set_path_attrs: called CC=1 SCAR=0.0
132 1171 ${ &{ $_[0]->can('_set_path_attr_common') } } = $_[-1];
133 }
134  
135 4791 ▶sub _set_path_attr {
Subroutine _set_path_attr: called CC=1 SCAR=0.0
136 4791 ${ &{ $_[0]->can('_set_path_attr_common') } }->{ $_[-2] } = $_[-1];
137 }
138  
139 315 ▶sub set_paths {
Subroutine set_paths: called CC=1 SCAR=0.0
Pod documented
140 315 map +($_[0]->__set_path($_, 1))[0], @_[1..$#_];
141 }
142  
143 219 ▶sub set_path_by_multi_id {
Subroutine set_path_by_multi_id: called CC=1 SCAR=0.0
Pod documented
144 219 push @_, 1;
145 219 goto &__set_path;
146 }
147  
148 700 ▶sub __set_path {
Subroutine __set_path: called CC=18 SCAR=28.9
149 700 my $inc_if_exists = pop;
150 700 &__arg;
151 700 my ($f, $a, $map_i, $pi, $map_s, $map_p, $m, $k, $id) = (@{ $_[0] }[ _f, _arity, _i, _pi, _s, _p ], @_);
152 700 my $is_multi = $f & _MULTI;
153 700 my $k_orig = $k;
154 700 ▶ $k = __strval($k, $f) if $a == 1 && ($f & _REF) && ref($k);
Branch: 1 branch
BranchTrueFalseTotal
if $a == 1 and $f & 8 and ref $k 185 515 700
Condition100%6/6
$a == 1 and $f & 8 and ref $k
!ll&&!rl&&r
47342185
$a == 1 and $f & 8
!ll&&!rl&&r
315158227
MC/DC100%3/3
$a == 1 and $f & 8 and ref $k
$a == 1 $f & 8 ref $k
Truth table100%4/4
A and B and C
A= $a == 1B= $f & 8C= ref $k
ABCresult
0XX0
10X0
1100
1111
155 700 ▶ my $l = ($a == 0 && !($f & _UNORD)) ? join '|', map join(' ', sort @$_), @$k : $a == 1 ? "$k" : "@$k";
Branch: 2 branches
BranchTrueFalseTotal
$a == 0 && !($f & 4) ? : 30 670 700
$a == 1 ? : 385 285 670
Condition100%3/3
$a == 0 and not $f & 4
!ll&&!rl&&r
6284230
MC/DC100%2/2
$a == 0 and not $f & 4
$a == 0 not $f & 4
Truth table100%3/3
A and not(B)
A= $a == 0B= not $f & 4
ABresult
0X0
100
111
156 700 ▶ if (exists $pi->{ $l }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pi->{$l}) 228 472 700
157 228 ▶ return ($pi->{ $l }) if !($inc_if_exists and ($f & _COUNTMULTI));
Branch: 1 branch
BranchTrueFalseTotal
unless $inc_if_exists and $f & &_COUNTMULTI() 173 55 228
Condition100%3/3
$inc_if_exists and $f & &_COUNTMULTI()
!ll&&!rl&&r
1621155
MC/DC100%2/2
$inc_if_exists and $f & &_COUNTMULTI()
$inc_if_exists $f & &_COUNTMULTI()
Truth table100%3/3
A and B
A= $inc_if_existsB= $f & &_COUNTMULTI()
ABresult
0X0
100
111
158 55 my $nc = \$m->[ _count ][ my $i = $pi->{ $l } ];
159 55 ▶ $$nc++, return ($i) if !$is_multi;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_multi 21 34 55
160 34 my $na = $m->[ _attr ][ $i ];
161 34 ▶ if ($id eq _GEN_ID) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id eq &_GEN_ID()) 17 17 34
162 17 ▶ $$nc++ while exists $na->{ $$nc };
Branch: 1 branch
BranchTrueFalseTotal
exists $$na{$$nc} and do { ++$$nc } 13 17 30
163 17 $id = $$nc;
164 }
165 34 $na->{ $id } = { };
166 34 return ($i, $id);
167 }
168 472 $map_i->[ $pi->{ $l } = my $i = $m->[ _n ]++ ] = $k_orig;
169 472 ▶ $m->[ _attr ][ $i ] = { ($id = ($id eq _GEN_ID) ? 0 : $id) => {} } if $is_multi;
Branch: 2 branches
BranchTrueFalseTotal
if $is_multi 185 287 472
$id eq &_GEN_ID() ? : 63 122 185
170 472 ▶ $m->[ _count ][ $i ] = $is_multi ? 0 : 1 if ($f & _COUNTMULTI);
Branch: 2 branches
BranchTrueFalseTotal
if $f & &_COUNTMULTI() 247 225 472
$is_multi ? : 185 62 247
171 472 ▶ _successors_add($f, $a, $map_s, $map_p, $i, $k) if $map_s; # dereffed
Branch: 1 branch
BranchTrueFalseTotal
if $map_s 174 298 472
172 472 ($i, $id);
173 }
174  
175 174 ▶sub _successors_add {
Subroutine _successors_add: called CC=4 SCAR=13.9
176 174 my ($f, $a, $map_s, $map_p, $id, $path) = @_;
177 174 my $pairs = _successors_cartesian(($f & _UNORD), $a == 0, $path);
178 174 push @{ $map_s->{ $_->[0] }{ $_->[1] } }, $id for @$pairs;
179 174 ▶ return if !$map_p;
Branch: 1 branch
BranchTrueFalseTotal
unless $map_p 55 119 174
180 119 push @{ $map_p->{ $_->[1] }{ $_->[0] } }, $id for @$pairs;
181 }
182  
183 26 ▶sub _successors_del {
Subroutine _successors_del: called CC=7 SCAR=19.5
184 26 my ($f, $a, $map_s, $map_p, $id, $path) = @_;
185 26 my $pairs = _successors_cartesian(($f & _UNORD), $a == 0, $path);
186 26 for (@$pairs) {
187 63 my ($p, $s) = @$_;
188 63 my @new = grep $_ != $id, @{ $map_s->{ $p }{ $s } };
189 63 ▶ if (@new) {
Branch: 1 branch
BranchTrueFalseTotal
if (@new) 2 61 63
190 2 $map_s->{ $p }{ $s } = \@new;
191 2 ▶ $map_p->{ $s }{ $p } = \@new if $map_p;
Branch: 1 branch
BranchTrueFalseTotal
if $map_p 0 2 2
192 2 next;
193 }
194 61 delete $map_s->{ $p }{ $s };
195 61 ▶ delete $map_s->{ $p } if !keys %{ $map_s->{ $p } };
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$map_s{$p};} 34 27 61
196 61 ▶ next if !$map_p;
Branch: 1 branch
BranchTrueFalseTotal
unless $map_p 32 29 61
197 29 delete $map_p->{ $s }{ $p };
198 29 ▶ delete $map_p->{ $s } if !keys %{ $map_p->{ $s } };
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$map_p{$s};} 19 10 29
199 }
200 }
201  
202 50177 ▶sub _successors_cartesian {
Subroutine _successors_cartesian: called CC=9 SCAR=22.0
203 50177 my ($unord, $hyper, $seq) = @_;
204 50177 ▶ return [ $seq ] if !$unord and !$hyper;
Branch: 1 branch
BranchTrueFalseTotal
unless $unord or $hyper 15123 35054 50177
Condition100%3/3
$unord or $hyper
l!l&&r!l&&!r
350381615123
MC/DC100%2/2
$unord or $hyper
$unord $hyper
Truth table100%3/3
A or B
A= $unordB= $hyper
ABresult
1X1
011
000
205 35054 ▶ return [] if $unord and $hyper and !@$seq;
Branch: 1 branch
BranchTrueFalseTotal
if $unord and $hyper and not @$seq 5 35049 35054
Condition100%6/6
$unord and $hyper and not @$seq
!ll&&!rl&&r
35027225
$unord and $hyper
!ll&&!rl&&r
163501127
MC/DC100%3/3
$unord and $hyper and not @$seq
$unord $hyper not @$seq
Truth table100%4/4
A and B and not(C)
A= $unordB= $hyperC= not @$seq
ABCresult
0XX0
10X0
1100
1111
206 35049 my ($allow_self, $p_s, $s_s, @pairs);
207 35049 ▶ if ($unord) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unord) { } 35033 16 35049
208 35033 require Set::Object;
209 35033 my @a = Set::Object->new(@$seq)->members;
210 35033 ($allow_self, $p_s, $s_s) = (@a < 2, \@a, \@a);
211 } else {
212 16 ($allow_self, $p_s, $s_s) = (1, @$seq);
213 }
214 35049 for my $p (@$p_s) {
215 69850 ▶ push @pairs, map [$p, $_], $allow_self ? @$s_s : grep $p != $_, @$s_s;
Branch: 1 branch
BranchTrueFalseTotal
$allow_self ? : 304 69546 69850
216 }
217 35049 \@pairs;
218 }
219  
220 420 ▶sub _get_path_count {
Subroutine _get_path_count: called CC=4 SCAR=13.9
221 420 ▶ return 0 unless my ($i) = &__has_path;
Branch: 1 branch
BranchTrueFalseTotal
unless my($i) = &__has_path 23 397 420
222 397 my $f = (my $m = $_[0])->[ _f ];
223 return
224 ($f & _COUNT) ? $m->[ _count ][ $i ] :
225 397 ▶ ($f & _MULTI) ? scalar keys %{ $m->[ _attr ][ $i ] } : 1;
Branch: 2 branches
BranchTrueFalseTotal
$f & 1 ? : 68 329 397
$f & 2 ? : 293 36 329
226 }
227  
228 778 ▶sub has_path {
Subroutine has_path: called CC=1 SCAR=0.0
Pod documented
229 778 ( &__has_path )[0];
230 }
231  
232 549 ▶sub has_path_by_multi_id {
Subroutine has_path_by_multi_id: called CC=2 SCAR=6.9
Pod documented
233 549 ▶ return undef unless my ($i) = &__has_path;
Branch: 1 branch
BranchTrueFalseTotal
unless my($i) = &__has_path 95 454 549
234 454 return exists $_[0]->[ _attr ][ $i ]{ $_[2] };
235 }
236  
237 209 ▶sub del_path {
Subroutine del_path: called CC=4 SCAR=13.9
Pod documented
238 209 ▶ return unless my ($i, $l) = &__has_path;
Branch: 1 branch
BranchTrueFalseTotal
unless () = &__has_path 1 208 209
239 208 ▶ return 1 if &_is_COUNT and --$_[0][ _count ][ $i ] > 0;
Branch: 1 branch
BranchTrueFalseTotal
if &_is_COUNT and --$_[0][8][$i] > 0 12 196 208
Condition100%3/3
&_is_COUNT and --$_[0][8][$i] > 0
!ll&&!rl&&r
1762012
MC/DC100%2/2
&_is_COUNT and --$_[0][8][$i] > 0
&_is_COUNT --$_[0][8][$i] > 0
Truth table100%3/3
A and B
A= &_is_COUNTB= --$_[0][8][$i] > 0
ABresult
0X0
100
111
240 196 $_[0]->_sequence_del($i, $l);
241 196 1;
242 }
243  
244 22 ▶sub del_path_by_multi_id {
Subroutine del_path_by_multi_id: called CC=3 SCAR=11.0
Pod documented
245 22 ▶ return unless my ($i, $l) = &__has_path;
Branch: 1 branch
BranchTrueFalseTotal
unless () = &__has_path 0 22 22
246 22 delete((my $attrs = (my $m = $_[0])->[ _attr ][ $i ])->{ $_[2] });
247 22 ▶ return 1 if keys %$attrs;
Branch: 1 branch
BranchTrueFalseTotal
if keys %$attrs 9 13 22
248 13 $m->_sequence_del($i, $l);
249 13 1;
250 }
251  
252 311 ▶sub get_multi_ids {
Subroutine get_multi_ids: called CC=3 SCAR=11.0
Pod documented
253 311 ▶ return unless ((my $m = $_[0])->[ _f ] & _MULTI) and my ($i) = &__has_path;
Branch: 1 branch
BranchTrueFalseTotal
unless +(my $m = $_[0])->[1] & 2 and my($i) = &__has_path 2 309 311
Condition66%2/3
+(my $m = $_[0])->[1] & 2 and my($i) = &__has_path
!ll&&!rl&&r
02309
MC/DC50%1/2
+(my $m = $_[0])->[1] & 2 and my($i) = &__has_path
+(my $m = $_[0])->[1] & 2 my($i) = &__has_path
Truth table66%2/3
A and B
A= +(my $m = $_[0])->[1] & 2B= my($i) = &__has_path
ABresult
0X0
100
111
254 309 keys %{ $m->[ _attr ][ $i ] };
255 }
256  
257 32 ▶sub rename_path {
Subroutine rename_path: called CC=5 SCAR=16.4
Pod documented
258 32 my ($m, $from, $to) = @_;
259 32 ▶ return 1 if $m->[ _arity ] != 1; # all integers, no names
Branch: 1 branch
BranchTrueFalseTotal
if $m->[2] != 1 0 32 32
260 32 ▶ return unless my ($i, $l) = $m->__has_path($from);
Branch: 1 branch
BranchTrueFalseTotal
unless () = $m->__has_path($from) 0 32 32
261 32 $m->[ _i ][ $i ] = $to;
262 32 ▶ $to = __strval($to, $m->[ _f ]) if ref($to) and ($m->[ _f ] & _REF);
Branch: 1 branch
BranchTrueFalseTotal
if ref $to and $m->[1] & 8 4 28 32
Condition66%2/3
ref $to and $m->[1] & 8
!ll&&!rl&&r
2804
MC/DC50%1/2
ref $to and $m->[1] & 8
ref $to $m->[1] & 8
Truth table66%2/3
A and B
A= ref $toB= $m->[1] & 8
ABresult
0X0
100
111
263 32 $m->[ _pi ]{ $to } = delete $m->[ _pi ]{ $l };
264 32 return 1;
265 }
266  
267 38 ▶sub _del_path_attrs {
Subroutine _del_path_attrs: called CC=3 SCAR=11.0
268 38 ▶ return unless my ($i) = &__has_path;
Branch: 1 branch
BranchTrueFalseTotal
unless my($i) = &__has_path 0 38 38
269 38 my $attr = (my $m = $_[0])->[ _attr ];
270 38 ▶ return $attr->[ $i ]{ $_[2] } = undef, 1 if ($m->[ _f ] & _MULTI);
Branch: 1 branch
BranchTrueFalseTotal
if $m->[1] & 2 11 27 38
271 27 delete $attr->[ $i ];
272 }
273  
274 2923 ▶sub __has_path {
Subroutine __has_path: called CC=8 SCAR=20.8
275 2923 &__arg;
276 2923 my ($f, $a, $pi, $k) = (@{ $_[0] }[ _f, _arity, _pi ], $_[1]);
277 2923 ▶ $k = __strval($k, $f) if $a == 1 && ($f & _REF) && ref($k);
Branch: 1 branch
BranchTrueFalseTotal
if $a == 1 and $f & 8 and ref $k 891 2032 2923
Condition100%6/6
$a == 1 and $f & 8 and ref $k
!ll&&!rl&&r
197755891
$a == 1 and $f & 8
!ll&&!rl&&r
1333644946
MC/DC100%3/3
$a == 1 and $f & 8 and ref $k
$a == 1 $f & 8 ref $k
Truth table100%4/4
A and B and C
A= $a == 1B= $f & 8C= ref $k
ABCresult
0XX0
10X0
1100
1111
278 2923 ▶ my $l = ($a == 0 && !($f & _UNORD)) ? join '|', map join(' ', sort @$_), @$k : $a == 1 ? "$k" : "@$k";
Branch: 2 branches
BranchTrueFalseTotal
$a == 0 && !($f & 4) ? : 66 2857 2923
$a == 1 ? : 1590 1267 2857
Condition100%3/3
$a == 0 and not $f & 4
!ll&&!rl&&r
27669166
MC/DC100%2/2
$a == 0 and not $f & 4
$a == 0 not $f & 4
Truth table100%3/3
A and not(B)
A= $a == 0B= not $f & 4
ABresult
0X0
100
111
279 2923 my $id = $pi->{ $l };
280 2923 ▶ (defined $id ? $id : return, $l);
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 2541 382 2923
281 }
282  
283 564 ▶sub _get_path_attrs {
Subroutine _get_path_attrs: called CC=3 SCAR=11.0
284 564 ▶ return unless my ($i) = &__has_path;
Branch: 1 branch
BranchTrueFalseTotal
unless my($i) = &__has_path 9 555 564
285 555 my $attrs = (my $m = $_[0])->[ _attr ][ $i ];
286 555 ▶ ($m->[ _f ] & _MULTI) ? $attrs->{ $_[2] } : $attrs;
Branch: 1 branch
BranchTrueFalseTotal
$m->[1] & 2 ? : 391 164 555
287 }
288  
289 82 ▶sub _has_path_attrs {
Subroutine _has_path_attrs: called CC=3 SCAR=11.0
290 82 ▶ keys %{ &{ $_[0]->can('_get_path_attrs') } || return undef } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
keys %{&{$_[0]->can('_get_path_attrs');} or return undef;} ? : 56 6 62
Condition100%2/2
&{$_[0]->can('_get_path_attrs');} || (return undef)
l!l
6220
MC/DC100%1/1
&{$_[0]->can('_get_path_attrs');} || (return undef)
&{$_[0]->can('_get_path_attrs');}
Truth table100%2/2
A
A= &{$_[0]->can('_get_path_attrs');}
Aresult
11
00
291 }
292  
293 62 ▶sub _has_path_attr {
Subroutine _has_path_attr: called CC=2 SCAR=6.9
294 62 ▶ exists(( &{ $_[0]->can('_get_path_attrs') } || return )->{ $_[-1] });
Condition100%2/2
&{$_[0]->can('_get_path_attrs');} || (return)
l!l
3329
MC/DC100%1/1
&{$_[0]->can('_get_path_attrs');} || (return)
&{$_[0]->can('_get_path_attrs');}
Truth table100%2/2
A
A= &{$_[0]->can('_get_path_attrs');}
Aresult
11
00
295 }
296  
297 11666 ▶sub _get_path_attr {
Subroutine _get_path_attr: called CC=2 SCAR=6.9
298 11666 ▶ ( &{ $_[0]->can('_get_path_attrs') } || return )->{ $_[-1] };
Condition100%2/2
&{$_[0]->can('_get_path_attrs');} || (return)
l!l
58525814
MC/DC100%1/1
&{$_[0]->can('_get_path_attrs');} || (return)
&{$_[0]->can('_get_path_attrs');}
Truth table100%2/2
A
A= &{$_[0]->can('_get_path_attrs');}
Aresult
11
00
299 }
300  
301 78 ▶sub _get_path_attr_names {
Subroutine _get_path_attr_names: called CC=2 SCAR=6.9
302 78 ▶ keys %{ &{ $_[0]->can('_get_path_attrs') } || return };
Condition100%2/2
&{$_[0]->can('_get_path_attrs');} || (return)
l!l
6018
MC/DC100%1/1
&{$_[0]->can('_get_path_attrs');} || (return)
&{$_[0]->can('_get_path_attrs');}
Truth table100%2/2
A
A= &{$_[0]->can('_get_path_attrs');}
Aresult
11
00
303 }
304  
305 26 ▶sub _get_path_attr_values {
Subroutine _get_path_attr_values: called CC=2 SCAR=6.9
306 26 ▶ values %{ &{ $_[0]->can('_get_path_attrs') } || return };
Condition100%2/2
&{$_[0]->can('_get_path_attrs');} || (return)
l!l
224
MC/DC100%1/1
&{$_[0]->can('_get_path_attrs');} || (return)
&{$_[0]->can('_get_path_attrs');}
Truth table100%2/2
A
A= &{$_[0]->can('_get_path_attrs');}
Aresult
11
00
307 }
308  
309 40 ▶sub _del_path_attr {
Subroutine _del_path_attr: called CC=4 SCAR=13.9
310 40 ▶ return unless my $attrs = &{ $_[0]->can('_get_path_attrs') };
Branch: 1 branch
BranchTrueFalseTotal
unless my $attrs = &{$_[0]->can("_get_path_attrs");} 4 36 40
311 36 ▶ return 0 unless exists $attrs->{ my $attr = $_[-1] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$attrs{my $attr = $_[-1]} 0 36 36
312 36 delete $attrs->{$attr};
313 36 ▶ return 1 if keys %$attrs;
Branch: 1 branch
BranchTrueFalseTotal
if keys %$attrs 21 15 36
314 15 &{ $_[0]->can('_del_path_attrs') };
315 15 1;
316 }
317  
318 209 ▶sub _sequence_del {
Subroutine _sequence_del: called CC=3 SCAR=11.0
319 209 my ($m, $id, $l) = @_;
320 209 my ($f, $a, $map_i, $pi, $map_s, $map_p) = @$m[ _f, _arity, _i, _pi, _s, _p ];
321 209 delete $pi->{ $l };
322 209 delete $m->[ $_ ][ $id ] for _count, _attr;
323 209 my $path = delete $map_i->[ $id ];
324 209 ▶ _successors_del($f, $a, $map_s, $map_p, $id, $path) if $map_s;
Branch: 1 branch
BranchTrueFalseTotal
if $map_s 26 183 209
325 209 return 1;
326 }
327  
328 17861 ▶sub get_paths_by_ids {
Subroutine get_paths_by_ids: called CC=2 SCAR=6.9
Pod documented
329 17861 my ($i, undef, $list, $deep) = ( @{ $_[0] }[ _i ], @_ );
330 17861 ▶ $deep ? map [ map [ @$i[ @$_ ] ], @$_ ], @$list : map [ @$i[ @$_ ] ], @$list;
Branch: 1 branch
BranchTrueFalseTotal
$deep ? : 302 17559 17861
331 }
332  
333 4882 ▶sub paths {
Subroutine paths: called CC=2 SCAR=8.1
Pod documented
334 4882 ▶ grep defined, @{ $_[0]->[ _i ] || Graph::_empty_array() };
Condition33%1/3
$_[0][3] || &Graph::_empty_array()
l!l&&r!l&&!r
488200
MC/DC0%0/2
$_[0][3] || &Graph::_empty_array()
$_[0][3] &Graph::_empty_array()
Truth table33%1/3
A || B
A= $_[0][3]B= &Graph::_empty_array()
ABresult
1X1
011
000
335 }
336  
337 302 ▶sub ids {
Subroutine ids: called CC=2 SCAR=8.1
Pod documented
338 302 ▶ values %{ $_[0]->[ _pi ] || Graph::_empty_array() };
Condition33%1/3
$_[0][4] || &Graph::_empty_array()
l!l&&r!l&&!r
30200
MC/DC0%0/2
$_[0][4] || &Graph::_empty_array()
$_[0][4] &Graph::_empty_array()
Truth table33%1/3
A || B
A= $_[0][4]B= &Graph::_empty_array()
ABresult
1X1
011
000
339 }
340  
341 1194 ▶sub get_ids_by_paths {
Subroutine get_ids_by_paths: called CC=24 SCAR=31.8
Pod documented
342 1194 my ($f, $a, $pi, $m, $list, $ensure, $deep) = ( @{ $_[0] }[ _f, _arity, _pi ], @_ );
343 1194 ▶ $deep ||= 0;
Condition100%2/2
$deep ||= 0
l!l
1581036
MC/DC100%1/1
$deep ||= 0
$deep
Truth table100%2/2
A
A= $deep
Aresult
11
00
344 1194 my ($is_multi, $is_ref, $is_unord) = (map $f & $_, _MULTI, _REF, _UNORD);
345 return map { # Fast path
346 1194 ▶ my @ret = map {
Branch: 1 branch
BranchTrueFalseTotal
if $a and not $is_ref and $deep < 2 174 1020 1194
Condition100%6/6
$a and not $is_ref and $deep < 2
!ll&&!rl&&r
10164174
$a and not $is_ref
!ll&&!rl&&r
131003178
MC/DC100%3/3
$a and not $is_ref and $deep < 2
$a not $is_ref $deep < 2
Truth table100%4/4
A and not(B) and C
A= $aB= not $is_refC= $deep < 2
ABCresult
0XX0
10X0
1100
1111
347 183 ▶ my $id = $pi->{ $a != 1 ? "@$_" : $_ };
Branch: 1 branch
BranchTrueFalseTotal
$a != 1 ? : 8 215 223
348 223 ▶ defined $id ? $id :
Branch: 4 branches
BranchTrueFalseTotal
defined $id ? : 166 57 223
!$ensure ? : 13 44 57
$is_multi ? : 33 11 44
$deep ? : 44 139 183
349 !$ensure ? return :
350 ($is_multi ? $m->set_path_by_multi_id($_, _GEN_ID) : $m->set_paths($_))[0];
351 } $deep ? @$_ : $_;
352 170 ▶ $deep ? \@ret : @ret;
Branch: 1 branch
BranchTrueFalseTotal
$deep ? : 37 133 170
353 } @$list if $a and !$is_ref and $deep < 2;
354 map {
355 1020 my @ret = map {
356 1166 my @ret2 = map {
357 1277 my $k = $_;
358 1290 ▶ $k = __strval($k, $f) if $a == 1 && $is_ref && ref($k);
Branch: 1 branch
BranchTrueFalseTotal
if $a == 1 and $is_ref and ref $k 1067 223 1290
Condition100%6/6
$a == 1 and $is_ref and ref $k
!ll&&!rl&&r
301931067
$a == 1 and $is_ref
!ll&&!rl&&r
13171260
MC/DC100%3/3
$a == 1 and $is_ref and ref $k
$a == 1 $is_ref ref $k
Truth table100%4/4
A and B and C
A= $a == 1B= $is_refC= ref $k
ABCresult
0XX0
10X0
1100
1111
359 1290 ▶ my $l = ($a == 0 && !$is_unord) ? join '|', map join(' ', sort @$_), @$k : $a == 1 ? "$k" : "@$k";
Branch: 2 branches
BranchTrueFalseTotal
$a == 0 && !$is_unord ? : 7 1283 1290
$a == 1 ? : 1277 6 1283
Condition100%3/3
$a == 0 and not $is_unord
!ll&&!rl&&r
127767
MC/DC100%2/2
$a == 0 and not $is_unord
$a == 0 not $is_unord
Truth table100%3/3
A and not(B)
A= $a == 0B= not $is_unord
ABresult
0X0
100
111
360 1290 my $id = $pi->{ $l };
361 1290 ▶ defined $id ? $id :
Branch: 4 branches
BranchTrueFalseTotal
defined $id ? : 941 349 1290
!$ensure ? : 161 188 349
$is_multi ? : 0 188 188
$deep > 1 ? : 12 1265 1277
362 !$ensure ? return :
363 ($is_multi ? $m->set_path_by_multi_id($_, _GEN_ID) : $m->set_paths($_))[0];
364 } $deep > 1 ? @$_ : $_;
365 1116 ▶ $deep > 1 ? \@ret2 : @ret2;
Branch: 2 branches
BranchTrueFalseTotal
$deep > 1 ? : 12 1104 1116
$deep ? : 116 1050 1166
366 } $deep ? @$_ : $_;
367 1005 ▶ $deep ? \@ret : @ret;
Branch: 1 branch
BranchTrueFalseTotal
$deep ? : 111 894 1005
368 } @$list;
369 }
370  
371 44 ▶sub _paths_fromto {
Subroutine _paths_fromto: called CC=3 SCAR=11.1
372 44 my $offset = pop;
373 44 my ($i, $map_x, @v) = ( @{ $_[0] }[ _i, $offset ], @_[1..$#_] );
374 44 ▶ Graph::__carp_confess("undefined vertex") if grep !defined, @v;
Branch: 1 branch
BranchTrueFalseTotal
if grep((!defined($_)), @v) 0 44 44
375 44 require Set::Object;
376 44 ▶ map $i->[ $_ ], Set::Object->new(map @$_, map values %{ $map_x->{ $_ } || _empty }, @v)->members;
Condition66%2/3
$map_x->{$_} || &_empty()
l!l&&r!l&&!r
39110
MC/DC0%0/2
$map_x->{$_} || &_empty()
$map_x->{$_} &_empty()
Truth table66%2/3
A || B
A= $map_x->{$_}B= &_empty()
ABresult
1X1
011
000
377 }
378 27 ▶sub paths_from { push @_, _s; goto &_paths_fromto }
Subroutine paths_from: called CC=1 SCAR=0.0
Pod documented
379 17 ▶sub paths_to { push @_, _p; goto &_paths_fromto }
Subroutine paths_to: called CC=1 SCAR=0.0
Pod documented
380  
381 234 ▶sub _cessors {
Subroutine _cessors: called CC=3 SCAR=11.1
382 234 my $offset = pop;
383 234 my ($map_x, @v) = ( @{ $_[0] }[ $offset ], @_[1..$#_] );
384 234 ▶ Graph::__carp_confess("undefined vertex") if grep !defined, @v;
Branch: 1 branch
BranchTrueFalseTotal
if grep((!defined($_)), @v) 0 234 234
385 234 require Set::Object;
386 234 ▶ Set::Object->new(map keys %{ $map_x->{ $_ } || _empty }, @v)->members;
Condition66%2/3
$map_x->{$_} || &_empty()
l!l&&r!l&&!r
179610
MC/DC0%0/2
$map_x->{$_} || &_empty()
$map_x->{$_} &_empty()
Truth table66%2/3
A || B
A= $map_x->{$_}B= &_empty()
ABresult
1X1
011
000
387 }
388 169 ▶sub successors { push @_, _s; goto &_cessors }
Subroutine successors: called CC=1 SCAR=0.0
Pod documented
389 65 ▶sub predecessors { push @_, _p; goto &_cessors }
Subroutine predecessors: called CC=1 SCAR=0.0
Pod documented
390  
391 72 ▶sub has_successor {
Subroutine has_successor: called CC=3 SCAR=11.2
Pod documented
392 72 my ($map_s, $u, $v) = ( @{ $_[0] }[ _s ], @_[1, 2] );
393 72 ▶ Graph::__carp_confess("undefined vertex") if grep !defined, $u, $v;
Branch: 1 branch
BranchTrueFalseTotal
if grep((!defined($_)), $u, $v) 0 72 72
394 72 ▶ exists ${ $map_s->{ $u } || _empty }{ $v };
Condition66%2/3
$map_s->{$u} || &_empty()
l!l&&r!l&&!r
54180
MC/DC0%0/2
$map_s->{$u} || &_empty()
$map_s->{$u} &_empty()
Truth table66%2/3
A || B
A= $map_s->{$u}B= &_empty()
ABresult
1X1
011
000
395 }
396  
397 2151 ▶sub __strval {
Subroutine __strval: called CC=4 SCAR=14.5
398 2151 my ($k, $f) = @_;
399 2151 ▶ return $k unless ref $k && ($f & _REF);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $k and $f & 8 0 2151 2151
Condition33%1/3
ref $k and $f & 8
!ll&&!rl&&r
002151
MC/DC0%0/2
ref $k and $f & 8
ref $k $f & 8
Truth table33%1/3
A and B
A= ref $kB= $f & 8
ABresult
0X0
100
111
400 2151 ▶ return "$k" if ($f & _STR);
Branch: 1 branch
BranchTrueFalseTotal
if $f & 64 4 2147 2151
401 2147 require Scalar::Util;
402 2147 Scalar::Util::refaddr($k);
403 }
404  
405 3623 ▶sub __arg {
Subroutine __arg: called CC=3 SCAR=11.4
406 3623 my ($f, $a, $m, $k) = (@{ $_[0] }[ _f, _arity ], @_[0, 1]);
407 3623 ▶ Graph::__carp_confess(sprintf "arguments %d (%s) expected %d for\n".$m->stringify,
Branch: 1 branch
BranchTrueFalseTotal
if $a > 1 and @$k != $a 0 3623 3623
Condition66%2/3
$a > 1 and @$k != $a
!ll&&!rl&&r
220414190
MC/DC0%0/2
$a > 1 and @$k != $a
$a > 1 @$k != $a
Truth table66%2/3
A and B
A= $a > 1B= @$k != $a
ABresult
0X0
100
111
408 scalar @$k, "@$k", $a)
409 if $a > 1 and @$k != $a;
410 }
411  
412 3 ▶sub reindex {
Subroutine reindex: called CC=6 SCAR=19.6
Pod documented
413 3 my ($f, $a, $i2p, $m) = (@{ $_[0] }[ _f, _arity, _i ], $_[0]);
414 3 ▶ my $is_ref = $a == 1 && ($f & _REF);
Condition33%1/3
$a == 1 && $f & 8
!ll&&!rl&&r
003
MC/DC0%0/2
$a == 1 && $f & 8
$a == 1 $f & 8
Truth table33%1/3
A && B
A= $a == 1B= $f & 8
ABresult
0X0
100
111
415 3 my $pi = $m->[ _pi ] = {};
416 3 for my $i ( 0..$#{ $i2p } ) {
417 4 ▶ next if !defined(my $k = $i2p->[ $i ]); # deleted
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $k = $i2p->[$i]) 0 4 4
418 4 ▶ $k = __strval($k, $f) if $is_ref && ref($k);
Branch: 1 branch
BranchTrueFalseTotal
if $is_ref and ref $k 4 0 4
Condition33%1/3
$is_ref and ref $k
!ll&&!rl&&r
004
MC/DC0%0/2
$is_ref and ref $k
$is_ref ref $k
Truth table33%1/3
A and B
A= $is_refB= ref $k
ABresult
0X0
100
111
419 4 $pi->{ $k } = $i;
420 }
421 }
422  
423 84 1;
424 __END__
« Graph/Traversal.pm ↑ Summary Graph/TransitiveClosure.pm »