PartialOrder/Std.pm

filter: Statementstmt 65.6% 145 / 221 Branchbran 44.5% 41 / 92 Conditioncond 41.1% 14 / 34 MC/DCmcdc 20.0% 4 / 20 Subroutinesub 76.6% 23 / 30 Podpod 100% 17 / 17 totaltotal 58.9% 244 / 414 CC 72 SCAR 26.6
CC
72
Cov
58%
_minimize
56.0
_maximize
56.0
merge
23.6
CRAP 14.2
« PartialOrder/Base.pm ↑ Summary PartialOrder/Caching.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::Std.pm
13 # Author: Bryan Jurish <jurish@ling.uni-potsdam.de>
14 #
15 # Description: standard iterative PartialOrder class
16 #
17 ###############################################################
18  
19 package Math::PartialOrder::Std;
20 # System modules
21 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 #require Exporter;
23 # 3rd party exstensions
24 # user extension modules
25 7 ▶use Math::PartialOrder::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 7 @ISA = qw(Math::PartialOrder::Base);
27 7 @EXPORT = qw();
28 7 @EXPORT_OK = qw();
29  
30 7 our $VERSION = 0.01;
31  
32 ###############################################################
33 # Initialization
34 # + object structure:
35 # {
36 # types => {type1=>type1, ... }
37 # root => scalar
38 # parents => { type1 => {p1a=>p1a, c1b=>c1b,... }, ... }
39 # children => { type1 => {c1a=>c1a, c1b=>c1b,... }, ... }
40 # attributes => { type1 => { attr1.1 => val1.1, ... }, ... }
41 # }
42 ###############################################################
43  
44 #----------------------------------------------------------------------
45 # new( {root=>$r} )
46 # + initialization routine: returns the object
47 #----------------------------------------------------------------------
48 11 ▶sub new ($;$) {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
49 11 my $class = shift;
50 11 my $args = shift;
51 11 my $self = bless {
52 types => {},
53 root => '',
54 parents => {},
55 children => {},
56 attrs => {}
57 }, $class;
58 # root node
59 11 ▶ $self->_root($args->{root}||'BOTTOM');
Condition100%2/2
$args->{'root'} || 'BOTTOM'
l!l
56
MC/DC100%1/1
$args->{'root'} || 'BOTTOM'
$args->{'root'}
Truth table100%2/2
A
A= $args->{'root'}
Aresult
11
00
60  
61 # hierarchy attributes
62 11 $self->_hattributes({});
63  
64 11 return $self;
65 }
66  
67 ###############################################################
68 # Hierarchy Information
69 # information
70 ###############################################################
71 # @types = $h->types()
72 227 ▶sub types ($) { return values(%{$_[0]->{types}}); }
Subroutine types: called CC=1 SCAR=0.0
Pod documented
73  
74 #--------------------------------------------------------------
75 # $bool = $h->has_type($t)
76 1428 ▶sub has_type ($$) { return (defined($_[1]) && exists($_[0]->{types}{$_[1]})); }
Subroutine has_type: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
defined $_[1] && exists $_[0]{'types'}{$_[1]}
!ll&&!rl&&r
03381090
MC/DC50%1/2
defined $_[1] && exists $_[0]{'types'}{$_[1]}
defined $_[1] exists $_[0]{'types'}{$_[1]}
Truth table66%2/3
A && B
A= defined $_[1]B= exists $_[0]{'types'}{$_[1]}
ABresult
0X0
100
111
77  
78 # $bool = $h->has_types(@types)
79 63 ▶sub has_types ($@) {
Subroutine has_types: called CC=3 SCAR=11.0
Pod documented
80 63 my $types = shift->{types};
81 grep {
82 63 ▶ return '' unless (defined($_) && exists($types->{$_}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ and exists $types->{$_} 6 111 117
Condition66%2/3
defined $_ and exists $types->{$_}
!ll&&!rl&&r
06111
MC/DC50%1/2
defined $_ and exists $types->{$_}
defined $_ exists $types->{$_}
Truth table66%2/3
A and B
A= defined $_B= exists $types->{$_}
ABresult
0X0
100
111
83 } @_;
84 57 return 1;
85 }
86  
87 #--------------------------------------------------------------
88 # @ps = $h->parents($typ)
89 1287 ▶sub parents ($$) {
Subroutine parents: called CC=3 SCAR=13.1
Pod documented
90 return
91 (defined($_[1]) && exists($_[0]->{parents}{$_[1]})
92 1287 ▶ ? values(%{$_[0]->{parents}{$_[1]}})
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && exists $_[0]{'parents'}{$_[1]} ? : 1287 0 1287
Condition33%1/3
defined $_[1] and exists $_[0]{"parents"}{$_[1]}
!ll&&!rl&&r
001287
MC/DC0%0/2
defined $_[1] and exists $_[0]{"parents"}{$_[1]}
defined $_[1] exists $_[0]{"parents"}{$_[1]}
Truth table33%1/3
A and B
A= defined $_[1]B= exists $_[0]{"parents"}{$_[1]}
ABresult
0X0
100
111
93 : qw());
94 }
95  
96 #--------------------------------------------------------------
97 # @cs = $h->children($typ)
98 175 ▶sub children ($$) {
Subroutine children: called CC=3 SCAR=11.1
Pod documented
99 return
100 (defined($_[1]) && exists($_[0]->{children}{$_[1]})
101 175 ▶ ? values(%{$_[0]->{children}{$_[1]}})
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && exists $_[0]{'children'}{$_[1]} ? : 72 103 175
Condition66%2/3
defined $_[1] and exists $_[0]{"children"}{$_[1]}
!ll&&!rl&&r
010372
MC/DC50%1/2
defined $_[1] and exists $_[0]{"children"}{$_[1]}
defined $_[1] exists $_[0]{"children"}{$_[1]}
Truth table66%2/3
A and B
A= defined $_[1]B= exists $_[0]{"children"}{$_[1]}
ABresult
0X0
100
111
102 : qw());
103 }
104  
105 #--------------------------------------------------------------
106 # $bool = $h->has_parent($kid,$prt);
107 521 ▶sub has_parent ($$) {
Subroutine has_parent: called CC=3 SCAR=14.2
Pod documented
108 return
109 (defined($_[1]) && exists($_[0]->{parents}{$_[1]})
110 521 ▶ ? exists($_[0]->{parents}{$_[1]}{$_[2]})
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && exists $_[0]{'parents'}{$_[1]} ? : 521 0 521
Condition33%1/3
defined $_[1] and exists $_[0]{"parents"}{$_[1]}
!ll&&!rl&&r
00521
MC/DC0%0/2
defined $_[1] and exists $_[0]{"parents"}{$_[1]}
defined $_[1] exists $_[0]{"parents"}{$_[1]}
Truth table33%1/3
A and B
A= defined $_[1]B= exists $_[0]{"parents"}{$_[1]}
ABresult
0X0
100
111
111 : '');
112 }
113  
114 #--------------------------------------------------------------
115 # $bool = $h->has_child($prt,$kid);
116 3 ▶sub has_child ($$) {
Subroutine has_child: called CC=3 SCAR=14.2
Pod documented
117 return
118 (defined($_[1]) && exists($_[0]->{parents}{$_[1]})
119 3 ▶ ? exists($_[0]->{parents}{$_[1]}{$_[2]})
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && exists $_[0]{'parents'}{$_[1]} ? : 3 0 3
Condition33%1/3
defined $_[1] and exists $_[0]{"parents"}{$_[1]}
!ll&&!rl&&r
003
MC/DC0%0/2
defined $_[1] and exists $_[0]{"parents"}{$_[1]}
defined $_[1] exists $_[0]{"parents"}{$_[1]}
Truth table33%1/3
A and B
A= defined $_[1]B= exists $_[0]{"parents"}{$_[1]}
ABresult
0X0
100
111
120 : '');
121 }
122  
123 #--------------------------------------------------------------
124 # @ancs = $h->ancestors($typ)
125 3 ▶sub ancestors ($$) { return values(%{$_[0]->_ancestors($_[1])}); }
Subroutine ancestors: called CC=1 SCAR=0.0
Pod documented
126  
127 #--------------------------------------------------------------
128 # @dscs = $h->descendants($typ)
129 3 ▶sub descendants ($$) { return values(%{$_[0]->_ancestors($_[1])}); }
Subroutine descendants: called CC=1 SCAR=0.0
Pod documented
130  
131 #--------------------------------------------------------------
132 # $bool = has_ancestor($t1,$t2) : inherited
133  
134 #--------------------------------------------------------------
135 # $bool = has_descendant($t1,$t2) : inherited
136  
137  
138 ###############################################################
139 # Additional Information
140 ###############################################################
141  
142 # $hashref = $h->_ancestors($t)
143 6 ▶sub _ancestors ($$) {
Subroutine _ancestors: called CC=2 SCAR=7.6
144 return
145 6 ▶ ($_[0]->has_type($_[1])
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->has_type($_[1]) ? : 6 0 6
146 ? $_[0]->iterate_cp_step(\&_ancestors_callback,
147 {
148 start => $_[1],
149 return => {}
150 })
151 : {});
152 }
153 27 ▶sub _ancestors_callback ($$$) {
Subroutine _ancestors_callback: called CC=1 SCAR=0.0
154 27 @{$_[2]->{return}}{$_[0]->parents($_[1])} = $_[0]->parents($_[1]);
155 27 return undef;
156 }
157  
158 # $hashref = $h->_descendants($t)
159 0 ▶sub _descendants ($$) {
Subroutine _descendants: not called CC=2 SCAR=17.9
160 0 ▶ ($_[0]->has_type($_[1])
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->has_type($_[1]) ? : 0 0 0
161 ? $_[0]->iterate_pc_step(\&_descendants_callback,
162 {
163 start => $_[1],
164 return => {}
165 })
166 : {});
167 }
168 0 ▶sub _descendants_callback ($$$) {
Subroutine _descendants_callback: not called CC=1 SCAR=6.9
169 0 @{$_[2]->{return}}{$_[0]->children($_[1])} = $_[0]->children($_[1]);
170 0 return undef;
171 }
172  
173 # end information
174  
175  
176 ###############################################################
177 # Hierarchy Manipulation
178 ###############################################################
179  
180 #--------------------------------------------------------------
181 # add($type,@parents)
182 328 ▶sub add ($$@) {
Subroutine add: called CC=5 SCAR=16.4
Pod documented
183 328 my $self = shift;
184 328 my $type = shift;
185  
186 # sanity checks
187 328 ▶ unless (defined($type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 0 328 328
188 0 carp("cannot add undefined type");
189 0 return $self;
190 }
191 328 ▶ return $self->move($type, @_) if ($self->has_type($type));
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_type($type) 55 273 328
192  
193 # add this type
194 273 $self->{types}{$type} = $type;
195  
196 # ensure parents are well-defined & well-placed
197 273 @_ = $self->ensure_types(@_);
198  
199 # set parents-relation for new $type
200 273 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 273 0 273
201 273 $self->{parents}{$type} = {};
202 273 @{$self->{parents}{$type}}{@_} = @_;
203 }
204 # set children-relation for new $type
205 273 my $kids = $self->{children};
206 273 foreach (@_) { $kids->{$_}{$type} = $type; }
207 273 return $self;
208 }
209  
210 #--------------------------------------------------------------
211 # sub add_parents($h,$type,@parents) : INHERITED
212  
213 #--------------------------------------------------------------
214 # replace($old,$new)
215 24 ▶sub replace ($$$) {
Subroutine replace: called CC=7 SCAR=20.4
Pod documented
216 24 my ($h, $old, $new) = @_;
217 24 ▶ return $h->add($new,$h->root) unless ($h->has_type($old));
Branch: 1 branch
BranchTrueFalseTotal
unless $h->has_type($old) 0 24 24
218 24 ▶ unless (defined($old) && defined($new)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $old and defined $new) 0 24 24
Condition33%1/3
defined $old and defined $new
!ll&&!rl&&r
0024
MC/DC0%0/2
defined $old and defined $new
defined $old defined $new
Truth table33%1/3
A and B
A= defined $oldB= defined $new
ABresult
0X0
100
111
219 0 carp("cannot add undefined type");
220 0 return $h;
221 }
222 24 $h->{types}{$new} = $new;
223 24 foreach (qw(parents children attrs)) {
224 72 ▶ if (exists($h->{$_}{$old})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h->{$_}{$old}) { } 48 24 72
225 48 $h->{$_}{$new} = $h->{$_}{$old};
226 48 delete($h->{$_}{$old});
227 } else {
228 24 delete($h->{$_}{$new});
229 }
230 }
231 24 ▶ if ($old eq $h->{root}) { $h->_root($new); }
Branch: 1 branch
BranchTrueFalseTotal
if ($old eq $h->{"root"}) 21 3 24
232 24 return $h;
233 }
234  
235  
236  
237 #--------------------------------------------------------------
238 # $move($type,@newps)
239 85 ▶sub move ($$@) {
Subroutine move: called CC=7 SCAR=19.7
Pod documented
240 85 my $self = shift;
241 85 my $type = shift;
242  
243 # sanity check: type existence
244 85 ▶ return $self->add($type, @_) unless ($self->has_type($type));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_type($type) 0 85 85
245 # sanity check: root node
246 85 ▶ if ($type eq $self->{root}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $self->{"root"}) 18 67 85
247 0 ▶ if (@_) { croak("Cannot move hierarchy root '$type'"); }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 18 18
248 18 else { return $self; }
249 }
250  
251 # ensure parents are well-defined & well-placed
252 67 @_ = $self->ensure_types(@_);
253  
254 67 my $kids = $self->{children};
255 67 my $prts = $self->{parents};
256 67 ▶ if (exists($prts->{$type})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $prts->{$type}) 67 0 67
257 # adjust old child-relations for moved $type
258 67 foreach (values(%{$prts->{$type}})) {
259 70 delete($kids->{$_}{$type});
260 }
261 }
262  
263 # add new child-relations for moved $type
264 67 foreach (@_) { $kids->{$_}{$type} = $type; }
265  
266 # adjust parent-relation for moved $type
267 67 %{$prts->{$type}} = map { ($_ => $_) } @_;
268  
269 67 return $self
270 }
271  
272 #--------------------------------------------------------------
273 # BUG (fixed): deleting an intermediate type orphans its descendants
274 3 ▶sub remove ($@) {
Subroutine remove: called CC=10 SCAR=24.0
Pod documented
275 3 my $self = shift;
276  
277 @_ = # sanity check
278 grep {
279 3 ▶ $self->has_type($_) &&
Condition25%2/8
$self->has_type($_) && ($_ ne $self->root || carp('attempt to remove hierarchy root!') && 0)
!ll&&!rl&&r
003
$_ ne $self->root or carp("attempt to remove hierarchy root!") and 0
l!l&&r!l&&!r
300
carp("attempt to remove hierarchy root!") and 0
!ll
00
MC/DC0%0/3
$self->has_type($_) && ($_ ne $self->root || carp('attempt to remove hierarchy root!') && 0)
$self->has_type($_) $_ ne $self->root carp("attempt to remove hierarchy root!")
Truth table25%1/4
A && B or C
A= $self->has_type($_)B= $_ ne $self->rootC= carp("attempt to remove hierarchy root!")
ABCresult
0XX0
1000
11X1
1011
280 ($_ ne $self->root ||
281 (carp("attempt to remove hierarchy root!") && 0))
282 } @_;
283  
284 3 ▶ return $self unless (@_); # not really deleting anything
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 3 3
285  
286 3 delete(@{$self->{types}}{@_});
287  
288 3 my ($kids,$parents,$deleted);
289 3 foreach $deleted (@_) {
290 # adopt orphans
291 3 $kids = $self->{children}{$deleted};
292 3 $parents = $self->{parents}{$deleted};
293 3 foreach (values(%$kids)) { # $_ is an orphaned child
294 3 ▶ $self->{parents}{$_} = {} unless (exists($self->{parents}{$_}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"parents"}{$_} 0 3 3
295 3 @{$self->{parents}{$_}}{values(%$parents)} = values(%$parents);
296 3 delete(@{$self->{parents}{$_}}{@_});
297 }
298 3 foreach (values(%$parents)) { # $_ is an adopting grandparent
299 3 ▶ $self->{children}{$_} = {} unless (exists($self->{children}{$_}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"children"}{$_} 3 0 3
300 3 @{$self->{children}{$_}}{values(%$kids)} = values(%$kids);
301 3 delete(@{$self->{children}{$_}}{@_});
302 }
303 }
304 # delete inheritance information for deleted types
305 3 delete(@{$self->{parents}}{@_});
306 3 delete(@{$self->{children}}{@_});
307  
308 3 return $self;
309 }
310  
311 #--------------------------------------------------------------
312 # $h1->assign($h2)
313 18 ▶sub assign ($$) {
Subroutine assign: called CC=3 SCAR=22.1
Pod documented
314 18 my ($h1,$h2) = @_;
315 18 ▶ return $h1->SUPER::assign($h2) unless ($h2->isa($h1));
Branch: 1 branch
BranchTrueFalseTotal
unless $h2->isa($h1) 18 0 18
316 0 $h1->clear();
317 0 %{$h1->{types}} = %{$h2->{types}};
318 0 $h1->_root($h2->{root});
319 0 foreach (values(%{$h1->{types}})) {
320 0 %{$h1->{parents}{$_}} = %{$h2->{parents}{$_}};
321 0 %{$h1->{children}{$_}} = %{$h2->{children}{$_}};
322 }
323 # assign attributes
324 0 %{$h1->_attributes} = %{$h2->_attributes};
325 0 %{$h1->_hattributes} = %{$h2->_hattributes};
326 0 delete($h1->_attributes->{$h2});
327 0 return $h1;
328 }
329  
330  
331  
332 #--------------------------------------------------------------
333 # $h1->merge($h2,...)
334 15 ▶sub merge ($@) {
Subroutine merge: called CC=7 SCAR=31.6
Pod documented
335 15 my $h1 = shift;
336  
337 15 my ($a2);
338 15 ▶ while ($h2 = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h2 = shift()) 15 15 30
339 15 ▶ unless ($h2->isa($h1)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($h2->isa($h1)) 15 0 15
340 15 $h1->SUPER::merge($h2);
341 15 next;
342 }
343  
344 # add all types
345 0 @{$h1->{types}}{$h2->types} = $h2->types;
346  
347 # adopt $h2->root under $h1->root if they differ
348 0 ▶ $h1->move($h2->{root}) unless ($h1->{root} eq $h2->{root});
Branch: 1 branch
BranchTrueFalseTotal
unless $h1->{"root"} eq $h2->{"root"} 0 0 0
349  
350 # merge/override hierarchy-attributes
351 0 %{$h1->_hattributes} = (%$h1->_hattributes, %{$h2->_hattributes});
352  
353 # merge in all parent-child relations and attributes
354 0 foreach (values(%{$h2->{types}})) {
355  
356 # parents
357 0 @{$h1->{parents}{$_}}{$h2->parents($_)} = $h2->parents($_);
358  
359 # children
360 0 @{$h1->{children}{$_}}{$h2->children($_)} = $h2->children($_);
361  
362 # attributes
363 0 ▶ if (defined($a2 = $h2->_attributes($_)) && %$a2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($a2 = $h2->_attributes($_)) and %$a2) 0 0 0
Condition0%0/3
defined($a2 = $h2->_attributes($_)) and %$a2
!ll&&!rl&&r
000
MC/DC0%0/2
defined($a2 = $h2->_attributes($_)) and %$a2
defined($a2 = $h2->_attributes($_)) %$a2
Truth table0%0/3
A and B
A= defined($a2 = $h2->_attributes($_))B= %$a2
ABresult
0X0
100
111
364 0 @{$h1->{attrs}{$_}}{keys(%$a2)} = values(%$a2);
365 }
366 }
367 }
368 15 return $h1;
369 }
370  
371 #--------------------------------------------------------------
372 # $h->clear
373 21 ▶sub clear ($) {
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
374 21 my $self = shift;
375 21 %{$self->{types}} = ();
376 21 %{$self->{parents}} = ();
377 21 %{$self->{children}} = ();
378 21 %{$self->{attributes}} = ();
379  
380 21 my $hattrs = $self->_hattributes; # save this reference!
381 21 %{$self->{attrs}} = ();
382 21 %$hattrs = ();
383 21 $self->_hattributes($hattrs);
384  
385  
386 # make sure we still have the root type!
387 21 $self->_root($self->root);
388  
389 21 return $self;
390 }
391  
392 # end manipulation
393  
394  
395  
396 ###############################################################
397 # additional sorting / comparison
398 ###############################################################
399  
400 # $h->_minimize($hashref)
401 0 ▶sub _minimize ($$) {
Subroutine _minimize: not called CC=7 SCAR=40.3
402 0 my ($self,$hash) = @_;
403 0 my ($t1,$t2);
404 0 my @members = values(%$hash);
405 MINIMIZE_T1:
406 0 foreach $t1 (@members) {
407 0 ▶ next unless (exists($hash->{$t1}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{$t1} 0 0 0
408 0 ▶ unless ($self->has_type($t1)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_type($t1)) 0 0 0
409 # sanity check
410 0 delete($hash->{$t1});
411 0 next;
412 }
413 0 foreach $t2 (@members) {
414 0 ▶ next unless (exists($hash->{$t2}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{$t2} 0 0 0
415 0 ▶ if ($self->has_ancestor($t1,$t2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_ancestor($t1, $t2)) 0 0 0
416 0 delete($hash->{$t1});
417 0 next MINIMIZE_T1;
418 }
419 }
420 }
421 0 return $hash;
422 }
423  
424 # $h->_maximize($hashref)
425 0 ▶sub _maximize ($$) {
Subroutine _maximize: not called CC=7 SCAR=40.3
426 0 my ($self,$hash) = @_;
427 0 my ($t1,$t2);
428 0 my @members = values(%$hash);
429 MAXIMIZE_T1:
430 0 foreach $t1 (@members) {
431 0 ▶ next unless (exists($hash->{$t1}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{$t1} 0 0 0
432 0 ▶ unless ($self->has_type($t1)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_type($t1)) 0 0 0
433 # sanity check
434 0 delete($hash->{$t1});
435 0 next;
436 }
437 0 foreach $t2 (@members) {
438 0 ▶ next unless (exists($hash->{$t2}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{$t2} 0 0 0
439 0 ▶ if ($self->has_descendant($t1,$t2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_descendant($t1, $t2)) 0 0 0
440 0 delete($hash->{$t1});
441 0 next MAXIMIZE_T1;
442 }
443 }
444 }
445 0 return $set;
446 }
447  
448 # end sorting/comparison
449  
450  
451 ###############################################################
452 # unsorted
453 ###############################################################
454  
455 ###############################################################
456 # Type operations
457 ###############################################################
458  
459 #--------------------------------------------------------------
460 # lub : inherited
461  
462 #--------------------------------------------------------------
463 # glb : inherited
464  
465  
466  
467 ###############################################################
468 # Accessors/manipulators
469 ###############################################################
470 0 ▶sub _types ($) { return $_[0]->{types}; }
Subroutine _types: not called CC=1 SCAR=6.9
471  
472 134 ▶sub _root ($;$) {
Subroutine _root: called CC=5 SCAR=16.1
473 134 my $self = shift;
474 134 ▶ return $self->{root} unless (@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 59 75 134
475 75 my $root = shift(@_);
476 75 ▶ $root = 'BOTTOM' unless (defined($root));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root 0 75 75
477 75 $self->{types}{$root} = $root;
478 75 ▶ $self->{parents}{$root} = {} unless (defined($self->{parents}{$root}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"parents"}{$root} 69 6 75
479 75 ▶ $self->{children}{$root} = {} unless (defined($self->{children}{$root}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"children"}{$root} 69 6 75
480 75 return $self->{root} = $root;
481 }
482 7 *root = \&_root;
483  
484 # \%prts_by_type = $h->_parents()
485 # \%type_prts = $h->_parents($type)
486 0 ▶sub _parents ($;$) {
Subroutine _parents: not called CC=3 SCAR=24.8
487 return
488 (exists($_[1])
489 ? (exists($_[0]->{parents}{$_[1]})
490 ? $_[0]->{parents}{$_[1]}
491 : undef)
492 0 ▶ : $_[0]->{parents});
Branch: 2 branches
BranchTrueFalseTotal
exists $_[1] ? : 0 0 0
exists $_[0]{'parents'}{$_[1]} ? : 0 0 0
493 }
494  
495 # \%kids_by_type = $h->_children()
496 # \%type_kids = $h->children($type)
497 0 ▶sub _children ($;$) {
Subroutine _children: not called CC=3 SCAR=24.8
498 return
499 (exists($_[1])
500 ? (exists($_[0]->{children}{$_[1]})
501 ? $_[0]->{children}{$_[1]}
502 : undef)
503 0 ▶ : $_[0]->{children});
Branch: 2 branches
BranchTrueFalseTotal
exists $_[1] ? : 0 0 0
exists $_[0]{'children'}{$_[1]} ? : 0 0 0
504 }
505  
506  
507 # * C<_attributes()>, C<_attributes($type)>, C<_attributes($type, $hashref)>
508 633 ▶sub _attributes ($;$$) {
Subroutine _attributes: called CC=5 SCAR=19.7
509 return
510 (exists($_[1])
511 ? (defined($_[1])
512 ? (exists($_[2])
513 ? (defined($_[2])
514 ? $_[0]->{attrs}{$_[1]} = $_[2]
515 : delete($_[0]->{attrs}{$_[1]}))
516 : $_[0]->{attrs}{$_[1]})
517 : undef)
518 633 ▶ : $_[0]->{attrs});
Branch: 4 branches
BranchTrueFalseTotal
exists $_[1] ? : 283 350 633
defined $_[1] ? : 283 0 283
exists $_[2] ? : 0 283 283
defined $_[2] ? : 0 0 0
519 }
520  
521  
522 7 1;
523 __END__
« PartialOrder/Base.pm ↑ Summary PartialOrder/Caching.pm »