blib/lib/PMLTQ/Relation/TransitiveIterator.pm

filter: Statementstmt 36.2% 45 / 124 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 63.6% 14 / 22 Podpod 0.0% 0 / 7 totaltotal 24.6% 59 / 239 CC 33 SCAR 54.9
CC
33
Cov
23%
next
552.0
start
42.0
new
20.0
CRAP 242.1
« blib/lib/PMLTQ/CGI.pm ↑ Summary blib/lib/PMLTQ/Relation/SiblingIteratorWithDistance.pm »
1 package PMLTQ::Relation::TransitiveIterator;
2 12 our $AUTHORITY = 'cpan:MATY';
3 12 $PMLTQ::Relation::TransitiveIterator::VERSION = '1.5.0';
4 # ABSTRACT: Iterates over nodes that are transitive
5  
6 12 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 ▶use base qw(PMLTQ::Relation::Iterator);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use constant CONDITIONS=>0;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use constant ITERATOR=>1;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶use constant MIN=>2;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 12 ▶use constant MAX=>3;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 12 ▶use constant ITER_STACK=>4;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 12 ▶use constant SEEN=>5;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 12 ▶use constant FILE=>6;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶use constant DEPTH=>7;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 ▶use constant FOUND=>8;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 12 our $DEBUG; ### newly added
23  
24 sub new {
25 0 ▶ my ($class,$iterator,$min,$max)=@_;
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
26 0 ▶ confess "usage: $class->new(\$iterator,\$min,\$max)" unless UNIVERSAL::DOES::does($iterator,'PMLTQ::Relation::Iterator');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::DOES::does($iterator, "PMLTQ::Relation::Iterator") 0 0 0
27 0 ▶ $min||=1;
Condition0%0/2
$min ||= 1
l!l
00
MC/DC0%0/1
$min ||= 1
$min
Truth table0%0/2
A
A= $min
Aresult
11
00
28 0 my $conditions = $iterator->conditions;
29 0 ▶ $iterator->set_conditions(sub{1});
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 ▶ warn "blessed $iterator,$min,$max,0.\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::Relation::TransitiveIterator::DEBUG 0 0 0
31 0 return bless [$conditions,$iterator,$min,$max,0],$class;
32 }
33 sub clone {
34 0 ▶ my ($self)=@_;
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
35 0 return bless [$self->[CONDITIONS],$self->[ITERATOR],$self->[MIN],$self->[MAX]], ref($self);
36 }
37 sub start {
38 0 ▶ my ($self,$parent,$fsfile)=@_;
Subroutine start: not called CC=6 SCAR=37.4
Pod undocumented
39 0 $self->[FILE]=$fsfile;
40 0 my $conditions = $self->[CONDITIONS];
41 0 my $seen = $self->[SEEN]={};
42 0 my $iter = $self->[ITERATOR]->clone();
43 0 my $iterators = $self->[ITER_STACK]=[ $iter ];
44 0 my $n = $iter->start($parent,$fsfile);
45 0 $seen->{$n}=1;
46 0 $self->[DEPTH] = 1;
47 0 my $found = $self->[FOUND]={};
48 0 ▶ warn "START $parent->{id},".($n?$n->{id}:q//).".\n" if $DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $PMLTQ::Relation::TransitiveIterator::DEBUG 0 0 0
$n ? : 0 0 0
49 0 ▶ $found->{$n}=1 if $conditions->($n, $iter->file);
Branch: 1 branch
BranchTrueFalseTotal
if &$conditions($n, $iter->file) 0 0 0
50 0 ▶ return $self->[MIN]<=1 && scalar(keys %$found) > 0 ? $n : $self->next;
Branch: 1 branch
BranchTrueFalseTotal
$self->[2] <= 1 && scalar keys %$found > 0 ? : 0 0 0
Condition0%0/3
$self->[2] <= 1 and scalar keys %$found > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->[2] <= 1 and scalar keys %$found > 0
$self->[2] <= 1 scalar keys %$found > 0
Truth table0%0/3
A and B
A= $self->[2] <= 1B= scalar keys %$found > 0
ABresult
0X0
100
111
51 }
52 sub next {
53 0 ▶ my ($self)=@_;
Subroutine next: not called CC=23 SCAR=63.1
Pod undocumented
54 0 my $depth = $self->[DEPTH];
55 0 my $found = $self->[FOUND];
56 0 ▶ return if $depth<1;
Branch: 1 branch
BranchTrueFalseTotal
if $depth < 1 0 0 0
57 0 my $seen = $self->[SEEN];
58 0 my $conditions = $self->[CONDITIONS];
59 0 my $iterators = $self->[ITER_STACK];
60 0 my $iter = $iterators->[-1];
61 0 my $min = $self->[MIN];
62 0 my $max = $self->[MAX];
63 0 my $n = $iter->node;
64 0 ▶ warn "NEXT: $min,$max: $n->{id} (depth $depth)\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::Relation::TransitiveIterator::DEBUG 0 0 0
65 0 ▶ while ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
66 0 ▶ if (!$max or $depth<$max) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $max or $depth < $max) 0 0 0
Condition0%0/3
not $max or $depth < $max
l!l&&r!l&&!r
000
MC/DC0%0/2
not $max or $depth < $max
not $max $depth < $max
Truth table0%0/3
not(A) or B
A= not $maxB= $depth < $max
ABresult
1X1
011
000
67 # prolong the iteratator (depth first)
68 0 my $new_it = $self->[ITERATOR]->clone();
69 0 my $new_n = $new_it->start($n,$self->[FILE]);
70 0 ▶ $new_n = $new_it->next while ($new_n and $seen->{$new_n});
Branch: 1 branch
BranchTrueFalseTotal
$new_n and $seen->{$new_n} and do { $new_n = $new_it->next } 0 0 0
Condition0%0/3
$new_n and $seen->{$new_n}
!ll&&!rl&&r
000
MC/DC0%0/2
$new_n and $seen->{$new_n}
$new_n $seen->{$new_n}
Truth table0%0/3
A and B
A= $new_nB= $seen->{$new_n}
ABresult
0X0
100
111
71 0 ▶ warn "NEWN $n->{id}" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::Relation::TransitiveIterator::DEBUG 0 0 0
72 0 ▶ if ($new_n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_n) 0 0 0
73 0 push @$iterators, $new_it;
74 0 $n = $new_n;
75 0 $seen->{$n}=1;
76 0 $iter = $new_it;
77 0 $depth ++;
78 0 ▶ $found->{$n}=1 if $conditions->($new_n, $new_it->file);
Branch: 1 branch
BranchTrueFalseTotal
if &$conditions($new_n, $new_it->file) 0 0 0
79 0 ▶ next if scalar(keys %$found)<$min;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %$found < $min 0 0 0
80 0 last;
81 }
82 }
83 # continue top-level iterator (go breadth)
84 0 delete $seen->{$n};
85 0 $n = $iter->next;
86 0 ▶ $n = $n->next while ($n and $seen->{$n});
Branch: 1 branch
BranchTrueFalseTotal
$n and $seen->{$n} and do { $n = $n->next } 0 0 0
Condition0%0/3
$n and $seen->{$n}
!ll&&!rl&&r
000
MC/DC0%0/2
$n and $seen->{$n}
$n $seen->{$n}
Truth table0%0/3
A and B
A= $nB= $seen->{$n}
ABresult
0X0
100
111
87 0 ▶ while (!$n and $depth>1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $n and $depth > 1) 0 0 0
Condition0%0/3
not $n and $depth > 1
!ll&&!rl&&r
000
MC/DC0%0/2
not $n and $depth > 1
not $n $depth > 1
Truth table0%0/3
not(A) and B
A= not $nB= $depth > 1
ABresult
0X0
100
111
88 0 pop @$iterators; # drop current iterator
89 0 $depth --;
90 0 $iter = $iterators->[-1]; # current top-level iterator
91 0 delete $seen->{ $iter->node };
92 0 delete $found->{ $iter->node };
93 0 $n = $iter->next;
94 0 ▶ $n = $n->next while ($n and $seen->{$n});
Branch: 1 branch
BranchTrueFalseTotal
$n and $seen->{$n} and do { $n = $n->next } 0 0 0
Condition0%0/3
$n and $seen->{$n}
!ll&&!rl&&r
000
MC/DC0%0/2
$n and $seen->{$n}
$n $seen->{$n}
Truth table0%0/3
A and B
A= $nB= $seen->{$n}
ABresult
0X0
100
111
95 }
96 0 ▶ $seen->{$n}=1 if $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n 0 0 0
97 0 ▶ last unless (scalar(keys %$found)<$min and
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %$found < $min and scalar keys %$found >= 1 0 0 0
Condition0%0/3
scalar keys %$found < $min and scalar keys %$found >= 1
!ll&&!rl&&r
000
MC/DC0%0/2
scalar keys %$found < $min and scalar keys %$found >= 1
scalar keys %$found < $min scalar keys %$found >= 1
Truth table0%0/3
A and B
A= scalar keys %$found < $minB= scalar keys %$found >= 1
ABresult
0X0
100
111
98 scalar(keys %$found)>=1); # prolong if found but not long enough
99 }
100 0 $self->[DEPTH]=$depth;
101 0 ▶ warn 'NEXT RETURN ',$n?$n->{id}:'empty',".\n" if $DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $PMLTQ::Relation::TransitiveIterator::DEBUG 0 0 0
$n ? : 0 0 0
102 0 return $n;
103 }
104 sub node {
105 0 ▶ my ($self)=@_;
Subroutine node: not called CC=2 SCAR=17.9
Pod undocumented
106 0 ▶ if ($self->[DEPTH]>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[7] > 0) { } 0 0 0
107 0 return $self->[ITER_STACK][-1]->node;
108 } else {
109 0 return undef;
110 }
111 }
112 sub file {
113 0 ▶ my ($self)=@_;
Subroutine file: not called CC=2 SCAR=17.9
Pod undocumented
114 0 ▶ if ($self->[DEPTH]>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[7] > 0) { } 0 0 0
115 0 return $self->[ITER_STACK][-1]->file;
116 } else {
117 0 return undef;
118 }
119 }
120 sub reset {
121 0 ▶ my ($self)=@_;
Subroutine reset: not called CC=1 SCAR=6.9
Pod undocumented
122 0 $self->[FILE]=undef;
123 0 $self->[ITER_STACK]=undef;
124 0 $self->[DEPTH]=undef;
125 0 $self->[SEEN]=undef;
126 }
127  
128 12 1; # End of PMLTQ::Relation::TransitiveIterator
129  
130 __END__
« blib/lib/PMLTQ/CGI.pm ↑ Summary blib/lib/PMLTQ/Relation/SiblingIteratorWithDistance.pm »