| 1 | package PMLTQ::Relation::DepthFirstRangeIterator; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | our $AUTHORITY = 'cpan:MATY'; | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | $PMLTQ::Relation::DepthFirstRangeIterator::VERSION = '1.5.0'; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Iterates tree using depth first search in given boundaries | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | ▶ | use base qw(PMLTQ::Relation::Iterator); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | ▶ | use constant CONDITIONS=>0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use constant LMIN =>1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | use constant LMAX =>2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | ▶ | use constant RMIN =>3; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use constant RMAX =>4; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | ▶ | use constant DIST =>5; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | ▶ | use constant NODE=>6; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 12 | ▶ | use constant FILE=>7; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | ▶ | use constant START=>8; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my ($class,$conditions,$lmin,$lmax,$rmin,$rmax)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | croak "usage: $class->new(sub{...})" unless ref($conditions) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | return bless [$conditions,$lmin,$lmax,$rmin,$rmax],$class; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | sub clone { | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | return bless [$self->[CONDITIONS],$self->[LMIN],$self->[LMAX],$self->[RMIN],$self->[RMAX]], ref($self); | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my ($self,$start_node,$fsfile)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: not called CC=18 SCAR=58.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ($fsfile) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $self->[FILE]=$fsfile; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $fsfile=$self->[FILE]; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $self->[START] = $start_node; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $n; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $dist=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $rmin = $self->[RMIN]; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (defined($rmin)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $n=$start_node; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | while ($n and $dist<$rmin) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$n and $dist < $rmin
MC/DC0%0/2
$n and $dist < $rmin
$n
$dist < $rmin
Truth table0%0/3
A and B
A= $nB= $dist < $rmin
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $n = $n->following; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $dist++; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $rmax = $self->[RMAX]; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | undef $n if ($n and defined($rmax) and $dist>$rmax); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$n and defined $rmax and $dist > $rmax
$n and defined $rmax
MC/DC0%0/3
$n and defined $rmax and $dist > $rmax
$n
defined $rmax
$dist > $rmax
Truth table0%0/4
A and B and C
A= $nB= defined $rmaxC= $dist > $rmax
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if (!$n) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $lmin = $self->[LMIN]; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (defined($lmin)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $dist=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $n=$start_node; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | while ($n and $dist>$lmin) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$n and $dist > $lmin
MC/DC0%0/2
$n and $dist > $lmin
$n
$dist > $lmin
Truth table0%0/3
A and B
A= $nB= $dist > $lmin
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $n = $n->previous; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $dist--; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $lmax = $self->[LMAX]; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | undef $n if ($n and defined($lmax) and $dist<$lmax); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$n and defined $lmax and $dist < $lmax
$n and defined $lmax
MC/DC0%0/3
$n and defined $lmax and $dist < $lmax
$n
defined $lmax
$dist < $lmax
Truth table0%0/4
A and B and C
A= $nB= defined $lmaxC= $dist < $lmax
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->[DIST]=$dist; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $self->[NODE]=$n; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return ($n && $self->[CONDITIONS]->($n,$fsfile)) ? $n : ($n && $self->next); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$n and $self->[0]->($n, $fsfile)
$n and $self->next
MC/DC0%0/2
$n and $self->[0]->($n, $fsfile)
$n
$self->[0]->($n, $fsfile)
MC/DC0%0/2
$n and $self->next
$n
$self->next
Truth table0%0/3
A and B
A= $nB= $self->[0]->($n, $fsfile)
Truth table0%0/3
A and B
A= $nB= $self->next
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | sub next { | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $conditions=$self->[CONDITIONS]; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $n=$self->[NODE]; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $fsfile=$self->[FILE]; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $dist=$self->[DIST]; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $max; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($dist>0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # advance right | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $max=$self->[RMAX]; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | while ($n) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $dist++; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | last if (defined($max) and $dist>$max); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $max and $dist > $max
MC/DC0%0/2
defined $max and $dist > $max
defined $max
$dist > $max
Truth table0%0/3
A and B
A= defined $maxB= $dist > $max
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $n=$n->following(); | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ($conditions->($n,$fsfile)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $self->[DIST]=$dist; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return $self->[NODE]=$n; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $lmin = $self->[LMIN]; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | unless (defined $lmin) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->[DIST]=$dist; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return($self->[NODE]=undef); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $dist = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $n = $self->[START]; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | while ($n and ($dist-1) > $lmin) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$n and $dist - 1 > $lmin
MC/DC0%0/2
$n and $dist - 1 > $lmin
$n
$dist - 1 > $lmin
Truth table0%0/3
A and B
A= $nB= $dist - 1 > $lmin
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $n = $n->previous; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $dist--; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # advance left | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $max = $self->[LMAX]; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | while ($n) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $dist--; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if (defined($max) and $dist<$max) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $max and $dist < $max
MC/DC0%0/2
defined $max and $dist < $max
defined $max
$dist < $max
Truth table0%0/3
A and B
A= defined $maxB= $dist < $max
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | undef $n; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $n=$n->previous(); | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | last if $conditions->($n,$fsfile); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->[DIST]=$dist; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | return $self->[NODE]=$n; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | sub node { | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return $_[0]->[NODE]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | sub file { | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | return $_[0]->[FILE]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | sub reset { | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->[NODE]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $self->[FILE]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->[START]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->[DIST]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 12 | 1; # End of PMLTQ::Relation::DepthFirstRangeIterator | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||