| 1 | package PMLTQ::Relation::AncestorIteratorWithBoundedDepth; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | our $AUTHORITY = 'cpan:MATY'; | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | $PMLTQ::Relation::AncestorIteratorWithBoundedDepth::VERSION = '1.5.0'; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Iterates over ancestor nodes to given bound | ||||||||||||||||||||||||||||||||||||||||||||||
| 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 DEPTH=>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,$node,$fsfile)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $min = $self->[MIN]||1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->[1] || 1
MC/DC0%0/1
$self->[1] || 1
$self->[1]
Truth table0%0/2
A
A= $self->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $max = $self->[MAX]; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $self->[FILE]=$fsfile; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $depth=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | while ($node and $depth<$min) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$node and $depth < $min
MC/DC0%0/2
$node and $depth < $min
$node
$depth < $min
Truth table0%0/3
A and B
A= $nodeB= $depth < $min
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $node = $node->parent ; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $depth++; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $node=undef if defined($max) and $depth>$max; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $max and $depth > $max
MC/DC0%0/2
defined $max and $depth > $max
defined $max
$depth > $max
Truth table0%0/3
A and B
A= defined $maxB= $depth > $max
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $self->[NODE]=$node; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $self->[DEPTH]=$depth; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return ($node && $self->[CONDITIONS]->($node,$fsfile)) ? $node : ($node && $self->next); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$node and $self->[0]->($node, $fsfile)
$node and $self->next
MC/DC0%0/2
$node and $self->[0]->($node, $fsfile)
$node
$self->[0]->($node, $fsfile)
MC/DC0%0/2
$node and $self->next
$node
$self->next
Truth table0%0/3
A and B
A= $nodeB= $self->[0]->($node, $fsfile)
Truth table0%0/3
A and B
A= $nodeB= $self->next
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | sub next { | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $conditions=$self->[CONDITIONS]; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $max = $self->[MAX]; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $depth = $self->[DEPTH]; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return $self->[NODE]=undef if (defined($max) and $depth>=$max); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $max and $depth >= $max
MC/DC0%0/2
defined $max and $depth >= $max
defined $max
$depth >= $max
Truth table0%0/3
A and B
A= defined $maxB= $depth >= $max
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $n=$self->[NODE]->parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $depth++; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $fsfile = $self->[FILE]; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | while ($n and !$conditions->($n,$fsfile)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$n and not &$conditions($n, $fsfile)
MC/DC0%0/2
$n and not &$conditions($n, $fsfile)
$n
not &$conditions($n, $fsfile)
Truth table0%0/3
A and not(B)
A= $nB= not &$conditions($n, $fsfile)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $depth++; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (defined($max) and $depth<=$max) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $max and $depth <= $max
MC/DC0%0/2
defined $max and $depth <= $max
defined $max
$depth <= $max
Truth table0%0/3
A and B
A= defined $maxB= $depth <= $max
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $n=$n->parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $n=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->[DEPTH]=$depth; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return $self->[NODE]=$n; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | sub node { | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return $_[0]->[NODE]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | sub file { | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return $_[0]->[FILE]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | sub reset { | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $self->[NODE]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $self->[FILE]=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 12 | 1; # End of PMLTQ::Relation::AncestorIteratorWithBoundedDepth | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||