| 1 | package Tree::Simple::Visitor::BreadthFirstTraversal; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | our $VERSION = '0.16'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use base qw(Tree::Simple::Visitor); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 6 | my ($_class) = @_; | |||||||||||||||||||||||||||
| 14 | 6 | ▶ | my $class = ref($_class) || $_class; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $_class || $_class
MC/DC0%0/2
ref $_class || $_class
ref $_class
$_class
Truth table33%1/3
A || B
A= ref $_classB= $_class
| |||||||||||||||||||||||||||||
| 15 | 6 | my $visitor = {}; | |||||||||||||||||||||||||||
| 16 | 6 | bless($visitor, $class); | |||||||||||||||||||||||||||
| 17 | 6 | $visitor->_init(); | |||||||||||||||||||||||||||
| 18 | 6 | return $visitor; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 6 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 23 | 6 | $self->SUPER::_init(); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 11 | ▶ | sub visit { | ||||||||||||||||||||||||||
|
Subroutine
visit: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 11 | my ($self, $tree) = @_; | |||||||||||||||||||||||||||
| 28 | 11 | ▶ | (blessed($tree) && $tree->isa("Tree::Simple")) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($tree) and $tree->isa("Tree::Simple")
MC/DC100%2/2
builtin::blessed($tree) and $tree->isa("Tree::Simple")
builtin::blessed($tree)
$tree->isa("Tree::Simple")
Truth table100%3/3
A and B
A= builtin::blessed($tree)B= $tree->isa("Tree::Simple")
| |||||||||||||||||||||||||||||
| 29 | || die "Insufficient Arguments : You must supply a valid Tree::Simple object"; | ||||||||||||||||||||||||||||
| 30 | # create a holder for our results | ||||||||||||||||||||||||||||
| 31 | 7 | my @results; | |||||||||||||||||||||||||||
| 32 | # get our filter function | ||||||||||||||||||||||||||||
| 33 | 7 | my $filter_function = $self->getNodeFilter(); | |||||||||||||||||||||||||||
| 34 | # now create a queue for | ||||||||||||||||||||||||||||
| 35 | # processing depth first | ||||||||||||||||||||||||||||
| 36 | 7 | my @queue; | |||||||||||||||||||||||||||
| 37 | # if we are to include the trunk | ||||||||||||||||||||||||||||
| 38 | 7 | ▶ | if ($self->includeTrunk()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | # then enqueue that | ||||||||||||||||||||||||||||
| 40 | 3 | @queue = ($tree); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | # if we are not including the trunk | ||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||
| 44 | # then we enqueue all the | ||||||||||||||||||||||||||||
| 45 | # trunks children instead | ||||||||||||||||||||||||||||
| 46 | 4 | @queue = ($tree->getAllChildren()); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | # until our queue is empty | ||||||||||||||||||||||||||||
| 49 | 7 | ▶ | while (scalar(@queue) != 0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | # get the first item off the queue | ||||||||||||||||||||||||||||
| 51 | 78 | my $current_tree = shift @queue; | |||||||||||||||||||||||||||
| 52 | # enqueue all the current tree's children | ||||||||||||||||||||||||||||
| 53 | 78 | push @queue => $current_tree->getAllChildren(); | |||||||||||||||||||||||||||
| 54 | # now collect the results | ||||||||||||||||||||||||||||
| 55 | 78 | ▶ | push @results => (($filter_function) ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | $filter_function->($current_tree) | ||||||||||||||||||||||||||||
| 57 | : | ||||||||||||||||||||||||||||
| 58 | $current_tree->getNodeValue()); | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | # store our results | ||||||||||||||||||||||||||||
| 61 | 3 | $self->setResults(@results); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 4 | 1; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||