PartialOrder/Base.pm

filter: Statementstmt 43.3% 231 / 533 Branchbran 34.5% 121 / 350 Conditioncond 35.2% 55 / 156 MC/DCmcdc 20.8% 19 / 91 Subroutinesub 40.4% 40 / 99 Podpod 80.8% 55 / 68 totaltotal 40.1% 521 / 1297 CC 254 SCAR 34.6
CC
254
Cov
39%
iterate_tracking
210.0
_get_strata_log
156.0
iterate
90.0
CRAP 31.7
« PartialOrder/Loader.pm ↑ Summary PartialOrder/Std.pm »
1 # -*- Mode: Perl -*-
2  
3 #
4 # Copyright (c) 2001, Bryan Jurish. All rights reserved.
5 #
6 # This package is free software. You may redistribute it
7 # and/or modify it under the same terms as Perl itself.
8 #
9  
10 ###############################################################
11 #
12 # File: Math::PartialOrder::Base.pm
13 # Author: Bryan Jurish <jurish@ling.uni-potsdam.de>
14 #
15 # Description: Abstract base class for partial orders
16 #
17 ###############################################################
18  
19 package Math::PartialOrder::Base;
20 # System modules
21 7 require 5.6.0; # for those handy 'our' variables...
22 7 ▶use Carp qw(:DEFAULT cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 7 require Exporter;
24 # 3rd party exstensions
25 # user extension modules
26 7 @ISA = qw(Exporter);
27 7 @EXPORT = qw();
28 7 @EXPORT_OK = (
29 qw(&_subsumes_trivial &_psubsumes_trivial),
30 qw(&_subsumes_user &_psubsumes_user),
31 qw(&_lub_trivial &_glb_trivial),
32 qw(&_binop_user &_lub_user &_glb_user),
33 qw($TYPE_NONE $TYPE_TOP),
34 );
35 7 %EXPORT_TAGS =
36 (
37 trivialities => [qw(&_subsumes_trivial &_psubsumes_trivial),
38 qw(&_lub_trivial &_glb_trivial)],
39 userhooks => [qw(&_subsumes_user &_psubsumes_user),
40 qw(&_binop_user &_lub_user &_glb_user)],
41 typevars => [qw($TYPE_TOP)]
42 );
43  
44 ###############################################################
45 # Package-global variables
46 ###############################################################
47 7 our $VERSION = 0.01;
48  
49 7 our $WANT_USER_HOOKS = 1;
50  
51 7 our $VERBOSE = 1;
52 7 our $TYPE_TOP = '__TOP__';
53 7 *TYPE_NONE = \$TYPE_TOP;
54  
55 ###############################################################
56 # Constructor
57 # + Hierarchy->new()
58 # + Hierarchy->new( att1 => val1, ..., attN => valN )
59 ###############################################################
60  
61 # $h->new(), $h->new(\%args)
62 0 ▶sub new ($;$) {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
63 0 my $proto = shift;
64 0 ▶ if (ref($proto)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $proto) 0 0 0
65 0 return bless %$proto, ref($proto);
66 }
67 0 ▶ my $self = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
68 0 bless $self, $proto;
69 0 ▶ $self->initialize(@_) if ($self->can('initialize'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("initialize") 0 0 0
70 0 return $self;
71 }
72  
73 5 ▶sub clone ($) {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
74 5 my $h = shift;
75 5 my $h2 = ref($h)->new();
76 5 $h2->assign($h);
77 5 return $h2;
78 }
79  
80 6 ▶sub compiled ($;$) { return 0; }
Subroutine compiled: called CC=1 SCAR=0.0
Pod documented
81  
82 3 ▶sub compile ($) { return 1; }
Subroutine compile: called CC=1 SCAR=0.0
Pod documented
83  
84  
85 ###############################################################
86 # Operations
87 # + most of these are not defined here, they're just wrappers
88 # for the functions we'll want
89 ###############################################################
90 0 ▶sub warn_abstract ($) {
Subroutine warn_abstract: not called CC=4 SCAR=30.0
Pod undocumented
91 0 ▶ if ($^W && $VERBOSE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^W and $VERBOSE) 0 0 0
Condition0%0/3
$^W and $VERBOSE
!ll&&!rl&&r
000
MC/DC0%0/2
$^W and $VERBOSE
$^W $VERBOSE
Truth table0%0/3
A and B
A= $^WB= $VERBOSE
ABresult
0X0
100
111
92 0 my $warn =
93 "Attempt to find non-existant method `$_[0]' via Math::PartialOrder::Base.\n"
94 ." > (Did you forget to implement an abstract method?)";
95 0 ▶ if ($VERBOSE > 1) { cluck($warn); }
Branch: 1 branch
BranchTrueFalseTotal
if ($VERBOSE > 1) { } 0 0 0
96 0 else { carp($warn); }
97 }
98 }
99  
100 ###############################################################
101 # Hierarchy Manipulation/Information
102 ###############################################################
103 0 ▶sub root ($;$) { warn_abstract('root'); }
Subroutine root: not called CC=1 SCAR=6.9
Pod documented
104 0 ▶sub add ($$@) { warn_abstract('add'); }
Subroutine add: not called CC=1 SCAR=6.9
Pod documented
105 0 ▶sub move ($$@) { warn_abstract('move'); }
Subroutine move: not called CC=1 SCAR=6.9
Pod documented
106 0 ▶sub remove ($@) { warn_abstract('remove'); }
Subroutine remove: not called CC=1 SCAR=6.9
Pod documented
107  
108 6 ▶sub add_parents ($$;@) {
Subroutine add_parents: called CC=1 SCAR=0.0
Pod documented
109 6 my ($self, $type, @parents) = @_;
110 return $self->move($type,
111 $self->parents($type),
112 6 grep { !$self->has_parent($type,$_) } @parents);
113 }
114 0 ▶sub replace ($$$) {
Subroutine replace: not called CC=2 SCAR=17.9
Pod documented
115 0 my ($h, $old, $new) = @_;
116 0 $h->add($new,$h->parents($old));
117 0 foreach ($h->children($old)) { $h->add_parents($_,$new); }
118 0 $h->remove($old);
119 0 return $h;
120 }
121  
122 528 ▶sub ensure_types ($@) {
Subroutine ensure_types: called CC=4 SCAR=13.9
Pod documented
123 528 my $self = shift;
124 528 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 505 23 528
125 505 foreach (@_) {
126 577 ▶ $self->add($_, $self->root) unless $self->has_type($_);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_type($_) 68 509 577
127 }
128 505 return @_;
129 }
130 23 return ($self->root);
131 }
132  
133 0 ▶sub clear ($) {
Subroutine clear: not called CC=1 SCAR=6.9
Pod documented
134 0 $_[0]->remove($_[0]->types);
135 0 %{$_[0]->_hattributes} = ();
136 }
137  
138 26 ▶sub assign ($$) {
Subroutine assign: called CC=4 SCAR=14.9
Pod documented
139 26 my ($h1,$h2) = @_;
140 26 $h1->clear();
141 26 $h1->replace($h1->root,$h2->root);
142 26 my ($t,$attrs,$newattrs);
143 26 foreach $t ($h2->types) {
144 187 $h1->add($t, $h2->parents($t));
145 187 $attrs = $h2->_attributes($t);
146 187 ▶ if (defined($attrs) && %$attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs and %$attrs) 0 187 187
Condition33%1/3
defined $attrs and %$attrs
!ll&&!rl&&r
18700
MC/DC0%0/2
defined $attrs and %$attrs
defined $attrs %$attrs
Truth table33%1/3
A and B
A= defined $attrsB= %$attrs
ABresult
0X0
100
111
147 0 $newattrs = {};
148 0 %$newattrs = %$attrs;
149 0 $h1->_attributes($t, $newattrs);
150 }
151 }
152 26 %{$h1->_hattributes} = %{$h2->_hattributes};
153 26 return $h1;
154 }
155  
156 # $h1->merge($h2,$h3,...)
157 25 ▶sub merge ($@) {
Subroutine merge: called CC=7 SCAR=20.3
Pod documented
158 25 my $h1 = shift;
159 25 my ($h2,$t,$attrs,$a,@parents);
160 25 ▶ while ($h2 = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h2 = shift()) 25 25 50
161 25 %{$h1->_hattributes} = (%{$h1->_hattributes}, %{$h2->_hattributes});
162 25 foreach $t ($h2->types) {
163 179 ▶ unless ($h1->has_type($t)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h1->has_type($t)) { } 179 0 179
164 # new type for $h1
165 0 $h1->add($t, $h2->parents($t));
166 } else {
167 # just add any parents this type didn't have before
168 179 @parents = grep { !$h1->has_parent($t,$_) } $h2->parents($t);
169 179 ▶ $h1->add_parents($t, @parents) if (@parents);
Branch: 1 branch
BranchTrueFalseTotal
if @parents 0 179 179
170 }
171 # merge attributes
172 179 $attrs = $h2->get_attributes($t);
173 179 ▶ if (defined($attrs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs) 0 179 179
174 0 foreach $a (keys(%$attrs)) {
175 0 $h1->set_attribute($t,$a,$h2->get_attribute($t,$a));
176 }
177 }
178 }
179 }
180 25 return $h1;
181 }
182  
183  
184  
185 ###############################################################
186 # Hierarchy Information
187 ###############################################################
188 56 ▶sub size ($) { return scalar($_[0]->types); }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
189 5 ▶sub leaves ($) { return grep { !$_[0]->children($_) } $_[0]->types(); }
Subroutine leaves: called CC=1 SCAR=0.0
Pod documented
190 0 ▶sub has_type ($$) {
Subroutine has_type: not called CC=2 SCAR=17.9
Pod documented
191 return
192 defined($_[1])
193 0 ? grep { $_ eq $_[1] } $_[0]->types()
194 0 ▶ : grep { !defined($_) } $_[0]->types();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
195 }
196 426 ▶sub has_types ($$@) {
Subroutine has_types: called CC=3 SCAR=11.0
Pod documented
197 426 my $h = shift;
198 426 foreach (@_) {
199 852 ▶ return '' unless ($h->has_type($_));
Branch: 1 branch
BranchTrueFalseTotal
unless $h->has_type($_) 4 848 852
200 }
201 422 return 1;
202 }
203  
204 0 ▶sub types ($) { warn_abstract('types'); }
Subroutine types: not called CC=1 SCAR=6.9
Pod documented
205  
206 60 ▶sub is_equal ($$) {
Subroutine is_equal: called CC=8 SCAR=20.8
Pod documented
207 60 my ($h1,$h2) = @_;
208 60 ▶ return 1 if ($h1 eq $h2); # object-equality
Branch: 1 branch
BranchTrueFalseTotal
if $h1 eq $h2 10 50 60
209 50 my (%alltypes, %allparents, $parent, $type);
210 50 @alltypes{($h1->types,
211 $h2->types)} = ($h1->types,
212 $h2->types);
213 50 foreach $type (values(%alltypes)) {
214 373 ▶ return 0 unless ($h1->has_type($type) && $h2->has_type($type));
Branch: 1 branch
BranchTrueFalseTotal
unless $h1->has_type($type) and $h2->has_type($type) 4 369 373
Condition66%2/3
$h1->has_type($type) and $h2->has_type($type)
!ll&&!rl&&r
04369
MC/DC50%1/2
$h1->has_type($type) and $h2->has_type($type)
$h1->has_type($type) $h2->has_type($type)
Truth table66%2/3
A and B
A= $h1->has_type($type)B= $h2->has_type($type)
ABresult
0X0
100
111
215 369 %allparents = ();
216 369 @allparents{($h1->parents($type),
217 $h2->parents($type))} = ($h1->parents($type),
218 $h2->parents($type));
219 369 foreach $parent (values(%allparents)) {
220 368 ▶ return 0 unless ($h1->has_parent($type, $parent) &&
Branch: 1 branch
BranchTrueFalseTotal
unless $h1->has_parent($type, $parent) and $h2->has_parent($type, $parent) 2 366 368
Condition66%2/3
$h1->has_parent($type, $parent) and $h2->has_parent($type, $parent)
!ll&&!rl&&r
02366
MC/DC50%1/2
$h1->has_parent($type, $parent) and $h2->has_parent($type, $parent)
$h1->has_parent($type, $parent) $h2->has_parent($type, $parent)
Truth table66%2/3
A and B
A= $h1->has_parent($type, $parent)B= $h2->has_parent($type, $parent)
ABresult
0X0
100
111
221 $h2->has_parent($type, $parent));
222 }
223 }
224 44 return 1;
225 }
226  
227 # $bool = $h->is_circular
228 # --iterative version
229 7 *is_circular = \&is_circular_iter;
230 7 *is_cyclic = \&is_circular_iter;
231 10 ▶sub is_circular_iter ($) {
Subroutine is_circular_iter: called CC=1 SCAR=0.0
Pod undocumented
232 return
233 10 $_[0]->iterate_strata($_[0]->can('children'),
234 \&_is_circular_callback,
235 {size=>$_[0]->size, return=>''});
236 }
237 50 ▶sub _is_circular_callback ($$$) {
Subroutine _is_circular_callback: called CC=2 SCAR=6.9
238 50 ▶ return 1 if ($_[2]->{step} > $_[2]->{size});
Branch: 1 branch
BranchTrueFalseTotal
if $_[2]{"step"} > $_[2]{"size"} 5 45 50
239 45 return undef;
240 }
241 # --logical version : assumes non-iterative has_ancestor...
242 #*is_circular = \&is_circular_log;
243 0 ▶sub is_circular_log ($) {
Subroutine is_circular_log: not called CC=3 SCAR=24.8
Pod undocumented
244 0 ▶ foreach ($_[0]->types) { return 1 if ($_[0]->has_ancestor($_,$_)); }
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->has_ancestor($_, $_) 0 0 0
245 0 return '';
246 }
247  
248 # $bool = $h->is_deterministic
249 10 ▶sub is_deterministic ($) { return !$_[0]->get_nondet_pair; }
Subroutine is_deterministic: called CC=1 SCAR=0.0
Pod documented
250 # ($t1,$t2) = $h->get_nondet_pair
251 10 ▶sub get_nondet_pair ($) {
Subroutine get_nondet_pair: called CC=5 SCAR=16.1
Pod documented
252 10 my $h = shift;
253 10 my @types = $h->types;
254 10 my (@lubs,$i,$j);
255 10 ▶ for ($i = 0; $i <= $#types; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#types) 30 5 35
256 30 ▶ for ($j = $i+1; $j <= $#types; ++$j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#types) 57 25 82
257 57 @lubs = $h->_lub($types[$i],$types[$j]);
258 57 ▶ return (@types[$i,$j]) if (@lubs && scalar(@lubs) > 1);
Branch: 1 branch
BranchTrueFalseTotal
if @lubs and scalar @lubs > 1 5 52 57
Condition100%3/3
@lubs and scalar @lubs > 1
!ll&&!rl&&r
17355
MC/DC100%2/2
@lubs and scalar @lubs > 1
@lubs scalar @lubs > 1
Truth table100%3/3
A and B
A= @lubsB= scalar @lubs > 1
ABresult
0X0
100
111
259 }
260 }
261 5 return qw();
262 }
263  
264 # $bool = $h->is_treelike
265 10 ▶sub is_treelike ($) { return !defined($_[0]->get_multiparent_type); }
Subroutine is_treelike: called CC=1 SCAR=0.0
Pod undocumented
266 # $type = $h->get_multiparent_type
267 10 ▶sub get_multiparent_type ($) {
Subroutine get_multiparent_type: called CC=3 SCAR=11.0
Pod documented
268 10 my $h = shift;
269 10 foreach ($h->types) {
270 32 ▶ return $_ if (scalar(@{[ $h->parents($_) ]}) > 1);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{[$h->parents($_)];} > 1 5 27 32
271 }
272 5 return undef;
273 }
274  
275  
276 0 ▶sub parents ($$) { warn_abstract('parents'); }
Subroutine parents: not called CC=1 SCAR=6.9
Pod documented
277 0 ▶sub children ($$) { warn_abstract('children'); }
Subroutine children: not called CC=1 SCAR=6.9
Pod documented
278  
279 0 ▶sub ancestors ($$) {
Subroutine ancestors: not called CC=1 SCAR=6.9
Pod documented
280 0 return @{$_[0]->iterate_cp_step
281 (\&_ancestors_callback, { start => $_[1], return => [] })};
282 }
283 # callback($h,$t,$args)
284 0 ▶sub _ancestors_callback ($$$) {
Subroutine _ancestors_callback: not called CC=1 SCAR=6.9
285 0 push(@{$_[2]->{return}}, $_[0]->parents($_[1]));
286 0 return undef;
287 }
288 0 ▶sub descendants ($$) {
Subroutine descendants: not called CC=1 SCAR=6.9
Pod documented
289 0 return @{$_[0]->iterate_pc_step
290 (\&_descendants_callback,
291 { start => $_[1], return => [] })};
292 }
293 # callback($h,$t,$args)
294 0 ▶sub _descendants_callback ($$$) {
Subroutine _descendants_callback: not called CC=1 SCAR=6.9
295 0 push(@{$_[2]->{return}}, $_[0]->children($_[1]));
296 0 return undef;
297 }
298  
299 # $h->has_parent($t,$p)
300 0 ▶sub has_parent ($$$) {
Subroutine has_parent: not called CC=2 SCAR=17.9
Pod documented
301 return
302 ($_[0]->has_types($_[1],$_[2])
303 and
304 0 ▶ grep { $_ eq $_[2] } $_[0]->parents($_[1]));
Condition0%0/3
$_[0]->has_types($_[1], $_[2]) && grep({$_ eq $_[2];} $_[0]->parents($_[1]))
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0]->has_types($_[1], $_[2]) && grep({$_ eq $_[2];} $_[0]->parents($_[1]))
$_[0]->has_types($_[1], $_[2]) grep({$_ eq $_[2];} $_[0]->parents($_[1]))
Truth table0%0/3
A && B
A= $_[0]->has_types($_[1], $_[2])B= grep({$_ eq $_[2];} $_[0]->parents($_[1]))
ABresult
0X0
100
111
305 }
306 # $h->has_child($t,$p)
307 0 ▶sub has_child ($$$) {
Subroutine has_child: not called CC=2 SCAR=17.9
Pod documented
308 ($_[0]->has_types($_[1],$_[2])
309 and
310 0 ▶ grep { $_ eq $_[2] } $_[0]->children($_[1]));
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->has_types($_[1], $_[2]) and grep {$_ eq $_[2];} $_[0]->children($_[1]) 0 0 0
311 }
312  
313 18 ▶sub has_ancestor ($$$) {
Subroutine has_ancestor: called CC=5 SCAR=21.9
Pod documented
314 return
315 18 ▶ defined($_[1]) && defined($_[2]) &&
Condition41%5/12
defined $_[1] && defined $_[2] && $_[0]->has_type($_[1]) && $_[0]->has_type($_[2]) && $_[0]->iterate_cp_step(\&_type_search_callback, {'start', [$_[0]->parents($_[1])], 'find', $_[2], 'return', ''})
!ll&&!rl&&r
099
defined $_[1] and defined $_[2] and $_[0]->has_type($_[1]) and $_[0]->has_type($_[2])
!ll&&!rl&&r
0018
defined $_[1] and defined $_[2] and $_[0]->has_type($_[1])
!ll&&!rl&&r
0018
defined $_[1] and defined $_[2]
!ll&&!rl&&r
0018
MC/DC20%1/5
defined $_[1] && defined $_[2] && $_[0]->has_type($_[1]) && $_[0]->has_type($_[2]) && $_[0]->iterate_cp_step(\&_type_search_callback, {'start', [$_[0]->parents($_[1])], 'find', $_[2], 'return', ''})
defined $_[1] defined $_[2] $_[0]->has_type($_[1]) $_[0]->has_type($_[2]) $_[0]->iterate_cp_step(\&_type_search_callback, {'start', [$_[0]->parents($_[1])], 'find', $_[2], 'return', ''})
Truth table33%2/6
A and B and C and D && E
A= defined $_[1]B= defined $_[2]C= $_[0]->has_type($_[1])D= $_[0]->has_type($_[2])E= $_[0]->iterate_cp_step(\&_type_search_callback, {'start', [$_[0]->parents($_[1])], 'find', $_[2], 'return', ''})
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
316 $_[0]->has_type($_[1]) &&
317 $_[0]->has_type($_[2]) &&
318 $_[0]->iterate_cp_step(\&_type_search_callback,
319 {
320 start => [$_[0]->parents($_[1])],
321 find => $_[2],
322 return => ''
323 });
324 }
325 # callback($h,$t,$args)
326 66 ▶sub _type_search_callback ($$$) {
Subroutine _type_search_callback: called CC=2 SCAR=6.9
327 66 ▶ return $_[2]->{find} eq $_[1] ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$_[2]{'find'} eq $_[1] ? : 9 57 66
328 }
329  
330 1 ▶sub has_descendant ($$$) { return $_[0]->has_ancestor($_[2],$_[1]); }
Subroutine has_descendant: called CC=1 SCAR=0.0
Pod documented
331  
332 # comparison aliases
333 7 *le = \&subsumes;
334 7 *lt = \&psubsumes;
335 7 *ge = \&extends;
336 7 *gt = \&pextends;
337 7 *cmp = \&compare;
338  
339 0 ▶sub extends ($$$) { return $_[0]->subsumes($_[2],$_[1]); }
Subroutine extends: not called CC=1 SCAR=6.9
Pod documented
340  
341 7 *properly_extends = \&pextends;
342 0 ▶sub pextends ($$$) { return $_[0]->psubsumes($_[2],$_[1]); }
Subroutine pextends: not called CC=1 SCAR=6.9
Pod undocumented
343  
344 45 ▶sub subsumes ($$$) {
Subroutine subsumes: called CC=6 SCAR=18.1
Pod documented
345 45 my ($a);
346 return
347 # easy answers
348 45 ▶ (defined($a = _subsumes_trivial($_[1],$_[2]))
Branch: 2 branches
BranchTrueFalseTotal
defined($a = &_subsumes_trivial($_[1], $_[2])) ? : 20 25 45
$WANT_USER_HOOKS && defined($a = &_subsumes_user($_[1], $_[2])) ? : 10 15 25
Condition77%7/9
$WANT_USER_HOOKS and defined($a = &_subsumes_user($_[1], $_[2]))
!ll&&!rl&&r
01510
ref $_[0] and $_[0]->has_types($_[1], $_[2]) and $_[0]->has_ancestor($_[2], $_[1])
!ll&&!rl&&r
555
ref $_[0] and $_[0]->has_types($_[1], $_[2])
!ll&&!rl&&r
0510
MC/DC50%1/2
$WANT_USER_HOOKS and defined($a = &_subsumes_user($_[1], $_[2]))
$WANT_USER_HOOKS defined($a = &_subsumes_user($_[1], $_[2]))
MC/DC66%2/3
ref $_[0] and $_[0]->has_types($_[1], $_[2]) and $_[0]->has_ancestor($_[2], $_[1])
ref $_[0] $_[0]->has_types($_[1], $_[2]) $_[0]->has_ancestor($_[2], $_[1])
Truth table66%2/3
A and B
A= $WANT_USER_HOOKSB= defined($a = &_subsumes_user($_[1], $_[2]))
ABresult
0X0
100
111
Truth table75%3/4
A and B and C
A= ref $_[0]B= $_[0]->has_types($_[1], $_[2])C= $_[0]->has_ancestor($_[2], $_[1])
ABCresult
0XX0
10X0
1100
1111
349 ? $a
350 # user-defined subsumption
351 : ($WANT_USER_HOOKS && defined($a = _subsumes_user($_[1],$_[2]))
352 ? $a
353 # consult hierarchy (if we can)
354 : (ref($_[0])
355 and $_[0]->has_types($_[1],$_[2])
356 and $_[0]->has_ancestor($_[2],$_[1]))));
357 }
358  
359 45 ▶sub _subsumes_trivial ($$) {
Subroutine _subsumes_trivial: called CC=6 SCAR=18.3
360 return
361 (# undef subsumes everything
362 45 ▶ !defined($_[0]) ? 1
Branch: 5 branches
BranchTrueFalseTotal
!defined($_[0]) ? : 5 40 45
!defined($_[1]) ? : 10 30 40
$_[0] eq $_[1] ? : 5 25 30
$_[1] eq $TYPE_TOP ? : 0 25 25
$_[0] eq $TYPE_TOP ? : 0 25 25
363 : (# nothing else subsumes undef
364 !defined($_[1]) ? 0
365 : (# object-identity counts as subsumption
366 $_[0] eq $_[1] ? 1
367 : (# everything subsumes $TYPE_TOP
368 $_[1] eq $TYPE_TOP ? 1
369 : (# nothing else subsumes $TYPE_TOP
370 $_[0] eq $TYPE_TOP ? 0
371 : # ... can't do it the easy way
372 undef)))));
373 }
374  
375 # _subsumes_user($t1,$t2)
376 # user-defined subsumption
377 25 ▶sub _subsumes_user ($$) {
Subroutine _subsumes_user: called CC=4 SCAR=14.3
378 return
379 (# object-oriented user-defined subsumption
380 UNIVERSAL::can($_[0], 'subsumes')
381 ? (1,$_[0]->subsumes($_[1]))
382 : (# functional user-defined subsumption
383 ref($_[0]) && ref($_[0]) eq 'CODE'
384 25 ▶ ? &{$_[0]}('subsumes',$_[1])
Branch: 2 branches
BranchTrueFalseTotal
UNIVERSAL::can($_[0], 'subsumes') ? : 0 25 25
ref $_[0] && ref $_[0] eq 'CODE' ? : 10 15 25
Condition66%2/3
ref $_[0] and ref $_[0] eq "CODE"
!ll&&!rl&&r
15010
MC/DC50%1/2
ref $_[0] and ref $_[0] eq "CODE"
ref $_[0] ref $_[0] eq "CODE"
Truth table66%2/3
A and B
A= ref $_[0]B= ref $_[0] eq "CODE"
ABresult
0X0
100
111
385 : # ... nope
386 undef));
387 }
388  
389  
390 7 *properly_subsumes = \&psubsumes;
391 0 ▶sub psubsumes ($$$) {
Subroutine psubsumes: not called CC=6 SCAR=37.4
Pod undocumented
392 0 my ($ans);
393 return
394 (# easy answers
395 0 ▶ defined($ans = _psubsumes_trivial($_[1],$_[2])) ? $ans
Branch: 2 branches
BranchTrueFalseTotal
defined($ans = &_psubsumes_trivial($_[1], $_[2])) ? : 0 0 0
$WANT_USER_HOOKS && defined($ans = &_psubsumes_user($_[1], $_[2])) ? : 0 0 0
Condition0%0/9
$WANT_USER_HOOKS and defined($ans = &_psubsumes_user($_[1], $_[2]))
!ll&&!rl&&r
000
ref $_[0] and $_[0]->has_types($_[1], $_[2]) and $_[0]->has_ancestor($_[2], $_[1])
!ll&&!rl&&r
000
ref $_[0] and $_[0]->has_types($_[1], $_[2])
!ll&&!rl&&r
000
MC/DC0%0/2
$WANT_USER_HOOKS and defined($ans = &_psubsumes_user($_[1], $_[2]))
$WANT_USER_HOOKS defined($ans = &_psubsumes_user($_[1], $_[2]))
MC/DC0%0/3
ref $_[0] and $_[0]->has_types($_[1], $_[2]) and $_[0]->has_ancestor($_[2], $_[1])
ref $_[0] $_[0]->has_types($_[1], $_[2]) $_[0]->has_ancestor($_[2], $_[1])
Truth table0%0/3
A and B
A= $WANT_USER_HOOKSB= defined($ans = &_psubsumes_user($_[1], $_[2]))
ABresult
0X0
100
111
Truth table0%0/4
A and B and C
A= ref $_[0]B= $_[0]->has_types($_[1], $_[2])C= $_[0]->has_ancestor($_[2], $_[1])
ABCresult
0XX0
10X0
1100
1111
396 : (# user-defined subsumption
397 $WANT_USER_HOOKS && defined($ans = _psubsumes_user($_[1],$_[2])) ? $ans
398 : (# consult hierarchy
399 ref($_[0])
400 and $_[0]->has_types($_[1],$_[2])
401 and $_[0]->has_ancestor($_[2],$_[1]))));
402 }
403 7 *_properly_subsumes_trivial = \&_psubsumes_trivial;
404 0 ▶sub _psubsumes_trivial ($$) {
Subroutine _psubsumes_trivial: not called CC=7 SCAR=40.3
405 return
406 0 ▶ (defined($_[0])
Branch: 6 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
!defined($_[1]) ? : 0 0 0
$_[0] eq $TYPE_TOP ? : 0 0 0
$_[1] eq $TYPE_TOP ? : 0 0 0
$_[0] eq $_[1] ? : 0 0 0
defined $_[1] ? : 0 0 0
407 ? (# nothing defined p-subsumes undef
408 !defined($_[1]) ? 0
409 : (# TOP p-subsumes nothing
410 $_[0] eq $TYPE_TOP ? 0
411 : (# everything else p-subsumes TOP
412 $_[1] eq $TYPE_TOP ? 1
413 : (# nothing p-subsumes itself
414 $_[0] eq $_[1] ? 0
415 : # ... can't do it this way
416 undef))))
417 : (# undef subsumes all and only defined values
418 defined($_[1]) ? 1 : 0));
419 }
420  
421 # non-method: _psubsumes_user($t1,$t2)
422 0 ▶sub _psubsumes_user ($$) {
Subroutine _psubsumes_user: not called CC=4 SCAR=30.0
423 return
424 (# object-oriented user-defined proper subsumption
425 UNIVERSAL::can($_[0], 'properly_subsumes')
426 ? $_[0]->properly_subsumes($_[1])
427 : (# functional user-defined p-subsumption
428 ref($_[0]) && ref($_[0]) eq 'CODE'
429 0 ▶ ? &{$_[0]}('properly_subsumes',$_[1])
Branch: 2 branches
BranchTrueFalseTotal
UNIVERSAL::can($_[0], 'properly_subsumes') ? : 0 0 0
ref $_[0] && ref $_[0] eq 'CODE' ? : 0 0 0
Condition0%0/3
ref $_[0] and ref $_[0] eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and ref $_[0] eq "CODE"
ref $_[0] ref $_[0] eq "CODE"
Truth table0%0/3
A and B
A= ref $_[0]B= ref $_[0] eq "CODE"
ABresult
0X0
100
111
430 # nope
431 : undef));
432 }
433 7 *_properly_subsumes = \&_psubsumes;
434 0 ▶sub _psubsumes ($$$) {
Subroutine _psubsumes: not called CC=1 SCAR=6.9
435 return
436 # check hierarchy structure
437 0 $_[0]->has_ancestor($_[2],$_[1]);
438 }
439  
440  
441  
442 #####################################################################
443 # Sorting/Comparison
444 #####################################################################
445 0 ▶sub compare ($$$) {
Subroutine compare: not called CC=8 SCAR=42.8
Pod documented
446 0 ▶ return 0 if (# object-equality is easy
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] and defined $_[2] and $_[1] eq $_[2] or not defined $_[1] || defined $_[2] 0 0 0
Condition0%0/12
defined $_[1] and defined $_[2] and $_[1] eq $_[2] or not defined $_[1] || defined $_[2]
l!l&&r!l&&!r
000
defined $_[1] and defined $_[2] and $_[1] eq $_[2]
!ll&&!rl&&r
000
defined $_[1] and defined $_[2]
!ll&&!rl&&r
000
defined $_[1] || defined $_[2]
l!l&&r!l&&!r
000
MC/DC0%0/5
defined $_[1] and defined $_[2] and $_[1] eq $_[2] or not defined $_[1] || defined $_[2]
defined $_[1] defined $_[2] $_[1] eq $_[2] defined $_[1] defined $_[2]
Truth table0%0/10
A and B and C or not(D || E)
A= defined $_[1]B= defined $_[2]C= $_[1] eq $_[2]D= defined $_[1]E= defined $_[2]
ABCDEresult
111XX1
0XX001
10X001
110001
0XX1X0
0XX010
10X1X0
10X010
1101X0
110010
447 (defined($_[1]) and defined($_[2]) and $_[1] eq $_[2])
448 or
449 # so is undef
450 (!defined($_[1]) and !defined($_[2])));
451 0 ▶ return -1 if ($_[0]->properly_subsumes($_[1],$_[2]));
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->properly_subsumes($_[1], $_[2]) 0 0 0
452 0 ▶ return 1 if ($_[0]->properly_subsumes($_[2],$_[1]));
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->properly_subsumes($_[2], $_[1]) 0 0 0
453 0 return undef; # incomparable
454 }
455 6 ▶sub _compare ($$$) {
Subroutine _compare: called CC=9 SCAR=25.5
456 6 ▶ return undef unless ($_[0]->has_types($_[1],$_[2])); # sanity check
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->has_types($_[1], $_[2]) 0 6 6
457 6 ▶ return 0 if (# object-equality is easy
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] and defined $_[2] and $_[1] eq $_[2] or not defined $_[1] || defined $_[2] 3 3 6
Condition50%6/12
defined $_[1] and defined $_[2] and $_[1] eq $_[2] or not defined $_[1] || defined $_[2]
l!l&&r!l&&!r
303
defined $_[1] and defined $_[2] and $_[1] eq $_[2]
!ll&&!rl&&r
033
defined $_[1] and defined $_[2]
!ll&&!rl&&r
006
defined $_[1] || defined $_[2]
l!l&&r!l&&!r
300
MC/DC20%1/5
defined $_[1] and defined $_[2] and $_[1] eq $_[2] or not defined $_[1] || defined $_[2]
defined $_[1] defined $_[2] $_[1] eq $_[2] defined $_[1] defined $_[2]
Truth table20%2/10
A and B and C or not(D || E)
A= defined $_[1]B= defined $_[2]C= $_[1] eq $_[2]D= defined $_[1]E= defined $_[2]
ABCDEresult
111XX1
0XX001
10X001
110001
0XX1X0
0XX010
10X1X0
10X010
1101X0
110010
458 (defined($_[1]) and defined($_[2]) and $_[1] eq $_[2])
459 or
460 # so is undef
461 (!defined($_[1]) and !defined($_[2])));
462 3 ▶ return 1 if ($_[0]->has_ancestor($_[1],$_[2]));
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->has_ancestor($_[1], $_[2]) 0 3 3
463 3 ▶ return -1 if ($_[0]->has_ancestor($_[2],$_[1]));
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->has_ancestor($_[2], $_[1]) 0 3 3
464 3 return undef; # incomparable
465 }
466  
467  
468 # @min = $h->min(@types)
469 0 ▶sub min ($@) {
Subroutine min: not called CC=4 SCAR=30.0
Pod documented
470 0 my $self = shift;
471 0 my ($t1,$t2,@results);
472 MIN_T1:
473 0 foreach $t1 (@_) {
474 0 foreach $t2 (@_) {
475 #next unless ($self->has_type($t1)); # sanity check -- not needed with 'extends'
476 0 ▶ next MIN_T1 if ($self->properly_extends($t1,$t2));
Branch: 1 branch
BranchTrueFalseTotal
if $self->properly_extends($t1, $t2) 0 0 0
477 }
478 0 push(@results,$t1);
479 }
480 0 return @results;
481 }
482 # @max = $h->max(@types)
483 0 ▶sub max ($@) {
Subroutine max: not called CC=4 SCAR=30.0
Pod documented
484 0 my $self = shift;
485 0 my ($t1,$t2,@results);
486 MAX_T1:
487 0 foreach $t1 (@_) {
488 #next unless ($self->has_type($t1)); # sanity check -- not needed w/ 'subsumes'
489 0 foreach $t2 (@_) {
490 0 ▶ next MAX_T1 if ($self->properly_subsumes($t1,$t2));
Branch: 1 branch
BranchTrueFalseTotal
if $self->properly_subsumes($t1, $t2) 0 0 0
491 }
492 0 push(@results,$t1);
493 }
494 0 return @results;
495 }
496  
497  
498  
499 # @min = $h->min_extending($base,@types)
500 # (logical version)
501 7 *min_extending = \&_min_extending_log;
502 0 ▶sub _min_extending_log ($$@) {
Subroutine _min_extending_log: not called CC=1 SCAR=6.9
503 0 my $h = shift;
504 0 my $base = shift;
505 0 return $h->min(grep { $h->extends($_,$base) } @_);
506 }
507  
508 # @max = $h->max_subsuming($base,@types)
509 # (logical version)
510 7 *max_subsuming = \&_max_subsuming_log;
511 0 ▶sub _max_subsuming_log ($$@) {
Subroutine _max_subsuming_log: not called CC=1 SCAR=6.9
512 0 my $h = shift;
513 0 my $base = shift;
514 0 return $h->max(grep { $h->subsumes($_,$base) } @_);
515 }
516  
517  
518 # --- iterative version
519 7 *subsort = \&_subsort_it;
520 0 ▶sub _subsort_it ($@) {
Subroutine _subsort_it: not called CC=1 SCAR=6.9
521 0 my $h = shift;
522 0 my %find = map { $_ => $_ } @_;
523 0 my %found = ();
524 0 my %found2step = ();
525 0 $h->iterate_strata($h->can('children'),
526 \&_subsort_callback,
527 {
528 find => \%find,
529 found => \%found,
530 found2step => \%found2step,
531 maxstep => $h->size,
532 });
533 return
534 0 @found{sort { $found2step{$a} <=> $found2step{$b} } keys(%found)},
535 values(%find);
536 }
537 # callback($hi,$type,$args)
538 0 ▶sub _subsort_callback ($$$) {
Subroutine _subsort_callback: not called CC=4 SCAR=30.0
539 0 ▶ return '' if ($_[2]->{step} > $_[2]->{maxstep});
Branch: 1 branch
BranchTrueFalseTotal
if $_[2]{"step"} > $_[2]{"maxstep"} 0 0 0
540 0 ▶ if (exists($_[2]->{find}{$_[1]})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $_[2]{'find'}{$_[1]}) { } 0 0 0
elsif (exists $_[2]{'found'}{$_[1]}) { } 0 0 0
541 0 $_[2]->{found2step}{$_[1]} = $_[2]->{step};
542 0 $_[2]->{found}{$_[1]} = $_[1];
543 0 delete($_[2]->{find}{$_[1]});
544 } elsif (exists($_[2]->{found}{$_[1]})) {
545 0 $_[2]->{found2step}{$_[1]} = $_[2]->{step};
546 }
547 0 return undef;
548 }
549  
550 # logical version -- nice if we've got a fast 'has_ancestor'
551 #*subsort = \&_subsort_log;
552 0 ▶sub _subsort_log ($@) {
Subroutine _subsort_log: not called CC=5 SCAR=34.0
553 0 my $h = shift;
554 0 my ($i,$j,$cmp);
555 0 ▶ for ($i = 0; $i < $#_; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#_) 0 0 0
556 0 ▶ for ($j = $i+1; $j <= $#_; ++$j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#_) 0 0 0
557 0 $cmp = $h->compare($_[$i],$_[$j]);
558 0 ▶ next if (!$cmp || $cmp < 0);
Branch: 1 branch
BranchTrueFalseTotal
if not $cmp or $cmp < 0 0 0 0
Condition0%0/3
not $cmp or $cmp < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not $cmp or $cmp < 0
not $cmp $cmp < 0
Truth table0%0/3
not(A) or B
A= not $cmpB= $cmp < 0
ABresult
1X1
011
000
559 0 @_[$i,$j] = @_[$j,$i];
560 }
561 }
562 0 return @_;
563 }
564  
565  
566 0 ▶sub stratasort ($@) {
Subroutine stratasort: not called CC=7 SCAR=40.3
Pod documented
567 0 my $h = shift;
568 0 ▶ my %find = map { defined($_) ? ($_ => $_) : qw() } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
569 0 my $stratah = $h->get_strata(@_);
570 0 my @strata = ();
571 0 my $last = [];
572 0 foreach (@_) {
573 0 ▶ if (defined($_) && exists($stratah->{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_ and exists $stratah->{$_}) { } 0 0 0
Condition0%0/3
defined $_ and exists $stratah->{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and exists $stratah->{$_}
defined $_ exists $stratah->{$_}
Truth table0%0/3
A and B
A= defined $_B= exists $stratah->{$_}
ABresult
0X0
100
111
574 0 ▶ unless (exists($strata[$stratah->{$_}])) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $strata[$stratah->{$_}]) { } 0 0 0
575 0 $strata[$stratah->{$_}] = [$_];
576 } else {
577 0 push(@{$strata[$stratah->{$_}]}, $_);
578 }
579 } else {
580 0 push(@$last, $_);
581 }
582 }
583 0 ▶ push(@strata, $last) if (@$last);
Branch: 1 branch
BranchTrueFalseTotal
if @$last 0 0 0
584 0 return grep { $_ } @strata;
585 }
586  
587  
588 # iterative version
589 7 *get_strata = \&_get_strata_it;
590 0 ▶sub _get_strata_it ($@) {
Subroutine _get_strata_it: not called CC=1 SCAR=6.9
591 return
592 0 $_[0]->iterate_strata
593 ($_[0]->can('children'),
594 \&_get_strata_callback,
595 {
596 maxstrat => scalar($_[0]->types),
597 laststep => {},
598 return => {},
599 });
600 }
601 # callback($h,$type,$args)
602 0 ▶sub _get_strata_callback ($$$) {
Subroutine _get_strata_callback: not called CC=4 SCAR=30.0
603 # circular hierarchy -- bail out
604 0 ▶ return $_[2]->{return} if ($_[2]->{step} >= $_[2]->{maxstrat});
Branch: 1 branch
BranchTrueFalseTotal
if $_[2]{"step"} >= $_[2]{"maxstrat"} 0 0 0
605  
606 0 ▶ if (!exists($_[2]->{laststep}{$_[1]}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $_[2]{"laststep"}{$_[1]} or $_[2]{"laststep"}{$_[1]} < $_[2]{"step"}) 0 0 0
Condition0%0/3
not exists $_[2]{"laststep"}{$_[1]} or $_[2]{"laststep"}{$_[1]} < $_[2]{"step"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $_[2]{"laststep"}{$_[1]} or $_[2]{"laststep"}{$_[1]} < $_[2]{"step"}
not exists $_[2]{"laststep"}{$_[1]} $_[2]{"laststep"}{$_[1]} < $_[2]{"step"}
Truth table0%0/3
not(A) or B
A= not exists $_[2]{"laststep"}{$_[1]}B= $_[2]{"laststep"}{$_[1]} < $_[2]{"step"}
ABresult
1X1
011
000
607 $_[2]->{laststep}{$_[1]} < $_[2]->{step})
608 {
609 # ... we need to move it to this virtual step-stratum
610 0 $_[2]->{return}{$_[1]} = $_[2]->{step};
611 }
612  
613 0 $_[2]->{laststep}{$_[1]} = $_[2]->{step}; # keep this for *all* types
614 0 return undef;
615 }
616  
617 # --- assumes we have a fast has_ancestor()
618 # : pretty but slow
619 #*get_strata = \&_get_strata_log;
620 0 ▶sub _get_strata_log ($@) {
Subroutine _get_strata_log: not called CC=12 SCAR=50.5
621 0 my $h = shift;
622 0 my @types = grep { $h->has_type($_) } @_;
623 0 my %strata = ( map { $_ => 0 } @types );
624 0 my ($cmp,$i,$j);
625 0 my $changed = 1;
626 0 my $step = 1;
627  
628 0 ▶ while ($changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed) 0 0 0
629 0 ▶ last if ($step > scalar(@_));
Branch: 1 branch
BranchTrueFalseTotal
if $step > scalar @_ 0 0 0
630 0 $changed = 0;
631  
632 0 ▶ for ($i = 0; $i < $#types; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#types) 0 0 0
633 0 ▶ next unless ($h->has_type($types[$i]));
Branch: 1 branch
BranchTrueFalseTotal
unless $h->has_type($types[$i]) 0 0 0
634  
635 0 ▶ for ($j = $i+1; $j <= $#types; ++$j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#types) 0 0 0
636 0 ▶ next unless ($h->has_type($types[$j]));
Branch: 1 branch
BranchTrueFalseTotal
unless $h->has_type($types[$j]) 0 0 0
637  
638 0 $cmp = $h->_compare($types[$i],$types[$j]);
639 0 ▶ next unless ($cmp);
Branch: 1 branch
BranchTrueFalseTotal
unless $cmp 0 0 0
640  
641 0 ▶ if ($cmp < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp < 0) { } 0 0 0
elsif ($cmp > 0) { } 0 0 0
642 0 ▶ next if ($strata{$types[$i]} < $strata{$types[$j]});
Branch: 1 branch
BranchTrueFalseTotal
if $strata{$types[$i]} < $strata{$types[$j]} 0 0 0
643 0 $changed = 1;
644 0 $strata{$types[$j]} = $strata{$types[$i]} + 1;
645 }
646 elsif ($cmp > 0) {
647 0 ▶ next if ($strata{$types[$i]} > $strata{$types[$j]});
Branch: 1 branch
BranchTrueFalseTotal
if $strata{$types[$i]} > $strata{$types[$j]} 0 0 0
648 0 $changed = 1;
649 0 $strata{$types[$i]} = $strata{$types[$j]} + 1;
650 }
651 }
652 }
653 }
654 0 return \%strata;
655 }
656  
657 ###############################################################
658 # Type Operations
659 ###############################################################
660  
661 # $h->warn_nondet($op,$t1,$t2,$default,@warnings)
662 # --> sets '$!'
663 0 ▶sub warn_nondet ($$$$$@) {
Subroutine warn_nondet: not called CC=8 SCAR=42.8
Pod undocumented
664 0 ▶ if ($^W && $VERBOSE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^W and $VERBOSE) 0 0 0
Condition0%0/3
$^W and $VERBOSE
!ll&&!rl&&r
000
MC/DC0%0/2
$^W and $VERBOSE
$^W $VERBOSE
Truth table0%0/3
A and B
A= $^WB= $VERBOSE
ABresult
0X0
100
111
665 0 my ($h,$op,$t1,$t2,$default) = @_;
666 0 ▶ my @warnings =
Branch: 3 branches
BranchTrueFalseTotal
defined $t1 ? : 0 0 0
defined $t2 ? : 0 0 0
defined $default ? : 0 0 0
Condition0%0/3
ref $h || $h
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $h || $h
ref $h $h
Truth table0%0/3
A || B
A= ref $hB= $h
ABresult
1X1
011
000
667 ("Warning: unsupported deterministic operation in non-ccpo hierarchy\n",
668 " > Class: ", (ref($h)||$h), "\n",
669 " > Operation: $op(", (defined($t1) ? "'$t1'" : "undef",
670 defined($t2) ? ",'$t2'" : ",undef"), ")\n",
671 " > Defaults to: ", defined($default) ? "'$default'" : 'undef', "\n",
672 " >");
673 0 ▶ if ($VERBOSE > 1) { cluck(@warnings); }
Branch: 1 branch
BranchTrueFalseTotal
if ($VERBOSE > 1) { } 0 0 0
674 0 else { carp(@warnings); }
675 }
676 }
677  
678 #--------------------------------------------------------------
679 # njoin : deterministc n-ary lub()
680 0 ▶sub njoin ($@) {
Subroutine njoin: not called CC=4 SCAR=30.0
Pod documented
681 0 my $h = shift;
682 0 my $val = shift;
683 0 my (@lubs);
684 0 foreach (@_) {
685 0 @lubs = $h->lub($val,$_);
686 0 ▶ return $TYPE_TOP unless (@lubs);
Branch: 1 branch
BranchTrueFalseTotal
unless @lubs 0 0 0
687 0 ▶ $h->warn_nondet('lub', $val, $_, $lubs[0]) if (scalar(@lubs) > 1);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @lubs > 1 0 0 0
688 0 $val = $lubs[0];
689 }
690 0 return $val;
691 }
692  
693 #--------------------------------------------------------------
694 # type_join : deterministic n-ary lub(), defined types only
695 0 ▶sub type_join ($@) {
Subroutine type_join: not called CC=5 SCAR=34.0
Pod documented
696 0 my $h = shift;
697 0 ▶ return $TYPE_TOP unless ($h->has_types(@_)); # sanity check
Branch: 1 branch
BranchTrueFalseTotal
unless $h->has_types(@_) 0 0 0
698 0 my $val = shift;
699 0 my (@lubs);
700 0 foreach (@_) {
701 0 @lubs = $h->_lub($val,$_);
702 0 ▶ return $TYPE_TOP unless (@lubs);
Branch: 1 branch
BranchTrueFalseTotal
unless @lubs 0 0 0
703 0 ▶ $h->warn_nondet('_lub', $val, $_, $lubs[0]) if (scalar(@lubs) > 1);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @lubs > 1 0 0 0
704 0 $val = $lubs[0];
705 }
706 0 return $val;
707 }
708  
709  
710 #--------------------------------------------------------------
711 # nmeet : deterministic n-ary glb()
712 0 ▶sub nmeet ($@) {
Subroutine nmeet: not called CC=4 SCAR=30.0
Pod documented
713 0 my $h = shift;
714 0 my $val = shift;
715 0 my (@glbs);
716 0 foreach (@_) {
717 0 @glbs = $h->glb($val,$_);
718 0 ▶ return undef unless (@glbs);
Branch: 1 branch
BranchTrueFalseTotal
unless @glbs 0 0 0
719 0 ▶ $h->warn_nondet('glb', $val, $_, $glbs[0]) if (scalar(@glbs) > 1);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @glbs > 1 0 0 0
720 0 $val = $glbs[0];
721 }
722 0 return $val;
723 }
724 #--------------------------------------------------------------
725 # type_meet : deterministic n-ary glb(), types only
726 0 ▶sub type_meet ($@) {
Subroutine type_meet: not called CC=5 SCAR=34.0
Pod documented
727 0 my $h = shift;
728 0 ▶ return undef unless ($h->has_types(@_));
Branch: 1 branch
BranchTrueFalseTotal
unless $h->has_types(@_) 0 0 0
729 0 my $val = shift;
730 0 my (@glbs);
731 0 foreach (@_) {
732 0 @glbs = $h->_glb($val,$_);
733 0 ▶ return undef unless (@glbs);
Branch: 1 branch
BranchTrueFalseTotal
unless @glbs 0 0 0
734 0 ▶ $h->warn_nondet('_glb', $val, $_, $glbs[0]) if (scalar(@glbs) > 1);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @glbs > 1 0 0 0
735 0 $val = $glbs[0];
736 }
737 0 return $val;
738 }
739  
740  
741  
742 #--------------------------------------------------------------
743 # lub : least upper bounds
744 #--------------------------------------------------------------
745 7 *least_upper_bounds = \&lub;
746 35 ▶sub lub ($$$) {
Subroutine lub: called CC=6 SCAR=19.2
Pod undocumented
747 35 my ($l);
748 return
749 (# get the easy answers
750 35 ▶ defined($l = _lub_trivial($_[1],$_[2])) ? @$l
Branch: 3 branches
BranchTrueFalseTotal
defined($l = &_lub_trivial($_[1], $_[2])) ? : 15 20 35
$WANT_USER_HOOKS && defined($l = &_lub_user($_[1], $_[2])) ? : 15 5 20
ref $_[0] && $_[0]->has_types($_[1], $_[2]) ? : 5 0 5
Condition50%3/6
$WANT_USER_HOOKS and defined($l = &_lub_user($_[1], $_[2]))
!ll&&!rl&&r
0515
ref $_[0] and $_[0]->has_types($_[1], $_[2])
!ll&&!rl&&r
005
MC/DC50%1/2
$WANT_USER_HOOKS and defined($l = &_lub_user($_[1], $_[2]))
$WANT_USER_HOOKS defined($l = &_lub_user($_[1], $_[2]))
MC/DC0%0/2
ref $_[0] and $_[0]->has_types($_[1], $_[2])
ref $_[0] $_[0]->has_types($_[1], $_[2])
Truth table66%2/3
A and B
A= $WANT_USER_HOOKSB= defined($l = &_lub_user($_[1], $_[2]))
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= ref $_[0]B= $_[0]->has_types($_[1], $_[2])
ABresult
0X0
100
111
751 : (# user hooks
752 ($WANT_USER_HOOKS && defined($l = _lub_user($_[1],$_[2]))) ? @$l
753 : (# are we an instance with these types?
754 (ref($_[0]) && $_[0]->has_types($_[1],$_[2]))
755 # ... then do the lookup
756 ? ($_[0]->_lub($_[1],$_[2]))
757 : # ... guess not
758 qw())));
759 }
760  
761 # lub: iterative version
762 7 *_lub = \&_lub_iter;
763 38 ▶sub _lub_iter ($$$) {
Subroutine _lub_iter: called CC=1 SCAR=0.0
764 return
765 38 values(%{$_[0]->_get_bounds_iter($_[0]->can('children'),
766 -1,
767 $_[1], $_[2],
768 {$_[1]=>$_[1]},
769 {$_[2]=>$_[2]})});
770 }
771  
772 # non-method -- easy answers for lub()
773 # $listref_or_undef = _lub_trivial($t1,$t2)
774 35 ▶sub _lub_trivial ($$) {
Subroutine _lub_trivial: called CC=6 SCAR=18.8
775 return
776 (# X * undef = X
777 35 ▶ !defined($_[1]) ? [$_[0]]
Branch: 4 branches
BranchTrueFalseTotal
!defined($_[1]) ? : 5 30 35
!defined($_[0]) ? : 5 25 30
$_[0] eq $TYPE_TOP || $_[1] eq $TYPE_TOP ? : 0 25 25
$_[0] eq $_[1] ? : 5 20 25
Condition33%1/3
$_[0] eq $TYPE_TOP or $_[1] eq $TYPE_TOP
l!l&&r!l&&!r
0025
MC/DC0%0/2
$_[0] eq $TYPE_TOP or $_[1] eq $TYPE_TOP
$_[0] eq $TYPE_TOP $_[1] eq $TYPE_TOP
Truth table33%1/3
A or B
A= $_[0] eq $TYPE_TOPB= $_[1] eq $TYPE_TOP
ABresult
1X1
011
000
778 : (# undef * X = X
779 !defined($_[0]) ? [$_[1]]
780 : (# X * top = top * X = top
781 ($_[0] eq $TYPE_TOP || $_[1] eq $TYPE_TOP) ? [$TYPE_TOP]
782 : (# X * X = X
783 $_[0] eq $_[1] ? [$_[0]]
784 : # ... can't do it the easy way
785 undef))));
786 }
787  
788 # non-method -- user hooks for lub()
789 # $listref_or_undef = _lub_user($t1,$t2)
790 20 ▶sub _lub_user ($$) { return Math::PartialOrder::Base::_binop_user('lub',$_[0],$_[1]); }
Subroutine _lub_user: called CC=1 SCAR=0.0
791  
792 # $listref_or_undef = binop_user($op,$t1,$t2)
793 45 ▶sub _binop_user ($$$) {
Subroutine _binop_user: called CC=7 SCAR=20.7
794 return
795 (# delegate to $t1 (func)
796 ref($_[1]) && ref($_[1]) eq 'CODE'
797 10 ▶ ? [&{$_[1]}($_[0],$_[2])]
Branch: 1 branch
BranchTrueFalseTotal
ref $_[2] && ref $_[2] eq 'CODE' ? : 0 35 35
Condition33%1/3
ref $_[2] and ref $_[2] eq "CODE"
!ll&&!rl&&r
3500
MC/DC0%0/2
ref $_[2] and ref $_[2] eq "CODE"
ref $_[2] ref $_[2] eq "CODE"
Truth table33%1/3
A and B
A= ref $_[2]B= ref $_[2] eq "CODE"
ABresult
0X0
100
111
798 : (# delegate to $t2 (func)
799 ref($_[2]) && ref($_[2]) eq 'CODE'
800 0 ▶ ? [&{$_[2]}($_[0],$_[1])]
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can($_[1], $_[0]) ? : 15 20 35
801 : (# delegate to $t1 (oop)
802 UNIVERSAL::can($_[1], $_[0])
803 15 ▶ ? [&{UNIVERSAL::can($_[1],$_[0])}($_[1],$_[2])]
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can($_[2], $_[0]) ? : 5 15 20
804 : (# delegate to $t2 (oop)
805 UNIVERSAL::can($_[2], $_[0])
806 45 ▶ ? [&{UNIVERSAL::can($_[2],$_[0])}($_[2],$_[1])]
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] && ref $_[1] eq 'CODE' ? : 10 35 45
Condition66%2/3
ref $_[1] and ref $_[1] eq "CODE"
!ll&&!rl&&r
35010
MC/DC50%1/2
ref $_[1] and ref $_[1] eq "CODE"
ref $_[1] ref $_[1] eq "CODE"
Truth table66%2/3
A and B
A= ref $_[1]B= ref $_[1] eq "CODE"
ABresult
0X0
100
111
807 : # ... nope
808 undef))));
809 }
810  
811 # $_[1] : STOP $_[0] :STOP 'lub' STOP
812  
813 # lub: logical version
814 #*_lub = \&_lub_log;
815 0 ▶sub _lub_log ($$$) {
Subroutine _lub_log: not called CC=3 SCAR=24.8
816 0 my ($cmp);
817 0 ▶ if (defined($cmp = $_[0]->compare($_[1],$_[2]))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($cmp = $_[0]->compare($_[1], $_[2]))) 0 0 0
818 # more easy answers
819 0 ▶ return $_[2] if ($cmp <= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $cmp <= 0 0 0 0
820 0 return $_[1];
821 }
822 # do the lookup
823 0 return $_[0]->mcd_log($_[1],$_[2]);
824 }
825  
826 #--------------------------------------------------------------
827 # mcd : minimal common descendants
828 #--------------------------------------------------------------
829 #*mcd= \&mcd_log;
830 7 *mcd = \&mcd_iter;
831 7 *minimal_common_descendants = \&mcd;
832  
833 # iterative version
834 0 ▶sub mcd_iter ($$$) {
Subroutine mcd_iter: not called CC=2 SCAR=17.9
Pod undocumented
835 0 ▶ return qw() unless ($_[0]->has_types($_[1],$_[2]));
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->has_types($_[1], $_[2]) 0 0 0
836 return
837 0 values(%{$_[0]->_get_bounds_iter($_[0]->can('children'),
838 -1, $_[1], $_[2])});
839 }
840  
841  
842 #--------------------------------------------------------------
843 # _get_bounds_iter: abstract iterative bound-getting method
844 #
845 # iterative version:
846 # lub:test = has_ancestor
847 # lub:next = children
848 # glb:test = has_descendant
849 # glb:next = parents
850 #--------------------------------------------------------------
851  
852 # $h->get_bounds_iter(\&next,$cmpkeep,$t1,$t2)
853 # $h->get_bounds_iter(\&next,$cmpkeep,$t1,$t2,$t1hash,$t2hash)
854 # --> $cmpkeep is -1 to keep minimal, 1 to keep maximal
855 # i.e. min={ x \in solns | y \in solns and !_compare(x,y) or (_compare(x,y) == cmpkeep }
856 41 ▶sub _get_bounds_iter ($&$$$;$$) {
Subroutine _get_bounds_iter: called CC=18 SCAR=32.8
857 41 my $self = shift;
858 41 my $next = shift;
859 41 my $cmpkeep = shift;
860 41 my @t1q = (shift);
861 41 my @t2q = (shift);
862 41 ▶ my $t1set = shift || {};
Condition50%1/2
shift() || {}
l!l
410
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
863 41 ▶ my $t2set = shift || {};
Condition50%1/2
shift() || {}
l!l
410
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
864 41 my %solns = ();
865 41 my %q = ();
866 41 my $step = $self->size;
867 41 my ($e,@next,$cmp,$want);
868 41 ▶ while ((@t1q || @t2q) && $step >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@t1q || @t2q and $step >= 0) 77 41 118
Condition83%5/6
@t1q || @t2q and $step >= 0
!ll&&!rl&&r
41077
@t1q or @t2q
l!l&&r!l&&!r
621541
MC/DC66%2/3
@t1q || @t2q and $step >= 0
@t1q @t2q $step >= 0
Truth table60%3/5
A or B and C
A= @t1qB= @t2qC= $step >= 0
ABCresult
00X0
1X00
0100
1X11
0111
869 77 --$step;
870 77 %q = ();
871 77 foreach $e (@t1q) {
872 83 $t1set->{$e} = $e;
873 83 ▶ if (exists($t2set->{$e})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $t2set->{$e}) { } 15 68 83
874 15 $want = 1;
875 15 foreach (values(%solns)) {
876 0 $cmp = $self->_compare($e,$_);
877 0 ▶ next if (!$cmp);
Branch: 1 branch
BranchTrueFalseTotal
unless $cmp 0 0 0
878 0 ▶ if ($cmp != $cmpkeep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp != $cmpkeep) 0 0 0
879 0 $want = 0;
880 0 last;
881 }
882 0 delete($solns{$_});
883 }
884 15 ▶ $solns{$e} = $e if ($want);
Branch: 1 branch
BranchTrueFalseTotal
if $want 15 0 15
885 } else {
886 68 @next = &$next($self,$e);
887 68 @q{@next} = @next;
888 }
889 }
890 77 @t1q = values(%q);
891 77 %q = ();
892 77 foreach $e (@t2q) {
893 86 $t2set->{$e} = $e;
894 86 ▶ if (exists($t1set->{$e})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $t1set->{$e}) { } 21 65 86
895 21 $want = 1;
896 21 foreach (values(%solns)) {
897 6 $cmp = $self->_compare($e,$_);
898 6 ▶ next if (!$cmp);
Branch: 1 branch
BranchTrueFalseTotal
unless $cmp 6 0 6
899 0 ▶ if ($cmp != $cmpkeep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp != $cmpkeep) 0 0 0
900 0 $want = 0;
901 0 last;
902 }
903 0 delete($solns{$_});
904 }
905 21 ▶ $solns{$e} = $e if ($want);
Branch: 1 branch
BranchTrueFalseTotal
if $want 21 0 21
906 } else {
907 65 @next = &$next($self,$e);
908 65 @q{@next} = @next;
909 }
910 }
911 77 @t2q = values(%q);
912 }
913 41 return \%solns;
914 }
915  
916  
917 # mcd($h,$t1,$t2): logical version
918 # *mcd = \&mcd_log;
919 0 ▶sub mcd_log ($$$) {
Subroutine mcd_log: not called CC=1 SCAR=6.9
Pod undocumented
920 # get intersection of descendants
921 0 my (@t1descs,%t1hash);
922 0 @t1descs = $_[0]->descendants($_[1]);
923 0 @t1hash{@t1descs} = @t1descs;
924 # delegate the gruntwork to min()
925 return
926 0 $_[0]->min(grep { exists($t1hash{$_}) } $_[0]->descendants($_[2]));
927 }
928  
929  
930 #--------------------------------------------------------------
931 # glb : greatest lower bounds
932 #--------------------------------------------------------------
933 7 *greatest_lower_bounds = \&glb;
934  
935 35 ▶sub glb ($$$) {
Subroutine glb: called CC=6 SCAR=18.1
Pod undocumented
936 35 my (@l);
937 return
938 (# get the easy answers
939 35 ▶ defined($l = _glb_trivial($_[1],$_[2])) ? @$l
Branch: 3 branches
BranchTrueFalseTotal
defined($l = &_glb_trivial($_[1], $_[2])) ? : 10 25 35
$WANT_USER_HOOKS && defined($l = &_glb_user($_[1], $_[2])) ? : 15 10 25
ref $_[0] && $_[0]->has_types($_[1], $_[2]) ? : 5 5 10
Condition66%4/6
$WANT_USER_HOOKS and defined($l = &_glb_user($_[1], $_[2]))
!ll&&!rl&&r
01015
ref $_[0] and $_[0]->has_types($_[1], $_[2])
!ll&&!rl&&r
055
MC/DC50%1/2
$WANT_USER_HOOKS and defined($l = &_glb_user($_[1], $_[2]))
$WANT_USER_HOOKS defined($l = &_glb_user($_[1], $_[2]))
MC/DC50%1/2
ref $_[0] and $_[0]->has_types($_[1], $_[2])
ref $_[0] $_[0]->has_types($_[1], $_[2])
Truth table66%2/3
A and B
A= $WANT_USER_HOOKSB= defined($l = &_glb_user($_[1], $_[2]))
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= ref $_[0]B= $_[0]->has_types($_[1], $_[2])
ABresult
0X0
100
111
940 : (# user hooks
941 ($WANT_USER_HOOKS && defined($l = _glb_user($_[1],$_[2]))) ? @$l
942 : (# are we an instance with these types?
943 (ref($_[0]) && $_[0]->has_types($_[1],$_[2]))
944 # ... then do the lookup
945 ? ($_[0]->_glb($_[1],$_[2]))
946 : # ... guess not
947 undef)));
948 }
949  
950 # non-method -- easy answers for glb()
951 # $listref_or_undef = _lub_trivial($t1,$t2)
952 35 ▶sub _glb_trivial ($$) {
Subroutine _glb_trivial: called CC=5 SCAR=16.5
953 return
954 (# X / undef = undef / X = undef
955 35 ▶ !defined($_[0]) or !defined($_[1]) ? [undef]
Branch: 3 branches
BranchTrueFalseTotal
!defined($_[1]) ? : 5 25 30
$_[0] eq $TYPE_TOP ? : 0 25 25
$_[1] eq $TYPE_TOP ? : 0 25 25
Condition100%3/3
!defined($_[0]) || (!defined($_[1]) ? [undef] : ($_[0] eq $TYPE_TOP ? [$_[1]] : ($_[1] eq $TYPE_TOP ? [$_[0]] : undef)))
l!l&&r!l&&!r
5525
MC/DC100%2/2
!defined($_[0]) || (!defined($_[1]) ? [undef] : ($_[0] eq $TYPE_TOP ? [$_[1]] : ($_[1] eq $TYPE_TOP ? [$_[0]] : undef)))
!defined($_[0]) (!defined($_[1]) ? [undef] : ($_[0] eq $TYPE_TOP ? [$_[1]] : ($_[1] eq $TYPE_TOP ? [$_[0]] : undef)))
Truth table100%3/3
not(A) || not(B)
A= !defined($_[0])B= (!defined($_[1]) ? [undef] : ($_[0] eq $TYPE_TOP ? [$_[1]] : ($_[1] eq $TYPE_TOP ? [$_[0]] : undef)))
ABresult
1X1
011
000
956 : (# top / X = X
957 $_[0] eq $TYPE_TOP ? [$_[1]]
958 : (# X / top = X
959 $_[1] eq $TYPE_TOP ? [$_[0]]
960 : # ... can't do it the easy way
961 undef)));
962 }
963  
964 # non-method -- user hooks for glb()
965 # $listref_or_undef = _glb_user($t1,$t2)
966 25 ▶sub _glb_user ($$) { return Math::PartialOrder::Base::_binop_user('glb',$_[0],$_[1]); }
Subroutine _glb_user: called CC=1 SCAR=0.0
967  
968 # glb: logical version
969 #*_glb = \&_glb_log;
970 0 ▶sub _glb_log ($$$) {
Subroutine _glb_log: not called CC=3 SCAR=24.8
971 0 my ($cmp);
972 0 ▶ if (defined($cmp = $_[0]->compare($_[1],$_[2]))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($cmp = $_[0]->compare($_[1], $_[2]))) 0 0 0
973 # more easy answers
974 0 ▶ return $_[2] if ($cmp >= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $cmp >= 0 0 0 0
975 0 return $_[1];
976 }
977 # do the lookup
978 0 return $_[0]->mca_log($_[1],$_[2]);
979 }
980  
981  
982 # glb: iterative version
983 7 *_glb = \&_glb_iter;
984 3 ▶sub _glb_iter ($$$) {
Subroutine _glb_iter: called CC=1 SCAR=0.0
985 return
986 3 values(%{$_[0]->_get_bounds_iter($_[0]->can('parents'),
987 1,
988 $_[1], $_[2],
989 {$_[1]=>$_[1]},
990 {$_[2]=>$_[2]})});
991 }
992  
993  
994 #--------------------------------------------------------------
995 # mca : maximal common ancestors
996 #--------------------------------------------------------------
997 7 *mca = \&mca_iter;
998 #*mca = \&mca_log;
999 7 *maximal_common_ancestors = \&mca;
1000  
1001 # iterative version
1002 0 ▶sub mca_iter ($$$) {
Subroutine mca_iter: not called CC=1 SCAR=6.9
Pod undocumented
1003 0 return values(%{$_[0]->_get_bounds_iter($_[0]->can('parents'),
1004 1,
1005 $_[1], $_[2])});
1006 }
1007  
1008 # mca: logical version
1009 # *mca = \&mca_log;
1010 0 ▶sub mca_log ($$$) {
Subroutine mca_log: not called CC=1 SCAR=6.9
Pod undocumented
1011 # get intersection of ancestors
1012 0 my (@t1descs,%t1hash);
1013 0 @t1descs = $_[0]->ancestors($_[1]);
1014 0 @t1hash{@t1descs} = @t1descs;
1015 # delegate the gruntwork to max()
1016 return
1017 0 $_[0]->max(grep { exists($t1hash{$_}) } $_[0]->ancestors($_[2]));
1018 }
1019  
1020  
1021 #####################################################################
1022 # User-Defined Attributes
1023 #####################################################################
1024  
1025 179 ▶sub get_attributes ($$) { return $_[0]->_attributes($_[1]); }
Subroutine get_attributes: called CC=1 SCAR=0.0
Pod documented
1026 0 ▶sub get_attribute ($$$) {
Subroutine get_attribute: not called CC=2 SCAR=17.9
Pod documented
1027 0 my ($self,$type,$attr) = @_;
1028 0 my ($tattrs);
1029 return
1030 defined($tattrs = $self->_attributes($type))
1031 0 ▶ ? $tattrs->{$attr}
Branch: 1 branch
BranchTrueFalseTotal
defined($tattrs = $self->_attributes($type)) ? : 0 0 0
1032 : undef;
1033 }
1034 0 ▶sub set_attribute ($$$$) {
Subroutine set_attribute: not called CC=2 SCAR=17.9
Pod documented
1035 0 my ($self,$type,$attr,$val) = @_;
1036 0 my ($tattrs);
1037 0 ▶ if (defined($tattrs = $self->_attributes($type))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($tattrs = $self->_attributes($type))) 0 0 0
1038 0 return $tattrs->{$attr} = $val;
1039 }
1040 # need new attributes
1041 0 $self->_attributes($type, {$attr => $val});
1042 0 return $val;
1043 }
1044 0 ▶sub _attributes ($$;$) {
Subroutine _attributes: not called CC=6 SCAR=37.4
1045 0 my $self = shift;
1046 0 ▶ return undef unless (ref($self) && $self =~ /=HASH\(/);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self and $self =~ /=HASH\(/ 0 0 0
Condition0%0/3
ref $self and $self =~ /=HASH\(/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self and $self =~ /=HASH\(/
ref $self $self =~ /=HASH\(/
Truth table0%0/3
A and B
A= ref $selfB= $self =~ /=HASH\(/
ABresult
0X0
100
111
1047 0 my $type = shift;
1048 0 my $attr = shift;
1049 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1050 # set attributes
1051 0 return $self->{attributes}->{$type} = shift;
1052 }
1053 # get attributes
1054 0 ▶ if (exists($self->{attributes}) && exists($self->{attributes}->{$type}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"attributes"} and exists $self->{"attributes"}{$type}) 0 0 0
Condition0%0/3
exists $self->{"attributes"} and exists $self->{"attributes"}{$type}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"attributes"} and exists $self->{"attributes"}{$type}
exists $self->{"attributes"} exists $self->{"attributes"}{$type}
Truth table0%0/3
A and B
A= exists $self->{"attributes"}B= exists $self->{"attributes"}{$type}
ABresult
0X0
100
111
1055 {
1056 0 return $self->{attributes}->{$type};
1057 }
1058 0 return undef;
1059 }
1060  
1061 # _hattributes(), _hattributes($attrs)
1062 # --> automagic creation!
1063 7 *_hattrs = \&_hattributes;
1064 140 ▶sub _hattributes ($;$) {
Subroutine _hattributes: called CC=4 SCAR=13.9
1065 140 ▶ if (scalar(@_) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) 105 35 140
1066 return $_[0]->_attributes->{$_[0]} = {} unless
1067 (defined($_[0]->_attributes) &&
1068 105 ▶ exists($_[0]->_attributes->{$_[0]}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0]->_attributes and exists $_[0]->_attributes->{$_[0]} 6 99 105
Condition66%2/3
defined $_[0]->_attributes and exists $_[0]->_attributes->{$_[0]}
!ll&&!rl&&r
0699
MC/DC50%1/2
defined $_[0]->_attributes and exists $_[0]->_attributes->{$_[0]}
defined $_[0]->_attributes exists $_[0]->_attributes->{$_[0]}
Truth table66%2/3
A and B
A= defined $_[0]->_attributesB= exists $_[0]->_attributes->{$_[0]}
ABresult
0X0
100
111
1069 99 return $_[0]->_attributes->{$_[0]};
1070 }
1071 35 return $_[0]->_attributes->{$_[0]} = $_[1];
1072 }
1073  
1074 # $val = $h->get_hattribute($a)
1075 0 ▶sub get_hattribute ($$) {
Subroutine get_hattribute: not called CC=2 SCAR=17.9
Pod documented
1076 0 ▶ return defined($_[1]) ? $_[0]->_hattributes->{$_[1]} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
1077 }
1078 # $val = $h->set_hattribute($a,$v)
1079 0 ▶sub set_hattribute ($$;$) {
Subroutine set_hattribute: not called CC=3 SCAR=24.8
Pod documented
1080 return
1081 defined($_[1])
1082 ? defined($_[2])
1083 ? $_[0]->_hattributes->{$_[1]} = $_[2]
1084 0 ▶ : delete($_[0]->_hattributes->{$_[1]})
Branch: 2 branches
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
1085 : undef;
1086 }
1087  
1088  
1089 #####################################################################
1090 # Iteration Utilitiles
1091 #####################################################################
1092  
1093 0 ▶sub iterate ($&&;$) {
Subroutine iterate: not called CC=9 SCAR=45.0
Pod documented
1094 0 my ($self,$next,$callback,$args) = @_;
1095 0 ▶ return undef unless (defined($next) && defined($callback));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next and defined $callback 0 0 0
Condition0%0/3
defined $next and defined $callback
!ll&&!rl&&r
000
MC/DC0%0/2
defined $next and defined $callback
defined $next defined $callback
Truth table0%0/3
A and B
A= defined $nextB= defined $callback
ABresult
0X0
100
111
1096 0 my ($t,$r);
1097 my @q = defined($args->{start})
1098 ? ref($args->{start})
1099 0 ? @{$args->{start}}
1100 : $args->{start}
1101 0 ▶ : ($self->root);
Branch: 2 branches
BranchTrueFalseTotal
defined $args->{'start'} ? : 0 0 0
ref $args->{'start'} ? : 0 0 0
1102 0 ▶ return undef unless ($self->has_types(@q));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_types(@q) 0 0 0
1103  
1104 0 ▶ while (@q) {
Branch: 1 branch
BranchTrueFalseTotal
if (@q) 0 0 0
1105 0 $t = shift(@q);
1106 0 ▶ $r = &$callback($self, $t, $args) if (defined($callback));
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback 0 0 0
1107 0 ▶ return $r if (defined($r));
Branch: 1 branch
BranchTrueFalseTotal
if defined $r 0 0 0
1108 0 push(@q, &$next($self,$t,$args));
1109 }
1110 0 return $args->{return};
1111 }
1112  
1113  
1114 24 ▶sub iterate_step ($&&;$) {
Subroutine iterate_step: called CC=12 SCAR=25.1
Pod documented
1115 24 my ($self,$next,$callback,$args) = @_;
1116 24 ▶ return undef unless (defined($next));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 24 24
1117  
1118 my @q = defined($args->{start})
1119 ? ref($args->{start})
1120 18 ? @{$args->{start}}
1121 : ($args->{start})
1122 24 ▶ : ($self->root);
Branch: 2 branches
BranchTrueFalseTotal
defined $args->{'start'} ? : 24 0 24
ref $args->{'start'} ? : 18 6 24
1123 24 ▶ return undef unless ($self->has_types(@q));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_types(@q) 0 24 24
1124  
1125 my $visited =
1126 defined($args->{visited})
1127 ? $args->{visited}
1128 24 ▶ : ($args->{visited} = {});
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'visited'} ? : 0 24 24
1129  
1130 24 my ($t,$r,%qh,@next);
1131 24 @qh{@q} = @q;
1132 24 ▶ $args->{step} = 0 unless (defined($args->{step}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"step"} 24 0 24
1133 24 ▶ while (%qh) {
Branch: 1 branch
BranchTrueFalseTotal
if (%qh) 60 15 75
1134 60 @q = values(%qh);
1135 60 %qh = ();
1136 60 ▶ while (defined($t = shift(@q))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($t = shift @q)) 96 51 147
1137 96 ▶ next if (exists($visited->{$t}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $visited->{$t} 3 93 96
1138 93 $visited->{$t} = undef;
1139 93 ▶ $r = &$callback($self, $t, $args) if (defined($callback));
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback 93 0 93
1140 93 ▶ return $r if (defined($r));
Branch: 1 branch
BranchTrueFalseTotal
if defined $r 9 84 93
1141 84 @next = grep { !exists($visited->{$_}) } &$next($self,$t);
1142 84 @qh{@next} = @next;
1143 }
1144 51 ++$args->{step};
1145 }
1146 15 return $args->{return};
1147 }
1148  
1149  
1150 0 ▶sub iterate_tracking ($&&;$) {
Subroutine iterate_tracking: not called CC=14 SCAR=53.5
Pod documented
1151 0 my ($self,$next,$callback,$args) = @_;
1152 0 ▶ return undef unless (defined($next) && defined($callback));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next and defined $callback 0 0 0
Condition0%0/3
defined $next and defined $callback
!ll&&!rl&&r
000
MC/DC0%0/2
defined $next and defined $callback
defined $next defined $callback
Truth table0%0/3
A and B
A= defined $nextB= defined $callback
ABresult
0X0
100
111
1153  
1154 my @q = defined($args->{start})
1155 ? ref($args->{start})
1156 0 ? @{$args->{start}}
1157 : ($args->{start})
1158 0 ▶ : ($self->root);
Branch: 2 branches
BranchTrueFalseTotal
defined $args->{'start'} ? : 0 0 0
ref $args->{'start'} ? : 0 0 0
1159  
1160 my $ignore =
1161 defined($args->{ignore})
1162 ? $args->{ignore}
1163 0 ▶ : ($args->{ignore} = {});
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'ignore'} ? : 0 0 0
1164  
1165 my $prev =
1166 defined($args->{prev})
1167 ? $args->{prev}
1168 0 ▶ : ($args->{prev} = {});
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'prev'} ? : 0 0 0
1169  
1170 0 my ($t,$r,%qh,@next);
1171 0 @qh{@q} = @q;
1172 0 ▶ $args->{step} = 0 unless (defined($args->{step}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"step"} 0 0 0
1173  
1174 0 ▶ while (%qh) {
Branch: 1 branch
BranchTrueFalseTotal
if (%qh) 0 0 0
1175 0 @q = values(%qh);
1176 0 %qh = ();
1177 0 ▶ while (defined($t = shift(@q))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($t = shift @q)) 0 0 0
1178 0 ▶ next if (exists($ignore->{$t}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $ignore->{$t} 0 0 0
1179  
1180 0 $r = &$callback($self, $t, $args);
1181 0 ▶ return $r if (defined($r));
Branch: 1 branch
BranchTrueFalseTotal
if defined $r 0 0 0
1182  
1183 0 ▶ next if (exists($ignore->{$t}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $ignore->{$t} 0 0 0
1184  
1185 0 @next = &$next($self,$t,$args);
1186  
1187 0 foreach (@next) { $prev->{$_}{$t} = undef; }
1188 0 @next = grep { !exists($ignore->{$_}) } @next;
1189 0 @qh{@next} = @next;
1190 }
1191 0 ++$args->{step};
1192 }
1193 0 return $args->{return};
1194 }
1195  
1196 10 ▶sub iterate_strata ($&&;$) {
Subroutine iterate_strata: called CC=13 SCAR=27.4
Pod documented
1197 10 my ($self,$next,$callback,$args) = @_;
1198  
1199 10 ▶ return undef unless (defined($next) && defined($callback));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next and defined $callback 0 10 10
Condition33%1/3
defined $next and defined $callback
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $next and defined $callback
defined $next defined $callback
Truth table33%1/3
A and B
A= defined $nextB= defined $callback
ABresult
0X0
100
111
1200  
1201 my @q = defined($args->{start})
1202 ? ref($args->{start})
1203 0 ? @{$args->{start}}
1204 : ($args->{start})
1205 10 ▶ : ($self->root);
Branch: 2 branches
BranchTrueFalseTotal
defined $args->{'start'} ? : 0 10 10
ref $args->{'start'} ? : 0 0 0
1206  
1207 my $prev =
1208 defined($args->{prev})
1209 ? $args->{prev}
1210 10 ▶ : ($args->{prev} = {});
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'prev'} ? : 0 10 10
1211  
1212 10 my ($t,$r,%qh,@next);
1213 10 @qh{@q} = @q;
1214 10 ▶ $args->{step} = 0 unless (defined($args->{step}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"step"} 10 0 10
1215  
1216 10 ▶ while (%qh) {
Branch: 1 branch
BranchTrueFalseTotal
if (%qh) 40 5 45
1217 40 @q = values(%qh);
1218 40 %qh = ();
1219 40 ▶ while (defined($t = shift(@q))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($t = shift @q)) 50 35 85
1220 50 $r = &$callback($self, $t, $args);
1221 50 ▶ return $r if (defined($r));
Branch: 1 branch
BranchTrueFalseTotal
if defined $r 5 45 50
1222  
1223 45 @next = &$next($self,$t,$args);
1224  
1225 45 foreach (@next) {
1226 40 ▶ if (!defined($prev->{$_}{$t}) || $prev->{$_}{$t} < $args->{step}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $prev->{$_}{$t} or $prev->{$_}{$t} < $args->{"step"}) 40 0 40
Condition66%2/3
not defined $prev->{$_}{$t} or $prev->{$_}{$t} < $args->{"step"}
l!l&&r!l&&!r
3550
MC/DC0%0/2
not defined $prev->{$_}{$t} or $prev->{$_}{$t} < $args->{"step"}
not defined $prev->{$_}{$t} $prev->{$_}{$t} < $args->{"step"}
Truth table66%2/3
not(A) or B
A= not defined $prev->{$_}{$t}B= $prev->{$_}{$t} < $args->{"step"}
ABresult
1X1
011
000
1227 $prev->{$_}{$t} = $args->{step}
1228 40 }
1229 }
1230 45 @qh{@next} = @next;
1231 }
1232 35 ++$args->{step};
1233 }
1234 5 return $args->{return};
1235 }
1236  
1237 0 ▶sub iterate_pc ($&;$) {
Subroutine iterate_pc: not called CC=2 SCAR=17.9
Pod documented
1238 0 ▶ return $_[0]->iterate
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 0 0 0
1239 (UNIVERSAL::can($_[0], 'children'),
1240 $_[1],
1241 defined($_[2]) ? $_[2] : {});
1242 }
1243  
1244 0 ▶sub iterate_pc_step ($&;$) {
Subroutine iterate_pc_step: not called CC=2 SCAR=17.9
Pod documented
1245 0 ▶ return $_[0]->iterate_step
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 0 0 0
1246 (UNIVERSAL::can($_[0], 'children'),
1247 $_[1],
1248 defined($_[2]) ? $_[2] : {});
1249 }
1250  
1251 0 ▶sub iterate_cp ($&;$) {
Subroutine iterate_cp: not called CC=4 SCAR=30.0
Pod documented
1252 $_[2]->{start} = [$_[0]->leaves] if
1253 0 ▶ (defined($_[2]) && !defined($_[2]->{start}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[2] and not defined $_[2]{"start"} 0 0 0
Condition0%0/3
defined $_[2] and not defined $_[2]{"start"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[2] and not defined $_[2]{"start"}
defined $_[2] not defined $_[2]{"start"}
Truth table0%0/3
A and not(B)
A= defined $_[2]B= not defined $_[2]{"start"}
ABresult
0X0
100
111
1254 0 ▶ return $_[0]->iterate
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 0 0 0
1255 (UNIVERSAL::can($_[0], 'parents'),
1256 $_[1],
1257 defined($_[2]) ? $_[2] : {});
1258 }
1259  
1260 24 ▶sub iterate_cp_step ($&;$) {
Subroutine iterate_cp_step: called CC=4 SCAR=16.9
Pod documented
1261 $_[2]->{start} = [$_[0]->leaves] if
1262 24 ▶ (defined($_[2]) && !defined($_[2]->{start}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[2] and not defined $_[2]{"start"} 0 24 24
Condition33%1/3
defined $_[2] and not defined $_[2]{"start"}
!ll&&!rl&&r
0240
MC/DC0%0/2
defined $_[2] and not defined $_[2]{"start"}
defined $_[2] not defined $_[2]{"start"}
Truth table33%1/3
A and not(B)
A= defined $_[2]B= not defined $_[2]{"start"}
ABresult
0X0
100
111
1263 24 ▶ return $_[0]->iterate_step
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 24 0 24
1264 (UNIVERSAL::can($_[0], 'parents'),
1265 $_[1],
1266 defined($_[2]) ? $_[2] : {});
1267 }
1268  
1269  
1270 #####################################################################
1271 # Miscellaneous
1272 #####################################################################
1273  
1274 0 ▶sub dump ($) {
Subroutine dump: not called CC=1 SCAR=6.9
Pod documented
1275 0 eval "use Data::Dumper";
1276 0 return Data::Dumper->Dump([$_[0]], [$_[0]]);
1277 }
1278  
1279  
1280  
1281 7 1;
1282 __END__
« PartialOrder/Loader.pm ↑ Summary PartialOrder/Std.pm »