Old/Node.pm

filter: Statementstmt 86.4% 108 / 125 Branchbran 78.9% 30 / 38 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 79.3% 23 / 29 Podpod 0.0% 0 / 6 totaltotal 81.5% 164 / 201 CC 21 SCAR 11.1
CC
21
Cov
85%
new
6.0
DELETE
5.2
ynode
5.1
CRAP 3.0
« Old/Error.pm ↑ Summary Old.pm »
1 45 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package YAML::Old::Node;
3  
4 45 ▶use YAML::Old::Tag;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 45 require YAML::Old::Mo;
6  
7 45 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 45 our @ISA = qw(Exporter YAML::Old::Mo::Object);
9 45 our @EXPORT = qw(ynode);
10  
11 1923 ▶sub ynode {
Subroutine ynode: called CC=5 SCAR=16.3
Pod undocumented
12 1923 my $self;
13 1923 ▶ if (ref($_[0]) eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 877 1046 1923
elsif (ref $_[0] eq 'ARRAY') { } 61 985 1046
elsif (ref \$_[0] eq 'GLOB') { } 0 985 985
14 877 $self = tied(%{$_[0]});
15 }
16 elsif (ref($_[0]) eq 'ARRAY') {
17 61 $self = tied(@{$_[0]});
18 }
19 elsif (ref(\$_[0]) eq 'GLOB') {
20 0 $self = tied(*{$_[0]});
21 }
22 else {
23 985 $self = tied($_[0]);
24 }
25 1923 ▶ return (ref($self) =~ /^yaml_/) ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref($self) =~ /^yaml_/ ? : 175 1748 1923
26 }
27  
28 97 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod undocumented
29 97 my ($class, $node, $tag) = @_;
30 97 my $self;
31 97 $self->{NODE} = $node;
32 97 my (undef, $type) = YAML::Old::Mo::Object->node_info($node);
33 97 ▶ $self->{KIND} = (not defined $type) ? 'scalar' :
Branch: 3 branches
BranchTrueFalseTotal
!defined($type) ? : 14 83 97
$type eq 'ARRAY' ? : 10 73 83
$type eq 'HASH' ? : 73 0 73
34 ($type eq 'ARRAY') ? 'sequence' :
35 ($type eq 'HASH') ? 'mapping' :
36 $class->die("Can't create YAML::Old::Node from '$type'");
37 97 ▶ tag($self, ($tag || ''));
Condition100%2/2
$tag || ''
l!l
916
MC/DC100%1/1
$tag || ''
$tag
Truth table100%2/2
A
A= $tag
Aresult
11
00
38 97 ▶ if ($self->{KIND} eq 'scalar') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"KIND"} eq "scalar") 14 83 97
39 14 yaml_scalar->new($self, $_[1]);
40 14 return \ $_[1];
41 }
42 83 my $package = "yaml_" . $self->{KIND};
43 83 $package->new($self)
44 }
45  
46 0 ▶sub node { $_->{NODE} }
Subroutine node: not called CC=1 SCAR=6.9
Pod undocumented
47 0 ▶sub kind { $_->{KIND} }
Subroutine kind: not called CC=1 SCAR=6.9
Pod undocumented
48 195 ▶sub tag {
Subroutine tag: called CC=2 SCAR=6.9
Pod undocumented
49 195 my ($self, $value) = @_;
50 195 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 97 98 195
51 97 $self->{TAG} = YAML::Old::Tag->new($value);
52 97 return $self;
53 }
54 else {
55 98 return $self->{TAG};
56 }
57 }
58 6 ▶sub keys {
Subroutine keys: called CC=2 SCAR=7.4
Pod undocumented
59 6 my ($self, $value) = @_;
60 6 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 6 0 6
61 6 $self->{KEYS} = $value;
62 6 return $self;
63 }
64 else {
65 0 return $self->{KEYS};
66 }
67 }
68  
69 #==============================================================================
70 package yaml_scalar;
71  
72 45 @yaml_scalar::ISA = qw(YAML::Old::Node);
73  
74 14 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
75 14 my ($class, $self) = @_;
76 14 tie $_[2], $class, $self;
77 }
78  
79 14 ▶sub TIESCALAR {
Subroutine TIESCALAR: called CC=1 SCAR=0.0
80 14 my ($class, $self) = @_;
81 14 bless $self, $class;
82 14 $self
83 }
84  
85 68 ▶sub FETCH {
Subroutine FETCH: called CC=1 SCAR=0.0
86 68 my ($self) = @_;
87 $self->{NODE}
88 68 }
89  
90 0 ▶sub STORE {
Subroutine STORE: not called CC=1 SCAR=6.9
91 0 my ($self, $value) = @_;
92 0 $self->{NODE} = $value
93 }
94  
95 #==============================================================================
96 package yaml_sequence;
97  
98 45 @yaml_sequence::ISA = qw(YAML::Old::Node);
99  
100 10 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
101 10 my ($class, $self) = @_;
102 10 my $new;
103 10 tie @$new, $class, $self;
104 10 $new
105 }
106  
107 10 ▶sub TIEARRAY {
Subroutine TIEARRAY: called CC=1 SCAR=0.0
108 10 my ($class, $self) = @_;
109 10 bless $self, $class
110 }
111  
112 52 ▶sub FETCHSIZE {
Subroutine FETCHSIZE: called CC=1 SCAR=0.0
113 52 my ($self) = @_;
114 52 scalar @{$self->{NODE}};
115 }
116  
117 36 ▶sub FETCH {
Subroutine FETCH: called CC=1 SCAR=0.0
118 36 my ($self, $index) = @_;
119 36 $self->{NODE}[$index]
120 }
121  
122 0 ▶sub STORE {
Subroutine STORE: not called CC=1 SCAR=6.9
123 0 my ($self, $index, $value) = @_;
124 0 $self->{NODE}[$index] = $value
125 }
126  
127 0 ▶sub undone {
Subroutine undone: not called CC=1 SCAR=6.9
128 0 die "Not implemented yet"; # XXX
129 }
130  
131 45 *STORESIZE = *POP = *PUSH = *SHIFT = *UNSHIFT = *SPLICE = *DELETE = *EXISTS =
132 *STORESIZE = *POP = *PUSH = *SHIFT = *UNSHIFT = *SPLICE = *DELETE = *EXISTS =
133 *undone; # XXX Must implement before release
134  
135 #==============================================================================
136 package yaml_mapping;
137  
138 45 @yaml_mapping::ISA = qw(YAML::Old::Node);
139  
140 73 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
141 73 my ($class, $self) = @_;
142 73 @{$self->{KEYS}} = sort keys %{$self->{NODE}};
143 73 my $new;
144 73 tie %$new, $class, $self;
145 73 $new
146 }
147  
148 73 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=1 SCAR=0.0
149 73 my ($class, $self) = @_;
150 73 bless $self, $class
151 }
152  
153 304 ▶sub FETCH {
Subroutine FETCH: called CC=3 SCAR=11.0
154 304 my ($self, $key) = @_;
155 304 ▶ if (exists $self->{NODE}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"NODE"}{$key}) 161 143 304
156 313 return (grep {$_ eq $key} @{$self->{KEYS}})
157 161 ▶ ? $self->{NODE}{$key} : undef;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq $key;} @{$$self{'KEYS'};}) ? : 161 0 161
158 }
159 143 return $self->{HASH}{$key};
160 }
161  
162 75 ▶sub STORE {
Subroutine STORE: called CC=4 SCAR=13.9
163 75 my ($self, $key, $value) = @_;
164 75 ▶ if (exists $self->{NODE}{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'NODE'}{$key}) { } 2 73 75
elsif (exists $self->{'HASH'}{$key}) { } 0 73 73
165 2 $self->{NODE}{$key} = $value;
166 }
167 elsif (exists $self->{HASH}{$key}) {
168 0 $self->{HASH}{$key} = $value;
169 }
170 else {
171 73 ▶ if (not grep {$_ eq $key} @{$self->{KEYS}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $key;} @{$$self{"KEYS"};}) 72 1 73
172 72 push(@{$self->{KEYS}}, $key);
173 }
174 73 $self->{HASH}{$key} = $value;
175 }
176 75 $value
177 }
178  
179 1 ▶sub DELETE {
Subroutine DELETE: called CC=5 SCAR=16.6
180 1 my ($self, $key) = @_;
181 1 my $return;
182 1 ▶ if (exists $self->{NODE}{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'NODE'}{$key}) { } 1 0 1
elsif (exists $self->{'HASH'}{$key}) { } 0 0 0
183 1 $return = $self->{NODE}{$key};
184 }
185 elsif (exists $self->{HASH}{$key}) {
186 0 $return = delete $self->{NODE}{$key};
187 }
188 1 ▶ for (my $i = 0; $i < @{$self->{KEYS}}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$self->{"KEYS"};}) 3 1 4
189 3 ▶ if ($self->{KEYS}[$i] eq $key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"KEYS"}[$i] eq $key) 1 2 3
190 1 splice(@{$self->{KEYS}}, $i, 1);
191 }
192 }
193 1 return $return;
194 }
195  
196 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=1 SCAR=6.9
197 0 my ($self) = @_;
198 0 @{$self->{KEYS}} = ();
199 0 %{$self->{HASH}} = ();
200 }
201  
202 197 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
203 197 my ($self) = @_;
204 197 $self->{ITER} = 0;
205 197 $self->{KEYS}[0]
206 }
207  
208 451 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=1 SCAR=0.0
209 451 my ($self) = @_;
210 451 $self->{KEYS}[++$self->{ITER}]
211 }
212  
213 91 ▶sub EXISTS {
Subroutine EXISTS: called CC=1 SCAR=0.0
214 91 my ($self, $key) = @_;
215 91 exists $self->{NODE}{$key}
216 }
217  
218 45 1;
« Old/Error.pm ↑ Summary Old.pm »