| 1 | 49 | ▶ | use strict; use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 2 | package YAML::Node; | ||||||||||||||||||
| 3 | |||||||||||||||||||
| 4 | 49 | ▶ | use YAML::Tag; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 49 | require YAML::Mo; | |||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 49 | ▶ | use Exporter; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 49 | our @ISA = qw(Exporter YAML::Mo::Object); | |||||||||||||||||
| 9 | 49 | our @EXPORT = qw(ynode); | |||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 1942 | ▶ | sub ynode { | ||||||||||||||||
|
Subroutine
ynode: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||
| 12 | 1942 | my $self; | |||||||||||||||||
| 13 | 1942 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 14 | 891 | $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 | 990 | $self = tied($_[0]); | |||||||||||||||||
| 24 | } | ||||||||||||||||||
| 25 | 1942 | ▶ | return (ref($self) =~ /^yaml_/) ? $self : undef; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 26 | } | ||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | 96 | ▶ | sub new { | ||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||
| 29 | 96 | my ($class, $node, $tag) = @_; | |||||||||||||||||
| 30 | 96 | my $self; | |||||||||||||||||
| 31 | 96 | $self->{NODE} = $node; | |||||||||||||||||
| 32 | 96 | my (undef, $type) = YAML::Mo::Object->node_info($node); | |||||||||||||||||
| 33 | 96 | ▶ | $self->{KIND} = (not defined $type) ? 'scalar' : | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 34 | ($type eq 'ARRAY') ? 'sequence' : | ||||||||||||||||||
| 35 | ($type eq 'HASH') ? 'mapping' : | ||||||||||||||||||
| 36 | $class->die("Can't create YAML::Node from '$type'"); | ||||||||||||||||||
| 37 | 96 | ▶ | tag($self, ($tag || '')); | ||||||||||||||||
|
Condition100%2/2
$tag || ''
MC/DC100%1/1
$tag || ''
$tag
Truth table100%2/2
A
A= $tag
| |||||||||||||||||||
| 38 | 96 | ▶ | if ($self->{KIND} eq 'scalar') { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 39 | 16 | yaml_scalar->new($self, $_[1]); | |||||||||||||||||
| 40 | 16 | return \ $_[1]; | |||||||||||||||||
| 41 | } | ||||||||||||||||||
| 42 | 80 | my $package = "yaml_" . $self->{KIND}; | |||||||||||||||||
| 43 | 80 | $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 | 193 | ▶ | sub tag { | ||||||||||||||||
|
Subroutine
tag: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 49 | 193 | my ($self, $value) = @_; | |||||||||||||||||
| 50 | 193 | ▶ | if (defined $value) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 51 | 96 | $self->{TAG} = YAML::Tag->new($value); | |||||||||||||||||
| 52 | 96 | return $self; | |||||||||||||||||
| 53 | } | ||||||||||||||||||
| 54 | else { | ||||||||||||||||||
| 55 | 97 | 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
| |||||||||||||||||||
| 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 | 49 | @yaml_scalar::ISA = qw(YAML::Node); | |||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | 16 | ▶ | sub new { | ||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 75 | 16 | my ($class, $self) = @_; | |||||||||||||||||
| 76 | 16 | tie $_[2], $class, $self; | |||||||||||||||||
| 77 | } | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | 16 | ▶ | sub TIESCALAR { | ||||||||||||||||
|
Subroutine
TIESCALAR: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 80 | 16 | my ($class, $self) = @_; | |||||||||||||||||
| 81 | 16 | bless $self, $class; | |||||||||||||||||
| 82 | 16 | $self | |||||||||||||||||
| 83 | } | ||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | 76 | ▶ | sub FETCH { | ||||||||||||||||
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 86 | 76 | my ($self) = @_; | |||||||||||||||||
| 87 | $self->{NODE} | ||||||||||||||||||
| 88 | 76 | } | |||||||||||||||||
| 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 | 49 | @yaml_sequence::ISA = qw(YAML::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 | 49 | *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 | 49 | @yaml_mapping::ISA = qw(YAML::Node); | |||||||||||||||||
| 139 | |||||||||||||||||||
| 140 | 70 | ▶ | sub new { | ||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 141 | 70 | my ($class, $self) = @_; | |||||||||||||||||
| 142 | 70 | @{$self->{KEYS}} = sort keys %{$self->{NODE}}; | |||||||||||||||||
| 143 | 70 | my $new; | |||||||||||||||||
| 144 | 70 | tie %$new, $class, $self; | |||||||||||||||||
| 145 | 70 | $new | |||||||||||||||||
| 146 | } | ||||||||||||||||||
| 147 | |||||||||||||||||||
| 148 | 70 | ▶ | sub TIEHASH { | ||||||||||||||||
|
Subroutine
TIEHASH: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 149 | 70 | my ($class, $self) = @_; | |||||||||||||||||
| 150 | 70 | bless $self, $class | |||||||||||||||||
| 151 | } | ||||||||||||||||||
| 152 | |||||||||||||||||||
| 153 | 286 | ▶ | sub FETCH { | ||||||||||||||||
|
Subroutine
FETCH: called CC=3 SCAR=11.0
| |||||||||||||||||||
| 154 | 286 | my ($self, $key) = @_; | |||||||||||||||||
| 155 | 286 | ▶ | if (exists $self->{NODE}{$key}) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 156 | 259 | return (grep {$_ eq $key} @{$self->{KEYS}}) | |||||||||||||||||
| 157 | 143 | ▶ | ? $self->{NODE}{$key} : undef; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 189 | 3 | ▶ | if ($self->{KEYS}[$i] eq $key) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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 | 188 | ▶ | sub FIRSTKEY { | ||||||||||||||||
|
Subroutine
FIRSTKEY: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 203 | 188 | my ($self) = @_; | |||||||||||||||||
| 204 | 188 | $self->{ITER} = 0; | |||||||||||||||||
| 205 | 188 | $self->{KEYS}[0] | |||||||||||||||||
| 206 | } | ||||||||||||||||||
| 207 | |||||||||||||||||||
| 208 | 424 | ▶ | sub NEXTKEY { | ||||||||||||||||
|
Subroutine
NEXTKEY: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 209 | 424 | my ($self) = @_; | |||||||||||||||||
| 210 | 424 | $self->{KEYS}[++$self->{ITER}] | |||||||||||||||||
| 211 | } | ||||||||||||||||||
| 212 | |||||||||||||||||||
| 213 | 88 | ▶ | sub EXISTS { | ||||||||||||||||
|
Subroutine
EXISTS: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 214 | 88 | my ($self, $key) = @_; | |||||||||||||||||
| 215 | 88 | exists $self->{NODE}{$key} | |||||||||||||||||
| 216 | } | ||||||||||||||||||
| 217 | |||||||||||||||||||
| 218 | 49 | 1; | |||||||||||||||||