StringTree/Node.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 65.0% 13 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 2 totaltotal 84.0% 63 / 75 CC 12 SCAR 9.4
CC
12
Cov
85%
__new
4.1
__set
3.3
isa
3.0
CRAP 2.6
« StringTree.pm ↑ Summary
1 package Template::Plugin::StringTree::Node;
2  
3 # This package implements the actual nodes in the StringTree.
4 # We need to be very careful not to pollute this namespace with methods.
5  
6 2 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use overload '""' => '__get';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use vars qw{$VERSION %STRING};
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 $VERSION = '0.08';
14  
15 # Data store for the Nodes
16 2 %STRING = ();
17 }
18  
19 # Create a new node, with an optional value
20 26 ▶sub __new {
Subroutine __new: called CC=4 SCAR=14.0
21 26 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 26 26
22 26 my $self = bless {}, $class;
23  
24 26 ▶ if ( defined $_[0] and ! ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and not ref $_[0]) 6 20 26
Condition66%2/3
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
2006
MC/DC50%1/2
defined $_[0] and not ref $_[0]
defined $_[0] not ref $_[0]
Truth table66%2/3
A and not(B)
A= defined $_[0]B= not ref $_[0]
ABresult
0X0
100
111
25 # The value for this node
26 6 $STRING{Scalar::Util::refaddr($self)} = shift;
27 }
28  
29 26 $self;
30 }
31  
32 # Get the value for this node
33 49 ▶sub __get {
Subroutine __get: called CC=2 SCAR=7.2
34 49 ▶ my $self = ref $_[0] ? shift : return undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 49 0 49
35 49 $STRING{Scalar::Util::refaddr($self)};
36 }
37  
38 # Set the value for this node
39 1 ▶sub __set {
Subroutine __set: called CC=3 SCAR=12.0
40 1 ▶ my $self = ref $_[0] ? shift : return undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 0 1
41 1 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) { } 1 0 1
42 1 $STRING{Scalar::Util::refaddr($self)} = shift;
43 } else {
44 0 delete $STRING{Scalar::Util::refaddr($_[0])};
45 }
46  
47 1 1;
48 }
49  
50 # Methods compatible with UNIVERSAL will die in a major way.
51 # Fortunately, we can tell if 'isa' and 'can' calls are meant to be genuine
52 # or not. The two-argument form is passed though, the one-argument form
53 # is treated by descending.
54 4 ▶sub isa {
Subroutine isa: called CC=3 SCAR=11.1
Pod undocumented
55 4 my $self = shift;
56 4 ▶ return $self->SUPER::isa(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 1 4
57 1 ▶ exists $self->{isa} ? $self->{isa} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'isa'} ? : 1 0 1
58 }
59 2 ▶sub can {
Subroutine can: called CC=3 SCAR=11.1
Pod undocumented
60 2 my $self = shift;
61 2 ▶ return $self->SUPER::can(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 1 2
62 1 ▶ exists $self->{can} ? $self->{can} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'can'} ? : 1 0 1
63 }
64  
65 # Unfortunately, we have no choice but to use this name.
66 # To prevent pollution, we'll throw an error should we ever try to set
67 # a value using a DESTROY segment in a path.
68 26 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.6
69 26 ▶ delete $STRING{Scalar::Util::refaddr($_[0])} if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 26 0 26
70 }
71  
72 2 1;
« StringTree.pm ↑ Summary