View.pm

filter: Statementstmt 100% 49 / 49 Branchbran 88.8% 16 / 18 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 17 / 17 Podpod 100% 11 / 11 totaltotal 92.7% 102 / 110 CC 13 SCAR 8.2
CC
13
Cov
93%
_init
4.0
includeTrunk
3.2
new
3.1
CRAP 2.3
« View/DHTML.pm ↑ Summary View/Exceptions.pm »
1 package Tree::Simple::View;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 our $VERSION = '0.20';
7  
8 8 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 ▶use Tree::Simple::View::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 58 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod documented
13 58 my ($_class, $tree, %configuration) = @_;
14 58 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
0580
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 58 ▶ ($class ne 'Tree::Simple::View')
Branch: 1 branch
BranchTrueFalseTotal
$class ne "Tree::Simple::View" or "Tree::Simple::View::AbstractClass"->throw("Tree::Simple::View is an abstract class, try Tree::Simple::View::HTML or Tree::Simple::View::DHTML instead") 57 1 58
16 || throw Tree::Simple::View::AbstractClass "Tree::Simple::View is an abstract class, try Tree::Simple::View::HTML or Tree::Simple::View::DHTML instead";
17 57 my $tree_view = bless{
18 tree => undef,
19 config => {},
20 include_trunk => undef,
21 ppath_comparison_func => undef
22 } => $class;
23 57 $tree_view->_init($tree, %configuration);
24 53 return $tree_view;
25 }
26  
27 57 ▶sub _init {
Subroutine _init: called CC=4 SCAR=13.9
28 57 my ($self, $tree, %config) = @_;
29 57 ▶ (blessed($tree) && $tree->isa("Tree::Simple"))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($tree) and $tree->isa("Tree::Simple") or "Tree::Simple::View::InsufficientArguments"->throw("tree argument must be a Tree::Simple object") 53 4 57
Condition100%3/3
builtin::blessed($tree) and $tree->isa("Tree::Simple")
!ll&&!rl&&r
3153
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
30 || throw Tree::Simple::View::InsufficientArguments "tree argument must be a Tree::Simple object";
31 53 $self->{tree} = $tree;
32 53 ▶ $self->{config} = \%config if %config;
Branch: 1 branch
BranchTrueFalseTotal
if %config 38 15 53
33 53 $self->{include_trunk} = 0;
34 53 $self->{path_comparison_func} = undef;
35 }
36  
37 1 ▶sub getTree { (shift)->{tree} }
Subroutine getTree: called CC=1 SCAR=0.0
Pod documented
38 1 ▶sub getConfig { (shift)->{config} }
Subroutine getConfig: called CC=1 SCAR=0.0
Pod documented
39  
40 15 ▶sub includeTrunk {
Subroutine includeTrunk: called CC=3 SCAR=11.7
Pod documented
41 15 my ($self, $boolean) = @_;
42 15 ▶ $self->{include_trunk} = ($boolean ? 1 : 0) if defined $boolean;
Branch: 2 branches
BranchTrueFalseTotal
if defined $boolean 15 0 15
$boolean ? : 15 0 15
43 15 return $self->{include_trunk};
44 }
45  
46 4 ▶sub setPathComparisonFunction {
Subroutine setPathComparisonFunction: called CC=3 SCAR=11.0
Pod documented
47 4 my ($self, $code) = @_;
48 4 ▶ (defined($code) && ref($code) eq "CODE")
Branch: 1 branch
BranchTrueFalseTotal
defined $code and ref $code eq "CODE" or "Tree::Simple::View::InsufficientArguments"->throw("Path comparison must be a function") 3 1 4
Condition66%2/3
defined $code and ref $code eq "CODE"
!ll&&!rl&&r
103
MC/DC50%1/2
defined $code and ref $code eq "CODE"
defined $code ref $code eq "CODE"
Truth table66%2/3
A and B
A= defined $codeB= ref $code eq "CODE"
ABresult
0X0
100
111
49 || throw Tree::Simple::View::InsufficientArguments "Path comparison must be a function";
50 3 $self->{path_comparison_func} = $code;
51 }
52  
53 27 ▶sub expandPath {
Subroutine expandPath: called CC=2 SCAR=6.9
Pod documented
54 27 my ($self, @path) = @_;
55 27 ▶ return $self->expandPathComplex($self->{tree}, $self->{config}, @path) if (keys %{$self->{config}});
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"config"};} 18 9 27
56 9 return $self->expandPathSimple($self->{tree}, @path);
57 }
58  
59 # override these method
60 2 ▶sub expandPathSimple { throw Tree::Simple::View::AbstractMethod "Method Not Implemented" }
Subroutine expandPathSimple: called CC=1 SCAR=0.0
Pod documented
61 2 ▶sub expandPathComplex { throw Tree::Simple::View::AbstractMethod "Method Not Implemented" }
Subroutine expandPathComplex: called CC=1 SCAR=0.0
Pod documented
62  
63 28 ▶sub expandAll {
Subroutine expandAll: called CC=2 SCAR=6.9
Pod documented
64 28 my ($self) = @_;
65 28 ▶ return $self->expandAllComplex($self->{config}) if (keys %{$self->{config}});
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"config"};} 21 7 28
66 7 return $self->expandAllSimple();
67 }
68  
69 # override these method
70 2 ▶sub expandAllSimple { throw Tree::Simple::View::AbstractMethod "Method Not Implemented" }
Subroutine expandAllSimple: called CC=1 SCAR=0.0
Pod documented
71 2 ▶sub expandAllComplex { throw Tree::Simple::View::AbstractMethod "Method Not Implemented" }
Subroutine expandAllComplex: called CC=1 SCAR=0.0
Pod documented
72  
73 ## private methods
74  
75 117 ▶sub _compareNodeToPath {
Subroutine _compareNodeToPath: called CC=2 SCAR=6.9
76 117 my ($self, $current_path, $current_tree) = @_;
77 # default to normal node-path comparison ...
78 return $current_path eq $current_tree->getNodeValue()
79 117 ▶ unless defined $self->{path_comparison_func};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"path_comparison_func"} 106 11 117
80 # unless we have a path_comparison_func in place
81 # in which case we use that
82 11 return $self->{path_comparison_func}->($current_path, $current_tree);
83 }
84  
85 8 1;
86  
87 __END__
« View/DHTML.pm ↑ Summary View/Exceptions.pm »