« blib/lib/PMLTQ/Relation/TransitiveIterator.pm
↑ Summary
blib/lib/PMLTQ/Relation/DepthFirstRangeIterator.pm »
| 1 | package PMLTQ::Relation::SiblingIteratorWithDistance; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | our $AUTHORITY = 'cpan:MATY'; | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | $PMLTQ::Relation::SiblingIteratorWithDistance::VERSION = '1.2.2'; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Iterates over siblings given node with boudaries | ||||||||||||||||||||||||||||||||||||||||||||||
| 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 Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | ▶ | use constant CONDITIONS=>0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | ▶ | use constant MIN=>1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use constant MAX=>2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | use constant NODE=>3; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | ▶ | use constant DIST=>4; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use constant FILE=>5; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | ▶ | use constant START=>6; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my ($class,$conditions,$min,$max)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | croak "usage: $class->new(sub{...})" unless ref($conditions) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $min||=0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$min ||= 0
MC/DC0%0/1
$min ||= 0
$min
Truth table0%0/2
A
A= $min
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | return bless [$conditions,$min,$max],$class; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub clone { | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return bless [$self->[CONDITIONS],$self->[MIN],$self->[MAX]], ref($self); | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # the iterator will first go right from the start node, | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # then left | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my ($self,$node,$fsfile)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: not called CC=20 SCAR=60.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $min = $self->[MIN]; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $max = $self->[MAX]; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $self->[FILE]=$fsfile; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $self->[START]=$node; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | # -10, means -10 to +infty | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # -10,0 means in fact -10,-1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # ,10, means -infty to 10, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # 0,10 means 1,10 | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # ,-10 means -infty to -10 | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # N,M with N=M=0 or M<N is never satisfied | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | return if (defined($min) and defined($max) and $min>$max); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $min and defined $max and $min > $max
defined $min and defined $max
MC/DC0%0/3
defined $min and defined $max and $min > $max
defined $min
defined $max
$min > $max
Truth table0%0/4
A and B and C
A= defined $minB= defined $maxC= $min > $max
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $dist=1; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $n=$node->rbrother; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (defined($min) and $min>$dist) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $min and $min > $dist
MC/DC0%0/2
defined $min and $min > $dist
defined $min
$min > $dist
Truth table0%0/3
A and B
A= defined $minB= $min > $dist
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $n = $n->rbrother while ($n and ($dist++)<$min); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$n and $dist++ < $min
MC/DC0%0/2
$n and $dist++ < $min
$n
$dist++ < $min
Truth table0%0/3
A and B
A= $nB= $dist++ < $min
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $n=undef 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (!$n) { # try going left | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $dist = -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $n=$node->lbrother; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if (defined($max) and $max<$dist) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $max and $max < $dist
MC/DC0%0/2
defined $max and $max < $dist
defined $max
$max < $dist
Truth table0%0/3
A and B
A= defined $maxB= $max < $dist
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $n = $n->lbrother while ($n and ($dist--)>$max); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$n and $dist-- > $max
MC/DC0%0/2
$n and $dist-- > $max
$n
$dist-- > $max
Truth table0%0/3
A and B
A= $nB= $dist-- > $max
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $n=undef if defined($min) and $dist<$min; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $min and $dist < $min
MC/DC0%0/2
defined $min and $dist < $min
defined $min
$dist < $min
Truth table0%0/3
A and B
A= defined $minB= $dist < $min
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $self->[NODE]=$n; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $self->[DIST]=$dist; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | sub next { | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $conditions=$self->[CONDITIONS]; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $max = $self->[MAX]; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $min = $self->[MIN]; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $dist = $self->[DIST]; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $fsfile = $self->[FILE]; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $n=$self->[NODE]; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ($dist>0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # advance right | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | while ($n) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $n=$n->rbrother; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $dist++; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($conditions->($n,$fsfile)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->[DIST]=$dist; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return $self->[NODE]=$n; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # return to start node | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $dist = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $n=$self->[START]; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (defined($max) and $max+1<$dist) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $max and $max + 1 < $dist
MC/DC0%0/2
defined $max and $max + 1 < $dist
defined $max
$max + 1 < $dist
Truth table0%0/3
A and B
A= defined $maxB= $max + 1 < $dist
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $n = $n->lbrother while ($n and $max+1<$dist--); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$n and $max + 1 < $dist--
MC/DC0%0/2
$n and $max + 1 < $dist--
$n
$max + 1 < $dist--
Truth table0%0/3
A and B
A= $nB= $max + 1 < $dist--
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # advance left | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | while ($n) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $n=$n->lbrother; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $dist--; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | last if defined($min) and $dist<$min; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $min and $dist < $min
MC/DC0%0/2
defined $min and $dist < $min
defined $min
$dist < $min
Truth table0%0/3
A and B
A= defined $minB= $dist < $min
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($conditions->($n,$fsfile)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $self->[DIST]=$dist; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return $self->[NODE]=$n; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $self->[DIST]=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | return $_[0]->[NODE]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | sub node { | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return $_[0]->[NODE]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | sub file { | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | return $_[0]->[FILE]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | sub reset { | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->[NODE]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->[FILE]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->[START]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->[DIST]=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 12 | 1; # End of PMLTQ::Relation::SiblingIteratorWithDistance | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||