| 1 | package PMLTQ::Relation::DescendantIteratorWithBoundedDepth; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | our $AUTHORITY = 'cpan:MATY'; | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | $PMLTQ::Relation::DescendantIteratorWithBoundedDepth::VERSION = '1.5.0'; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Iterates over descendant nodes in given boundaries | ||||||||||||||||||||||||||||||||||||||||||||||
| 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 DEPTH=>3; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | ▶ | use constant NODE=>4; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use constant FILE=>5; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | my ($class,$conditions,$min,$max)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | croak "usage: $class->new(sub{...})" unless ref($conditions) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $min||=0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$min ||= 0
MC/DC0%0/1
$min ||= 0
$min
Truth table0%0/2
A
A= $min
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | return bless [$conditions,$min,$max],$class; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub clone { | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | return bless [$self->[CONDITIONS],$self->[MIN],$self->[MAX]], ref($self); | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my ($self,$parent,$fsfile)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $self->[FILE]=$fsfile; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $n=$parent->firstson; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $self->[DEPTH]=1; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $self->[NODE]=$n; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | return ($self->[MIN]<=1 and $self->[CONDITIONS]->($n,$fsfile)) ? $n : ($n && $self->next); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->[1] <= 1 and $self->[0]->($n, $fsfile)
$n and $self->next
MC/DC0%0/2
$self->[1] <= 1 and $self->[0]->($n, $fsfile)
$self->[1] <= 1
$self->[0]->($n, $fsfile)
MC/DC0%0/2
$n and $self->next
$n
$self->next
Truth table0%0/3
A and B
A= $self->[1] <= 1B= $self->[0]->($n, $fsfile)
Truth table0%0/3
A and B
A= $nB= $self->next
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | sub next { | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $min = $self->[MIN]; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $max = $self->[MAX]; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $depth = $self->[DEPTH]; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $conditions=$self->[CONDITIONS]; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $n = $self->[NODE]; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $fsfile=$self->[FILE]; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $r; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | SEARCH: | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | while ($n) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ((!defined($max) or ($depth<$max)) and $n->firstson) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
!defined($max) || $depth < $max and $n->firstson
not defined $max or $depth < $max
MC/DC0%0/3
!defined($max) || $depth < $max and $n->firstson
not defined $max
$depth < $max
$n->firstson
Truth table0%0/5
not(A) or B and C
A= not defined $maxB= $depth < $maxC= $n->firstson
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $n=$n->firstson; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $depth++; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | while ($n) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($depth == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | undef $n; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | last SEARCH; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($r = $n->rbrother) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $n=$r; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $n=$n->parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $depth--; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($n and $min<=$depth and $conditions->($n,$fsfile)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$n and $min <= $depth and &$conditions($n, $fsfile)
$n and $min <= $depth
MC/DC0%0/3
$n and $min <= $depth and &$conditions($n, $fsfile)
$n
$min <= $depth
&$conditions($n, $fsfile)
Truth table0%0/4
A and B and C
A= $nB= $min <= $depthC= &$conditions($n, $fsfile)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $self->[DEPTH]=$depth; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $self->[NODE]=$n; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return $self->[NODE]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | sub file { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return $_[0]->[FILE]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | sub node { | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return $_[0]->[NODE]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | sub reset { | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $self->[NODE]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->[FILE]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 12 | 1; # End of PMLTQ::Relation::DescendantIteratorWithBoundedDepth | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||