| 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
MC/DC0%0/2
ref $_class || $_class
ref $_class
$_class
Truth table33%1/3
A || B
A= ref $_classB= $_class
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
builtin::blessed($tree) and $tree->isa("Tree::Simple")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 46 | 4 | ▶ | (defined $self->{class_to_load}) || die "Insufficient Arguments : Must provide a class to load"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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'}
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'}
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # deal with the include trunk functionality | ||||||||||||||||||||||||||||
| 53 | 4 | ▶ | if ($self->includeTrunk()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | $tree->setNodeValue(defined $filter ? $filter->($class_to_load) : $class_to_load); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||
| 57 | 3 | ▶ | my $new_tree = Tree::Simple->new(defined $filter ? $filter->($class_to_load) : $class_to_load); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 3 | $tree->addChild($new_tree); | |||||||||||||||||||||||||||
| 59 | 3 | ▶ | if ($self->includeMethods()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 78 | 20 | $tree->addChild($new_tree); | |||||||||||||||||||||||||||
| 79 | 20 | ▶ | if ($self->includeMethods()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | 1; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||