Visitor/LoadClassHierarchy.pm

filter: Statementstmt 100% 70 / 70 Branchbran 73.0% 19 / 26 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 85.1% 109 / 128 CC 19 SCAR 16.6
CC
19
Cov
88%
visit
11.3
_loadClass
4.0
includeMethods
3.0
CRAP 5.2
« Visitor/FindByUID.pm ↑ Summary Visitor/LoadDirectoryTree.pm »
1 package Tree::Simple::Visitor::LoadClassHierarchy;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.16';
7  
8 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Tree::Simple::Visitor);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
13 4 my ($_class) = @_;
14 4 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
040
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 4 my $visitor = {};
16 4 bless($visitor, $class);
17 4 $visitor->_init();
18 4 return $visitor;
19 }
20  
21 4 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
22 4 my ($self) = @_;
23 4 $self->{class_to_load} = undef;
24 4 $self->{include_methods} = 0;
25 4 $self->SUPER::_init();
26 }
27  
28 4 ▶sub setClass {
Subroutine setClass: called CC=2 SCAR=7.1
Pod documented
29 4 my ($self, $class_to_load) = @_;
30 4 ▶ (defined($class_to_load)) || die "Insufficient Arguments : Must provide a class to load";
Branch: 1 branch
BranchTrueFalseTotal
defined $class_to_load or die "Insufficient Arguments : Must provide a class to load" 4 0 4
31 4 $self->{class_to_load} = $class_to_load;
32 }
33  
34 24 ▶sub includeMethods {
Subroutine includeMethods: called CC=3 SCAR=11.1
Pod documented
35 24 my ($self, $boolean) = @_;
36 24 ▶ $self->{include_methods} = ($boolean ? 1 : 0) if defined $boolean;
Branch: 2 branches
BranchTrueFalseTotal
if defined $boolean 1 23 24
$boolean ? : 1 0 1
37 24 return $self->{include_methods};
38 }
39  
40 4 ▶sub visit {
Subroutine visit: called CC=10 SCAR=24.3
Pod documented
41 4 my ($self, $tree) = @_;
42 4 ▶ (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" 4 0 4
Condition33%1/3
builtin::blessed($tree) and $tree->isa("Tree::Simple")
!ll&&!rl&&r
004
MC/DC0%0/2
builtin::blessed($tree) and $tree->isa("Tree::Simple")
builtin::blessed($tree) $tree->isa("Tree::Simple")
Truth table33%1/3
A and B
A= builtin::blessed($tree)B= $tree->isa("Tree::Simple")
ABresult
0X0
100
111
43 || die "Insufficient Arguments : You must supply a valid Tree::Simple object";
44 # it must be a leaf
45 4 ▶ ($tree->isLeaf()) || die "Illegal Operation : The tree must be a leaf node to load a class hierarchy";
Branch: 1 branch
BranchTrueFalseTotal
$tree->isLeaf or die "Illegal Operation : The tree must be a leaf node to load a class hierarchy" 4 0 4
46 4 ▶ (defined $self->{class_to_load}) || die "Insufficient Arguments : Must provide a class to load";
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"class_to_load"} or die "Insufficient Arguments : Must provide a class to load" 4 0 4
47 # get the filter
48 4 my $filter = $self->getNodeFilter();
49 # get the class to load
50 4 ▶ my $class_to_load = ref($self->{class_to_load}) || $self->{class_to_load};
Condition33%1/3
ref $self->{'class_to_load'} || $self->{'class_to_load'}
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $self->{'class_to_load'} || $self->{'class_to_load'}
ref $self->{'class_to_load'} $self->{'class_to_load'}
Truth table33%1/3
A || B
A= ref $self->{'class_to_load'}B= $self->{'class_to_load'}
ABresult
1X1
011
000
51  
52 # deal with the include trunk functionality
53 4 ▶ if ($self->includeTrunk()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->includeTrunk) { } 1 3 4
54 1 ▶ $tree->setNodeValue(defined $filter ? $filter->($class_to_load) : $class_to_load);
Branch: 1 branch
BranchTrueFalseTotal
defined $filter ? : 0 1 1
55 }
56 else {
57 3 ▶ my $new_tree = Tree::Simple->new(defined $filter ? $filter->($class_to_load) : $class_to_load);
Branch: 1 branch
BranchTrueFalseTotal
defined $filter ? : 1 2 3
58 3 $tree->addChild($new_tree);
59 3 ▶ if ($self->includeMethods()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->includeMethods) 1 2 3
60 1 $self->_loadMethods($new_tree, $class_to_load, $filter);
61 }
62 3 $tree = $new_tree;
63 }
64  
65 # and load it recursively
66 4 $self->_loadClass($tree, $class_to_load, $filter);
67 }
68  
69 24 ▶sub _loadClass {
Subroutine _loadClass: called CC=4 SCAR=13.9
70 24 my ($self, $tree, $class_to_load, $filter) = @_;
71 24 my @superclasses;
72 {
73 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 24 @superclasses = @{"${class_to_load}::ISA"};
75 }
76 24 foreach my $superclass (@superclasses) {
77 20 ▶ my $new_tree = Tree::Simple->new(defined $filter ? $filter->($superclass) : $superclass);
Branch: 1 branch
BranchTrueFalseTotal
defined $filter ? : 6 14 20
78 20 $tree->addChild($new_tree);
79 20 ▶ if ($self->includeMethods()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->includeMethods) 2 18 20
80 2 $self->_loadMethods($new_tree, $superclass, $filter);
81 }
82 20 $self->_loadClass($new_tree, $superclass, $filter);
83 }
84 }
85  
86 3 ▶sub _loadMethods {
Subroutine _loadMethods: called CC=3 SCAR=11.0
87 3 my ($self, $tree, $class, $filter) = @_;
88 3 my @methods;
89 {
90 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
91 3 @methods = sort grep { defined &{"${class}::$_"} } keys %{"${class}::"};
92 }
93 3 foreach my $method (@methods) {
94 4 ▶ $tree->addChild(Tree::Simple->new(defined $filter ? $filter->($method) : $method));
Branch: 1 branch
BranchTrueFalseTotal
defined $filter ? : 0 4 4
95 }
96 }
97  
98 1 1;
99  
100 __END__
« Visitor/FindByUID.pm ↑ Summary Visitor/LoadDirectoryTree.pm »