Visitor/GetAllDescendents.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 8 / 8 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 94.8% 73 / 77 CC 8 SCAR 8.3
CC
8
Cov
96%
visit
4.0
setTraversalMethod
3.0
new
2.0
CRAP 2.3
« Visitor/Sort.pm ↑ Summary VisitorFactory.pm »
1 package Tree::Simple::Visitor::GetAllDescendents;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '0.16';
7  
8 3 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use base qw(Tree::Simple::Visitor);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
13 7 my ($_class) = @_;
14 7 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
070
MC/DC0%0/2
ref $_class || $_class
ref $_class $_class
Truth table33%1/3
A || B
A= ref $_classB= $_class
ABresult
1X1
011
000
15 7 my $visitor = {};
16 7 bless($visitor, $class);
17 7 $visitor->_init();
18 7 return $visitor;
19 }
20  
21 7 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
22 7 my ($self) = @_;
23 7 $self->{traversal_method} = undef;
24 7 $self->SUPER::_init();
25 }
26  
27 5 ▶sub setTraversalMethod {
Subroutine setTraversalMethod: called CC=3 SCAR=11.0
Pod documented
28 5 my ($self, $visitor) = @_;
29 5 ▶ (blessed($visitor) && $visitor->isa("Tree::Simple::Visitor"))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($visitor) and $visitor->isa("Tree::Simple::Visitor") or die "Insufficient Arguments : You must supply a valid Tree::Simple::Visitor object" 1 4 5
Condition100%3/3
builtin::blessed($visitor) and $visitor->isa("Tree::Simple::Visitor")
!ll&&!rl&&r
311
MC/DC100%2/2
builtin::blessed($visitor) and $visitor->isa("Tree::Simple::Visitor")
builtin::blessed($visitor) $visitor->isa("Tree::Simple::Visitor")
Truth table100%3/3
A and B
A= builtin::blessed($visitor)B= $visitor->isa("Tree::Simple::Visitor")
ABresult
0X0
100
111
30 || die "Insufficient Arguments : You must supply a valid Tree::Simple::Visitor object";
31 1 $self->{traversal_method} = $visitor;
32 }
33  
34 13 ▶sub visit {
Subroutine visit: called CC=4 SCAR=13.9
Pod documented
35 13 my ($self, $tree) = @_;
36 13 ▶ (blessed($tree) && $tree->isa("Tree::Simple"))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($tree) and $tree->isa("Tree::Simple") or die "Insufficient Arguments : You must supply a valid Tree::Simple object" 9 4 13
Condition100%3/3
builtin::blessed($tree) and $tree->isa("Tree::Simple")
!ll&&!rl&&r
319
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")
ABresult
0X0
100
111
37 || die "Insufficient Arguments : You must supply a valid Tree::Simple object";
38 # create an closure for the
39 # collection function
40 9 my @descendents;
41 9 my $filter_function = $self->getNodeFilter();
42 # build a collection function
43 225 ▶ my $collection_function = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
44 225 my ($t) = @_;
45 225 ▶ push @descendents => ($filter_function ?
Branch: 1 branch
BranchTrueFalseTotal
$filter_function ? : 30 195 225
46 $filter_function->($t)
47 :
48 $t->getNodeValue());
49 9 };
50 # and collect our descendents with the
51 # traversal method specified
52 9 ▶ unless (defined($self->{traversal_method})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'traversal_method'}) { } 1 8 9
53 8 $tree->traverse($collection_function);
54 }
55 else {
56 1 $self->{traversal_method}->setNodeFilter($collection_function);
57 1 $self->{traversal_method}->visit($tree);
58 }
59 # now store our collected descendents
60 9 $self->setResults(@descendents);
61 }
62  
63 6 ▶sub getAllDescendents {
Subroutine getAllDescendents: called CC=1 SCAR=0.0
Pod documented
64 6 my ($self) = @_;
65 6 return $self->getResults();
66 }
67  
68 3 1;
69  
70 __END__
« Visitor/Sort.pm ↑ Summary VisitorFactory.pm »