Old/Loader.pm

filter: Statementstmt 91.4% 416 / 455 Branchbran 86.8% 231 / 266 Conditioncond 87.6% 85 / 97 MC/DCmcdc 76.7% 43 / 56 Subroutinesub 100% 28 / 28 Podpod 0.0% 0 / 1 totaltotal 88.9% 803 / 903 CC 171 SCAR 30.0
CC
171
Cov
89%
_parse_inline
41.5
_parse_node
31.0
_parse_next_line
30.7
CRAP 20.2
↑ Summary Old/Dumper.pm »
1 package YAML::Old::Loader;
2  
3 32 ▶use YAML::Old::Mo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 32 extends 'YAML::Old::Loader::Base';
5  
6 32 ▶use YAML::Old::Loader::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 32 ▶use YAML::Old::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 32 ▶use YAML::Old::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Context constants
11 32 ▶use constant LEAF => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 32 ▶use constant COLLECTION => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 32 ▶use constant VALUE => "\x07YAML\x07VALUE\x07";
Subroutine BEGIN: called CC=1 SCAR=0.0
14 32 ▶use constant COMMENT => "\x07YAML\x07COMMENT\x07";
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # Common YAML character sets
17 32 my $ESCAPE_CHAR = '[\\x00-\\x08\\x0b-\\x0d\\x0e-\\x1f]';
18 32 my $FOLD_CHAR = '>';
19 32 my $LIT_CHAR = '|';
20 32 my $LIT_CHAR_RX = "\\$LIT_CHAR";
21  
22 277 ▶sub load {
Subroutine load: called CC=2 SCAR=7.1
Pod undocumented
23 277 my $self = shift;
24 277 ▶ $self->stream($_[0] || '');
Condition50%1/2
$_[0] || ''
l!l
2770
MC/DC0%0/1
$_[0] || ''
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
25 277 return $self->_parse();
26 }
27  
28 # Top level function for parsing. Parse each document in order and
29 # handle processing for YAML headers.
30 277 ▶sub _parse {
Subroutine _parse: called CC=17 SCAR=28.3
31 277 my $self = shift;
32 277 my (%directives, $preface);
33 277 $self->{stream} =~ s|\015\012|\012|g;
34 277 $self->{stream} =~ s|\015|\012|g;
35 277 $self->line(0);
36 277 ▶ $self->die('YAML_PARSE_ERR_BAD_CHARS')
Branch: 1 branch
BranchTrueFalseTotal
if $self->stream =~ /$ESCAPE_CHAR/ 1 276 277
37 if $self->stream =~ /$ESCAPE_CHAR/;
38 276 $self->{stream} =~ s/(.)\n\Z/$1/s;
39 276 $self->lines([split /\x0a/, $self->stream, -1]);
40 276 $self->line(1);
41 # Throw away any comments or blanks before the header (or start of
42 # content for headerless streams)
43 276 $self->_parse_throwaway_comments();
44 276 $self->document(0);
45 276 $self->documents([]);
46 # Add an "assumed" header if there is no header and the stream is
47 # not empty (after initial throwaways).
48 276 ▶ if (not $self->eos) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eos) 238 38 276
49 238 ▶ if ($self->lines->[0] !~ /^---(\s|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->lines->[0] =~ /^---(\s|$)/) 31 207 238
50 31 unshift @{$self->lines}, '---';
51 31 $self->{line}--;
52 }
53 }
54  
55 # Main Loop. Parse out all the top level nodes and return them.
56 276 ▶ while (not $self->eos) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eos) 276 246 522
57 276 $self->anchor2node({});
58 276 $self->{document}++;
59 276 $self->done(0);
60 276 $self->level(0);
61 276 $self->offset->[0] = -1;
62  
63 276 ▶ if ($self->lines->[0] =~ /^---\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lines->[0] =~ /^---\s*(.*)$/) { } 276 0 276
64 276 my @words = split /\s+/, $1;
65 276 %directives = ();
66 276 ▶ while (@words && $words[0] =~ /^#(\w+):(\S.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words and $words[0] =~ /^#(\w+):(\S.*)$/) 17 276 293
Condition100%3/3
@words and $words[0] =~ /^#(\w+):(\S.*)$/
!ll&&!rl&&r
1809617
MC/DC100%2/2
@words and $words[0] =~ /^#(\w+):(\S.*)$/
@words $words[0] =~ /^#(\w+):(\S.*)$/
Truth table100%3/3
A and B
A= @wordsB= $words[0] =~ /^#(\w+):(\S.*)$/
ABresult
0X0
100
111
67 17 my ($key, $value) = ($1, $2);
68 17 shift(@words);
69 17 ▶ if (defined $directives{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $directives{$key}) 2 15 17
70 2 $self->warn('YAML_PARSE_WARN_MULTIPLE_DIRECTIVES',
71 $key, $self->document);
72 2 next;
73 }
74 15 $directives{$key} = $value;
75 }
76 276 $self->preface(join ' ', @words);
77 }
78 else {
79 0 $self->die('YAML_PARSE_ERR_NO_SEPARATOR');
80 }
81  
82 276 ▶ if (not $self->done) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->done) 276 0 276
83 276 $self->_parse_next_line(COLLECTION);
84 }
85 274 ▶ if ($self->done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->done) 53 221 274
86 53 $self->{indent} = -1;
87 53 $self->content('');
88 }
89  
90 274 ▶ $directives{YAML} ||= '1.0';
Condition100%2/2
$directives{"YAML"} ||= "1.0"
l!l
12262
MC/DC100%1/1
$directives{"YAML"} ||= "1.0"
$directives{"YAML"}
Truth table100%2/2
A
A= $directives{"YAML"}
Aresult
11
00
91 274 ▶ $directives{TAB} ||= 'NONE';
Condition100%2/2
$directives{"TAB"} ||= "NONE"
l!l
2272
MC/DC100%1/1
$directives{"TAB"} ||= "NONE"
$directives{"TAB"}
Truth table100%2/2
A
A= $directives{"TAB"}
Aresult
11
00
92 ($self->{major_version}, $self->{minor_version}) =
93 274 split /\./, $directives{YAML}, 2;
94 $self->die('YAML_PARSE_ERR_BAD_MAJOR_VERSION', $directives{YAML})
95 274 ▶ if $self->major_version ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $self->major_version ne 1 1 273 274
96 $self->warn('YAML_PARSE_WARN_BAD_MINOR_VERSION', $directives{YAML})
97 273 ▶ if $self->minor_version ne '0';
Branch: 1 branch
BranchTrueFalseTotal
if $self->minor_version ne 0 1 272 273
98 $self->die('Unrecognized TAB policy')
99 273 ▶ unless $directives{TAB} =~ /^(NONE|\d+)(:HARD)?$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $directives{"TAB"} =~ /^(NONE|\d+)(:HARD)?$/ 1 272 273
100  
101 272 push @{$self->documents}, $self->_parse_node();
102 }
103 246 ▶ return wantarray ? @{$self->documents} : $self->documents->[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 121 125 246
104 }
105  
106 # This function is the dispatcher for parsing each node. Every node
107 # recurses back through here. (Inlines are an exception as they have
108 # their own sub-parser.)
109 1902 ▶sub _parse_node {
Subroutine _parse_node: called CC=26 SCAR=34.3
110 1902 my $self = shift;
111 1902 my $preface = $self->preface;
112 1902 $self->preface('');
113 1902 my ($node, $type, $indicator, $escape, $chomp) = ('') x 5;
114 1902 my ($anchor, $alias, $explicit, $implicit, $class) = ('') x 5;
115 1902 ($anchor, $alias, $explicit, $implicit, $preface) =
116 $self->_parse_qualifiers($preface);
117 1893 ▶ if ($anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anchor) 16 1877 1893
118 16 $self->anchor2node->{$anchor} = CORE::bless [], 'YAML-anchor2node';
119 }
120 1893 $self->inline('');
121 1893 ▶ while (length $preface) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $preface) 1281 1892 3173
122 1281 my $line = $self->line - 1;
123 1281 ▶ if ($preface =~ s/^($FOLD_CHAR|$LIT_CHAR_RX)(-|\+)?\d*\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preface =~ s/^($FOLD_CHAR|$LIT_CHAR_RX)(-|\+)?\d*\s*//) { } 56 1225 1281
124 56 $indicator = $1;
125 56 ▶ $chomp = $2 if defined($2);
Branch: 1 branch
BranchTrueFalseTotal
if defined $2 18 38 56
126 }
127 else {
128 1225 ▶ $self->die('YAML_PARSE_ERR_TEXT_AFTER_INDICATOR') if $indicator;
Branch: 1 branch
BranchTrueFalseTotal
if $indicator 1 1224 1225
129 1224 $self->inline($preface);
130 1224 $preface = '';
131 }
132 }
133 1892 ▶ if ($alias) {
Branch: 4 branches
BranchTrueFalseTotal
if ($alias) { } 17 1875 1892
elsif (length $self->inline) { } 1224 651 1875
elsif ($indicator eq $LIT_CHAR) { } 38 613 651
elsif ($indicator eq $FOLD_CHAR) { } 17 596 613
134 $self->die('YAML_PARSE_ERR_NO_ANCHOR', $alias)
135 17 ▶ unless defined $self->anchor2node->{$alias};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->anchor2node->{$alias} 1 16 17
136 16 ▶ if (ref($self->anchor2node->{$alias}) ne 'YAML-anchor2node') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->anchor2node->{$alias} ne 'YAML-anchor2node') { } 16 0 16
137 16 $node = $self->anchor2node->{$alias};
138 }
139 else {
140 0 $node = do {my $sv = "*$alias"};
141 0 push @{$self->anchor2node->{$alias}}, [\$node, $self->line];
142 }
143 }
144 elsif (length $self->inline) {
145 1224 $node = $self->_parse_inline(1, $implicit, $explicit);
146 1218 ▶ if (length $self->inline) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->inline) 1 1217 1218
147 1 $self->die('YAML_PARSE_ERR_SINGLE_LINE');
148 }
149 }
150 elsif ($indicator eq $LIT_CHAR) {
151 38 $self->{level}++;
152 38 $node = $self->_parse_block($chomp);
153 38 ▶ $node = $self->_parse_implicit($node) if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 0 38 38
154 38 $self->{level}--;
155 }
156 elsif ($indicator eq $FOLD_CHAR) {
157 17 $self->{level}++;
158 17 $node = $self->_parse_unfold($chomp);
159 17 ▶ $node = $self->_parse_implicit($node) if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 1 16 17
160 16 $self->{level}--;
161 }
162 else {
163 596 $self->{level}++;
164 596 ▶ $self->offset->[$self->level] ||= 0;
Condition100%2/2
$self->offset->[$self->level] ||= 0
l!l
390206
MC/DC100%1/1
$self->offset->[$self->level] ||= 0
$self->offset->[$self->level]
Truth table100%2/2
A
A= $self->offset->[$self->level]
Aresult
11
00
165 596 ▶ if ($self->indent == $self->offset->[$self->level]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->indent == $self->offset->[$self->level]) { } 587 9 596
166 587 ▶ if ($self->content =~ /^-( |$)/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->content =~ /^-( |$)/) { } 139 448 587
elsif ($self->content =~ /(^\?|\:( |$))/) { } 448 0 448
elsif ($preface =~ /^\s*$/) { } 0 0 0
167 139 $node = $self->_parse_seq($anchor);
168 }
169 elsif ($self->content =~ /(^\?|\:( |$))/) {
170 448 $node = $self->_parse_mapping($anchor);
171 }
172 elsif ($preface =~ /^\s*$/) {
173 0 $node = $self->_parse_implicit('');
174 }
175 else {
176 0 $self->die('YAML_PARSE_ERR_BAD_NODE');
177 }
178 }
179 else {
180 9 $node = undef;
181 }
182 572 $self->{level}--;
183 }
184 1859 $#{$self->offset} = $self->level;
185  
186 1859 ▶ if ($explicit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($explicit) 66 1793 1859
187 66 ▶ if ($class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class) { } 0 66 66
188 0 ▶ if (not ref $node) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node) 0 0 0
189 0 my $copy = $node;
190 0 undef $node;
191 0 $node = \$copy;
192 }
193 0 CORE::bless $node, $class;
194 }
195 else {
196 66 $node = $self->_parse_explicit($node, $explicit);
197 }
198 }
199 1858 ▶ if ($anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anchor) 16 1842 1858
200 16 ▶ if (ref($self->anchor2node->{$anchor}) eq 'YAML-anchor2node') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->anchor2node->{$anchor} eq "YAML-anchor2node") 6 10 16
201 # XXX Can't remember what this code actually does
202 6 for my $ref (@{$self->anchor2node->{$anchor}}) {
203 0 ${$ref->[0]} = $node;
204 0 $self->warn('YAML_LOAD_WARN_UNRESOLVED_ALIAS',
205 $anchor, $ref->[1]);
206 }
207 }
208 16 $self->anchor2node->{$anchor} = $node;
209 }
210 1858 return $node;
211 }
212  
213 # Preprocess the qualifiers that may be attached to any node.
214 4542 ▶sub _parse_qualifiers {
Subroutine _parse_qualifiers: called CC=14 SCAR=26.4
215 4542 my $self = shift;
216 4542 my ($preface) = @_;
217 4542 my ($anchor, $alias, $explicit, $implicit, $token) = ('') x 5;
218 4542 $self->inline('');
219 4542 ▶ while ($preface =~ /^[&*!]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preface =~ /^[&*!]/) 118 4533 4651
220 118 my $line = $self->line - 1;
221 118 ▶ if ($preface =~ s/^\!(\S+)\s*//) {
Branch: 4 branches
BranchTrueFalseTotal
if ($preface =~ s/^\!(\S+)\s*//) { } 70 48 118
elsif ($preface =~ s/^\!\s*//) { } 5 43 48
elsif ($preface =~ s/^\&([^ ,:]*)\s*//) { } 21 22 43
elsif ($preface =~ s/^\*([^ ,:]*)\s*//) { } 22 0 22
222 70 ▶ $self->die('YAML_PARSE_ERR_MANY_EXPLICIT') if $explicit;
Branch: 1 branch
BranchTrueFalseTotal
if $explicit 1 69 70
223 69 $explicit = $1;
224 }
225 elsif ($preface =~ s/^\!\s*//) {
226 5 ▶ $self->die('YAML_PARSE_ERR_MANY_IMPLICIT') if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 1 4 5
227 4 $implicit = 1;
228 }
229 elsif ($preface =~ s/^\&([^ ,:]*)\s*//) {
230 21 $token = $1;
231 21 ▶ $self->die('YAML_PARSE_ERR_BAD_ANCHOR')
Branch: 1 branch
BranchTrueFalseTotal
unless $token =~ /^[a-zA-Z0-9]+$/ 2 19 21
232 unless $token =~ /^[a-zA-Z0-9]+$/;
233 19 ▶ $self->die('YAML_PARSE_ERR_MANY_ANCHOR') if $anchor;
Branch: 1 branch
BranchTrueFalseTotal
if $anchor 1 18 19
234 18 ▶ $self->die('YAML_PARSE_ERR_ANCHOR_ALIAS') if $alias;
Branch: 1 branch
BranchTrueFalseTotal
if $alias 0 18 18
235 18 $anchor = $token;
236 }
237 elsif ($preface =~ s/^\*([^ ,:]*)\s*//) {
238 22 $token = $1;
239 22 ▶ $self->die('YAML_PARSE_ERR_BAD_ALIAS')
Branch: 1 branch
BranchTrueFalseTotal
unless $token =~ /^[a-zA-Z0-9]+$/ 2 20 22
240 unless $token =~ /^[a-zA-Z0-9]+$/;
241 20 ▶ $self->die('YAML_PARSE_ERR_MANY_ALIAS') if $alias;
Branch: 1 branch
BranchTrueFalseTotal
if $alias 1 19 20
242 19 ▶ $self->die('YAML_PARSE_ERR_ANCHOR_ALIAS') if $anchor;
Branch: 1 branch
BranchTrueFalseTotal
if $anchor 1 18 19
243 18 $alias = $token;
244 }
245 }
246 4533 return ($anchor, $alias, $explicit, $implicit, $preface);
247 }
248  
249 # Morph a node to it's explicit type
250 83 ▶sub _parse_explicit {
Subroutine _parse_explicit: called CC=21 SCAR=30.7
251 83 my $self = shift;
252 83 my ($node, $explicit) = @_;
253 83 my ($type, $class);
254 83 ▶ if ($explicit =~ /^\!?perl\/(hash|array|ref|scalar)(?:\:(\w(\w|\:\:)*)?)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($explicit =~ m[^\!?perl/(hash|array|ref|scalar)(?:\:(\w(\w|\:\:)*)?)?$]) 47 36 83
255 47 ▶ ($type, $class) = (($1 || ''), ($2 || ''));
Condition75%3/4
$1 || ''
l!l
470
$2 || ''
l!l
2027
MC/DC0%0/1
$1 || ''
$1
MC/DC100%1/1
$2 || ''
$2
Truth table50%1/2
A
A= $1
Aresult
11
00
Truth table100%2/2
A
A= $2
Aresult
11
00
256  
257 # FIXME # die unless uc($type) eq ref($node) ?
258  
259 47 ▶ if ( $type eq "ref" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "ref") 21 26 47
260 $self->die('YAML_LOAD_ERR_NO_DEFAULT_VALUE', 'XXX', $explicit)
261 21 ▶ unless exists $node->{VALUE()} and scalar(keys %$node) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $node->{"\aYAML\aVALUE\a"} and scalar keys %$node == 1 1 20 21
Condition66%2/3
exists $node->{"\aYAML\aVALUE\a"} and scalar keys %$node == 1
!ll&&!rl&&r
1020
MC/DC50%1/2
exists $node->{"\aYAML\aVALUE\a"} and scalar keys %$node == 1
exists $node->{"\aYAML\aVALUE\a"} scalar keys %$node == 1
Truth table66%2/3
A and B
A= exists $node->{"\aYAML\aVALUE\a"}B= scalar keys %$node == 1
ABresult
0X0
100
111
262  
263 20 my $value = $node->{VALUE()};
264 20 $node = \$value;
265 }
266  
267 46 ▶ if ( $type eq "scalar" and length($class) and !ref($node) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "scalar" and length $class and not ref $node) 3 43 46
Condition100%6/6
$type eq "scalar" and length $class and not ref $node
!ll&&!rl&&r
4033
$type eq "scalar" and length $class
!ll&&!rl&&r
3646
MC/DC100%3/3
$type eq "scalar" and length $class and not ref $node
$type eq "scalar" length $class not ref $node
Truth table100%4/4
A and B and not(C)
A= $type eq "scalar"B= length $classC= not ref $node
ABCresult
0XX0
10X0
1100
1111
268 3 my $value = $node;
269 3 $node = \$value;
270 }
271  
272 46 ▶ if ( length($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $class) 20 26 46
273 20 CORE::bless($node, $class);
274 }
275  
276 46 return $node;
277 }
278 36 ▶ if ($explicit =~ m{^!?perl/(glob|regexp|code)(?:\:(\w(\w|\:\:)*)?)?$}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($explicit =~ m[^!?perl/(glob|regexp|code)(?:\:(\w(\w|\:\:)*)?)?$]) { } 14 22 36
elsif ($YAML::TagClass->{$explicit} or $explicit =~ m[^perl/(\@|\$)?([a-zA-Z](\w|::)+)$]) { } 13 9 22
elsif (ref $node) { } 5 4 9
279 14 ▶ ($type, $class) = (($1 || ''), ($2 || ''));
Condition75%3/4
$1 || ''
l!l
140
$2 || ''
l!l
212
MC/DC0%0/1
$1 || ''
$1
MC/DC100%1/1
$2 || ''
$2
Truth table50%1/2
A
A= $1
Aresult
11
00
Truth table100%2/2
A
A= $2
Aresult
11
00
280 14 my $type_class = "YAML::Old::Type::$type";
281 32 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
282 14 ▶ if ($type_class->can('yaml_load')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_class->can('yaml_load')) { } 14 0 14
283 14 return $type_class->yaml_load($node, $class, $self);
284 }
285 else {
286 0 $self->die('YAML_LOAD_ERR_NO_CONVERT', 'XXX', $explicit);
287 }
288 }
289 # This !perl/@Foo and !perl/$Foo are deprecated but still parsed
290 ▶ elsif ($YAML::TagClass->{$explicit} ||
Condition100%3/3
$YAML::TagClass->{$explicit} or $explicit =~ m[^perl/(\@|\$)?([a-zA-Z](\w|::)+)$]
l!l&&r!l&&!r
2119
MC/DC100%2/2
$YAML::TagClass->{$explicit} or $explicit =~ m[^perl/(\@|\$)?([a-zA-Z](\w|::)+)$]
$YAML::TagClass->{$explicit} $explicit =~ m[^perl/(\@|\$)?([a-zA-Z](\w|::)+)$]
Truth table100%3/3
A or B
A= $YAML::TagClass->{$explicit}B= $explicit =~ m[^perl/(\@|\$)?([a-zA-Z](\w|::)+)$]
ABresult
1X1
011
000
291 $explicit =~ m{^perl/(\@|\$)?([a-zA-Z](\w|::)+)$}
292 ) {
293 13 ▶ $class = $YAML::TagClass->{$explicit} || $2;
Condition66%2/3
$YAML::TagClass->{$explicit} || $2
l!l&&r!l&&!r
2110
MC/DC0%0/2
$YAML::TagClass->{$explicit} || $2
$YAML::TagClass->{$explicit} $2
Truth table66%2/3
A || B
A= $YAML::TagClass->{$explicit}B= $2
ABresult
1X1
011
000
294 13 ▶ if ($class->can('yaml_load')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('yaml_load')) { } 4 9 13
295 4 require YAML::Old::Node;
296 4 return $class->yaml_load(YAML::Old::Node->new($node, $explicit));
297 }
298 else {
299 9 ▶ if (ref $node) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node) { } 9 0 9
300 9 return CORE::bless $node, $class;
301 }
302 else {
303 0 return CORE::bless \$node, $class;
304 }
305 }
306 }
307 elsif (ref $node) {
308 5 require YAML::Old::Node;
309 5 return YAML::Old::Node->new($node, $explicit);
310 }
311 else {
312 # XXX This is likely wrong. Failing test:
313 # --- !unknown 'scalar value'
314 4 return $node;
315 }
316 }
317  
318 # Parse a YAML mapping into a Perl hash
319 484 ▶sub _parse_mapping {
Subroutine _parse_mapping: called CC=9 SCAR=22.0
320 484 my $self = shift;
321 484 my ($anchor) = @_;
322 484 ▶ my $mapping = $self->preserve ? YAML::Old::Node->new({}) : {};
Branch: 1 branch
BranchTrueFalseTotal
$self->preserve ? : 1 483 484
323 484 $self->anchor2node->{$anchor} = $mapping;
324 484 my $key;
325 484 ▶ while (not $self->done and $self->indent == $self->offset->[$self->level]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->done and $self->indent == $self->offset->[$self->level]) 1343 481 1824
Condition100%3/3
not $self->done and $self->indent == $self->offset->[$self->level]
!ll&&!rl&&r
1523291343
MC/DC100%2/2
not $self->done and $self->indent == $self->offset->[$self->level]
not $self->done $self->indent == $self->offset->[$self->level]
Truth table100%3/3
not(A) and B
A= not $self->doneB= $self->indent == $self->offset->[$self->level]
ABresult
0X0
100
111
326 # If structured key:
327 1343 ▶ if ($self->{content} =~ s/^\?\s*//) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'content'} =~ s/^\?\s*//) { } 4 1339 1343
elsif ($self->{'content'} =~ s/^\=\s*//) { } 22 1317 1339
elsif ($self->{'content'} =~ s/^\=\s*//) { } 0 1317 1317
328 4 $self->preface($self->content);
329 4 $self->_parse_next_line(COLLECTION);
330 4 $key = $self->_parse_node();
331 4 $key = "$key";
332 }
333 # If "default" key (equals sign)
334 elsif ($self->{content} =~ s/^\=\s*//) {
335 22 $key = VALUE;
336 }
337 # If "comment" key (slash slash)
338 elsif ($self->{content} =~ s/^\=\s*//) {
339 0 $key = COMMENT;
340 }
341 # Regular scalar key:
342 else {
343 1317 $self->inline($self->content);
344 1317 $key = $self->_parse_inline();
345 1317 $key = "$key";
346 1317 $self->content($self->inline);
347 1317 $self->inline('');
348 }
349  
350 1343 ▶ unless ($self->{content} =~ s/^:\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"content"} =~ s/^:\s*//) 1 1342 1343
351 1 $self->die('YAML_LOAD_ERR_BAD_MAP_ELEMENT');
352 }
353 1342 $self->preface($self->content);
354 1342 my $line = $self->line;
355 1342 $self->_parse_next_line(COLLECTION);
356 1340 my $value = $self->_parse_node();
357 1340 ▶ if (exists $mapping->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $mapping->{$key}) { } 2 1338 1340
358 2 $self->warn('YAML_LOAD_WARN_DUPLICATE_KEY', $key);
359 }
360 else {
361 1338 $mapping->{$key} = $value;
362 }
363 }
364 481 return $mapping;
365 }
366  
367 # Parse a YAML sequence into a Perl array
368 139 ▶sub _parse_seq {
Subroutine _parse_seq: called CC=8 SCAR=20.8
369 139 my $self = shift;
370 139 my ($anchor) = @_;
371 139 my $seq = [];
372 139 $self->anchor2node->{$anchor} = $seq;
373 139 ▶ while (not $self->done and $self->indent == $self->offset->[$self->level]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->done and $self->indent == $self->offset->[$self->level]) 325 118 443
Condition100%3/3
not $self->done and $self->indent == $self->offset->[$self->level]
!ll&&!rl&&r
9523325
MC/DC100%2/2
not $self->done and $self->indent == $self->offset->[$self->level]
not $self->done $self->indent == $self->offset->[$self->level]
Truth table100%3/3
not(A) and B
A= not $self->doneB= $self->indent == $self->offset->[$self->level]
ABresult
0X0
100
111
374 325 ▶ if ($self->content =~ /^-(?: (.*))?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->content =~ /^-(?: (.*))?$/) { } 324 1 325
375 324 ▶ $self->preface(defined($1) ? $1 : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 312 12 324
376 }
377 else {
378 1 $self->die('YAML_LOAD_ERR_BAD_SEQ_ELEMENT');
379 }
380  
381 # Check whether the preface looks like a YAML mapping ("key: value").
382 # This is complicated because it has to account for the possibility
383 # that a key is a quoted string, which itself may contain escaped
384 # quotes.
385 324 my $preface = $self->preface;
386 324 ▶ if ( $preface =~ /^ (\s*) ( \w .*? \: (?:\ |$).*) $/x or
Branch: 1 branch
BranchTrueFalseTotal
if ($preface =~ /^ (\s*) ( \w .*? \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x) { } 36 288 324
Condition83%5/6
$preface =~ /^ (\s*) ( \w .*? \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x
l!l&&r!l&&!r
360288
$preface =~ /^ (\s*) ( \w .*? \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x
l!l&&r!l&&!r
333288
MC/DC66%2/3
$preface =~ /^ (\s*) ( \w .*? \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x
$preface =~ /^ (\s*) ( \w .*? \: (?:\ |$).*) $/x $preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x
Truth table75%3/4
A or B or C
A= $preface =~ /^ (\s*) ( \w .*? \: (?:\ |$).*) $/xB= $preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/xC= $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x
ABCresult
1XX1
01X1
0011
0000
387 $preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or
388 $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x
389 ) {
390 36 $self->indent($self->offset->[$self->level] + 2 + length($1));
391 36 $self->content($2);
392 36 $self->level($self->level + 1);
393 36 $self->offset->[$self->level] = $self->indent;
394 36 $self->preface('');
395 36 push @$seq, $self->_parse_mapping('');
396 36 $self->{level}--;
397 36 $#{$self->offset} = $self->level;
398 }
399 else {
400 288 $self->_parse_next_line(COLLECTION);
401 286 push @$seq, $self->_parse_node();
402 }
403 }
404 118 return $seq;
405 }
406  
407 # Parse an inline value. Since YAML supports inline collections, this is
408 # the top level of a sub parsing.
409 2640 ▶sub _parse_inline {
Subroutine _parse_inline: called CC=24 SCAR=37.2
410 2640 my $self = shift;
411 2640 my ($top, $top_implicit, $top_explicit) = (@_, '', '', '');
412 2640 $self->{inline} =~ s/^\s*(.*)\s*$/$1/; # OUCH - mugwump
413 2640 my ($node, $anchor, $alias, $explicit, $implicit) = ('') x 5;
414 2640 ($anchor, $alias, $explicit, $implicit, $self->{inline}) =
415 $self->_parse_qualifiers($self->inline);
416 2640 ▶ if ($anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anchor) 0 2640 2640
417 0 $self->anchor2node->{$anchor} = CORE::bless [], 'YAML-anchor2node';
418 }
419 2640 ▶ $implicit ||= $top_implicit;
Condition66%2/3
$implicit ||= $top_implicit
l!l&&r!l&&!r
022638
MC/DC50%1/2
$implicit ||= $top_implicit
$implicit $top_implicit
Truth table66%2/3
A ||= B
A= $implicitB= $top_implicit
ABresult
1X1
011
000
420 2640 ▶ $explicit ||= $top_explicit;
Condition100%3/3
$explicit ||= $top_explicit
l!l&&r!l&&!r
2152623
MC/DC100%2/2
$explicit ||= $top_explicit
$explicit $top_explicit
Truth table100%3/3
A ||= B
A= $explicitB= $top_explicit
ABresult
1X1
011
000
421 2640 ($top_implicit, $top_explicit) = ('', '');
422 2640 ▶ if ($alias) {
Branch: 5 branches
BranchTrueFalseTotal
if ($alias) { } 0 2640 2640
elsif ($self->inline =~ /^\{/) { } 24 2616 2640
elsif ($self->inline =~ /^\[/) { } 28 2588 2616
elsif ($self->inline =~ /^"/) { } 22 2566 2588
elsif ($self->inline =~ /^'/) { } 52 2514 2566
423 $self->die('YAML_PARSE_ERR_NO_ANCHOR', $alias)
424 0 ▶ unless defined $self->anchor2node->{$alias};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->anchor2node->{$alias} 0 0 0
425 0 ▶ if (ref($self->anchor2node->{$alias}) ne 'YAML-anchor2node') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->anchor2node->{$alias} ne 'YAML-anchor2node') { } 0 0 0
426 0 $node = $self->anchor2node->{$alias};
427 }
428 else {
429 0 $node = do {my $sv = "*$alias"};
430 0 push @{$self->anchor2node->{$alias}}, [\$node, $self->line];
431 }
432 }
433 elsif ($self->inline =~ /^\{/) {
434 24 $node = $self->_parse_inline_mapping($anchor);
435 }
436 elsif ($self->inline =~ /^\[/) {
437 28 $node = $self->_parse_inline_seq($anchor);
438 }
439 elsif ($self->inline =~ /^"/) {
440 22 $node = $self->_parse_inline_double_quoted();
441 21 $node = $self->_unescape($node);
442 21 ▶ $node = $self->_parse_implicit($node) if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 2 19 21
443 }
444 elsif ($self->inline =~ /^'/) {
445 52 $node = $self->_parse_inline_single_quoted();
446 51 ▶ $node = $self->_parse_implicit($node) if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 0 51 51
447 }
448 else {
449 2514 ▶ if ($top) {
Branch: 1 branch
BranchTrueFalseTotal
if ($top) { } 1130 1384 2514
450 1130 $node = $self->inline;
451 1130 $self->inline('');
452 }
453 else {
454 1384 $node = $self->_parse_inline_simple();
455 }
456 2513 ▶ $node = $self->_parse_implicit($node) unless $explicit;
Branch: 1 branch
BranchTrueFalseTotal
unless $explicit 2505 8 2513
457  
458 2512 ▶ if ($self->numify and defined $node and not ref $node and length $node
Branch: 1 branch
BranchTrueFalseTotal
if ($self->numify and defined $node and not ref $node and length $node and $node =~ /\A-?(?:0|[1-9][0-9]*)?(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?\z/) 3 2509 2512
Condition75%9/12
$self->numify and defined $node and not ref $node and length $node and $node =~ /\A-?(?:0|[1-9][0-9]*)?(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?\z/
!ll&&!rl&&r
250633
$self->numify and defined $node and not ref $node and length $node
!ll&&!rl&&r
250606
$self->numify and defined $node and not ref $node
!ll&&!rl&&r
250606
$self->numify and defined $node
!ll&&!rl&&r
250606
MC/DC40%2/5
$self->numify and defined $node and not ref $node and length $node and $node =~ /\A-?(?:0|[1-9][0-9]*)?(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?\z/
$self->numify defined $node not ref $node length $node $node =~ /\A-?(?:0|[1-9][0-9]*)?(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?\z/
Truth table50%3/6
A and B and not(C) and D and E
A= $self->numifyB= defined $nodeC= not ref $nodeD= length $nodeE= $node =~ /\A-?(?:0|[1-9][0-9]*)?(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?\z/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
459 and $node =~ m/\A-?(?:0|[1-9][0-9]*)?(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?\z/) {
460 3 $node += 0;
461 }
462 }
463 2633 ▶ if ($explicit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($explicit) 17 2616 2633
464 17 $node = $self->_parse_explicit($node, $explicit);
465 }
466 2633 ▶ if ($anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anchor) 0 2633 2633
467 0 ▶ if (ref($self->anchor2node->{$anchor}) eq 'YAML-anchor2node') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->anchor2node->{$anchor} eq "YAML-anchor2node") 0 0 0
468 0 for my $ref (@{$self->anchor2node->{$anchor}}) {
469 0 ${$ref->[0]} = $node;
470 0 $self->warn('YAML_LOAD_WARN_UNRESOLVED_ALIAS',
471 $anchor, $ref->[1]);
472 }
473 }
474 0 $self->anchor2node->{$anchor} = $node;
475 }
476 2633 return $node;
477 }
478  
479 # Parse the inline YAML mapping into a Perl hash
480 24 ▶sub _parse_inline_mapping {
Subroutine _parse_inline_mapping: called CC=7 SCAR=19.7
481 24 my $self = shift;
482 24 my ($anchor) = @_;
483 24 my $node = {};
484 24 $self->anchor2node->{$anchor} = $node;
485  
486 $self->die('YAML_PARSE_ERR_INLINE_MAP')
487 24 ▶ unless $self->{inline} =~ s/^\{\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inline"} =~ s/^\{\s*// 0 24 24
488 24 ▶ while (not $self->{inline} =~ s/^\s*\}\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inline"} =~ s/^\s*\}\s*//) 24 23 47
489 24 my $key = $self->_parse_inline();
490 $self->die('YAML_PARSE_ERR_INLINE_MAP')
491 24 ▶ unless $self->{inline} =~ s/^\: \s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inline"} =~ s/^\: \s*// 1 23 24
492 23 my $value = $self->_parse_inline();
493 23 ▶ if (exists $node->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{$key}) { } 0 23 23
494 0 $self->warn('YAML_LOAD_WARN_DUPLICATE_KEY', $key);
495 }
496 else {
497 23 $node->{$key} = $value;
498 }
499 23 ▶ next if $self->inline =~ /^\s*\}/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->inline =~ /^\s*\}/ 14 9 23
500 $self->die('YAML_PARSE_ERR_INLINE_MAP')
501 9 ▶ unless $self->{inline} =~ s/^\,\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inline"} =~ s/^\,\s*// 0 9 9
502 }
503 23 return $node;
504 }
505  
506 # Parse the inline YAML sequence into a Perl array
507 28 ▶sub _parse_inline_seq {
Subroutine _parse_inline_seq: called CC=5 SCAR=16.1
508 28 my $self = shift;
509 28 my ($anchor) = @_;
510 28 my $node = [];
511 28 $self->anchor2node->{$anchor} = $node;
512  
513 $self->die('YAML_PARSE_ERR_INLINE_SEQUENCE')
514 28 ▶ unless $self->{inline} =~ s/^\[\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inline"} =~ s/^\[\s*// 0 28 28
515 28 ▶ while (not $self->{inline} =~ s/^\s*\]\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inline"} =~ s/^\s*\]\s*//) 52 26 78
516 52 my $value = $self->_parse_inline();
517 51 push @$node, $value;
518 51 ▶ next if $self->inline =~ /^\s*\]/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->inline =~ /^\s*\]/ 18 33 51
519 $self->die('YAML_PARSE_ERR_INLINE_SEQUENCE')
520 33 ▶ unless $self->{inline} =~ s/^\,\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inline"} =~ s/^\,\s*// 1 32 33
521 }
522 26 return $node;
523 }
524  
525 # Parse the inline double quoted string.
526 22 ▶sub _parse_inline_double_quoted {
Subroutine _parse_inline_double_quoted: called CC=2 SCAR=6.9
527 22 my $self = shift;
528 22 my $node;
529 # https://rt.cpan.org/Public/Bug/Display.html?id=90593
530 22 ▶ if ($self->inline =~ /^"((?:(?:\\"|[^"]){0,32766}){0,32766})"\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inline =~ /^"((?:(?:\\"|[^"]){0,32766}){0,32766})"\s*(.*)$/) { } 21 1 22
531 21 $node = $1;
532 21 $self->inline($2);
533 21 $node =~ s/\\"/"/g;
534 }
535 else {
536 1 $self->die('YAML_PARSE_ERR_BAD_DOUBLE');
537 }
538 21 return $node;
539 }
540  
541  
542 # Parse the inline single quoted string.
543 52 ▶sub _parse_inline_single_quoted {
Subroutine _parse_inline_single_quoted: called CC=2 SCAR=6.9
544 52 my $self = shift;
545 52 my $node;
546 52 ▶ if ($self->inline =~ /^'((?:(?:''|[^']){0,32766}){0,32766})'\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inline =~ /^'((?:(?:''|[^']){0,32766}){0,32766})'\s*(.*)$/) { } 51 1 52
547 51 $node = $1;
548 51 $self->inline($2);
549 51 $node =~ s/''/'/g;
550 }
551 else {
552 1 $self->die('YAML_PARSE_ERR_BAD_SINGLE');
553 }
554 51 return $node;
555 }
556  
557 # Parse the inline unquoted string and do implicit typing.
558 1384 ▶sub _parse_inline_simple {
Subroutine _parse_inline_simple: called CC=2 SCAR=6.9
559 1384 my $self = shift;
560 1384 my $value;
561 1384 ▶ if ($self->inline =~ /^(|[^!@#%^&*].*?)(?=[\[\]\{\},]|, |: |- |:\s*$|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inline =~ /^(|[^!\@#%^&*].*?)(?=[\[\]\{\},]|, |: |- |:\s*$|$)/) { } 1383 1 1384
562 1383 $value = $1;
563 1383 substr($self->{inline}, 0, length($1)) = '';
564 }
565 else {
566 1 $self->die('YAML_PARSE_ERR_BAD_INLINE_IMPLICIT', $value);
567 }
568 1383 return $value;
569 }
570  
571 2508 ▶sub _parse_implicit {
Subroutine _parse_implicit: called CC=5 SCAR=16.1
572 2508 my $self = shift;
573 2508 my ($value) = @_;
574 2508 $value =~ s/\s*$//;
575 2508 ▶ return $value if $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "" 4 2504 2508
576 2504 ▶ return undef if $value =~ /^~$/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^~$/ 4 2500 2504
577 2500 ▶ return $value
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^[\@\`]/ or $value =~ /^[\-\?]\s/ 2498 2 2500
Condition100%3/3
$value =~ /^[\@\`]/ or $value =~ /^[\-\?]\s/
l!l&&r!l&&!r
112498
MC/DC100%2/2
$value =~ /^[\@\`]/ or $value =~ /^[\-\?]\s/
$value =~ /^[\@\`]/ $value =~ /^[\-\?]\s/
Truth table100%3/3
A or B
A= $value =~ /^[\@\`]/B= $value =~ /^[\-\?]\s/
ABresult
1X1
011
000
578 unless $value =~ /^[\@\`]/ or
579 $value =~ /^[\-\?]\s/;
580 2 $self->die('YAML_PARSE_ERR_BAD_IMPLICIT', $value);
581 }
582  
583 # Unfold a YAML multiline scalar into a single string.
584 17 ▶sub _parse_unfold {
Subroutine _parse_unfold: called CC=5 SCAR=16.1
585 17 my $self = shift;
586 17 my ($chomp) = @_;
587 17 my $node = '';
588 17 my $space = 0;
589 17 ▶ while (not $self->done and $self->indent == $self->offset->[$self->level]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->done and $self->indent == $self->offset->[$self->level]) 54 17 71
Condition100%3/3
not $self->done and $self->indent == $self->offset->[$self->level]
!ll&&!rl&&r
12554
MC/DC100%2/2
not $self->done and $self->indent == $self->offset->[$self->level]
not $self->done $self->indent == $self->offset->[$self->level]
Truth table100%3/3
not(A) and B
A= not $self->doneB= $self->indent == $self->offset->[$self->level]
ABresult
0X0
100
111
590 54 $node .= $self->content. "\n";
591 54 $self->_parse_next_line(LEAF);
592 }
593 17 $node =~ s/^(\S.*)\n(?=\S)/$1 /gm;
594 17 $node =~ s/^(\S.*)\n(\n+\S)/$1$2/gm;
595 17 ▶ $node =~ s/\n*\Z// unless $chomp eq '+';
Branch: 1 branch
BranchTrueFalseTotal
unless $chomp eq "+" 16 1 17
596 17 ▶ $node .= "\n" unless $chomp;
Branch: 1 branch
BranchTrueFalseTotal
unless $chomp 15 2 17
597 17 return $node;
598 }
599  
600 # Parse a YAML block style scalar. This is like a Perl here-document.
601 38 ▶sub _parse_block {
Subroutine _parse_block: called CC=5 SCAR=16.1
602 38 my $self = shift;
603 38 my ($chomp) = @_;
604 38 my $node = '';
605 38 ▶ while (not $self->done and $self->indent == $self->offset->[$self->level]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->done and $self->indent == $self->offset->[$self->level]) 130 38 168
Condition100%3/3
not $self->done and $self->indent == $self->offset->[$self->level]
!ll&&!rl&&r
1820130
MC/DC100%2/2
not $self->done and $self->indent == $self->offset->[$self->level]
not $self->done $self->indent == $self->offset->[$self->level]
Truth table100%3/3
not(A) and B
A= not $self->doneB= $self->indent == $self->offset->[$self->level]
ABresult
0X0
100
111
606 130 $node .= $self->content . "\n";
607 130 $self->_parse_next_line(LEAF);
608 }
609 38 ▶ return $node if '+' eq $chomp;
Branch: 1 branch
BranchTrueFalseTotal
if "+" eq $chomp 3 35 38
610 35 $node =~ s/\n*\Z/\n/;
611 35 ▶ $node =~ s/\n\Z// if $chomp eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $chomp eq "-" 13 22 35
612 35 return $node;
613 }
614  
615 # Handle Perl style '#' comments. Comments must be at the same indentation
616 # level as the collection line following them.
617 2529 ▶sub _parse_throwaway_comments {
Subroutine _parse_throwaway_comments: called CC=3 SCAR=11.0
618 2529 my $self = shift;
619 2529 ▶ while (@{$self->lines} and
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->lines;} and $self->lines->[0] =~ /^\s*(\#|$)/) 527 2529 3056
Condition100%3/3
@{$self->lines;} and $self->lines->[0] =~ /^\s*(\#|$)/
!ll&&!rl&&r
442485527
MC/DC100%2/2
@{$self->lines;} and $self->lines->[0] =~ /^\s*(\#|$)/
@{$self->lines;} $self->lines->[0] =~ /^\s*(\#|$)/
Truth table100%3/3
A and B
A= @{$self->lines;}B= $self->lines->[0] =~ /^\s*(\#|$)/
ABresult
0X0
100
111
620 $self->lines->[0] =~ m{^\s*(\#|$)}
621 ) {
622 527 shift @{$self->lines};
623 527 $self->{line}++;
624 }
625 2529 $self->eos($self->{done} = not @{$self->lines});
626 }
627  
628 # This is the routine that controls what line is being parsed. It gets called
629 # once for each line in the YAML stream.
630 #
631 # This routine must:
632 # 1) Skip past the current line
633 # 2) Determine the indentation offset for a new level
634 # 3) Find the next _content_ line
635 # A) Skip over any throwaways (Comments/blanks)
636 # B) Set $self->indent, $self->content, $self->line
637 # 4) Expand tabs appropriately
638 2094 ▶sub _parse_next_line {
Subroutine _parse_next_line: called CC=30 SCAR=34.2
639 2094 my $self = shift;
640 2094 my ($type) = @_;
641 2094 my $level = $self->level;
642 2094 my $offset = $self->offset->[$level];
643 2094 ▶ $self->die('YAML_EMIT_ERR_BAD_LEVEL') unless defined $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 2094 2094
644 2094 shift @{$self->lines};
645 2094 $self->eos($self->{done} = not @{$self->lines});
646 2094 ▶ if ($self->eos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eos) 219 1875 2094
647 219 $self->offset->[$level + 1] = $offset + 1;
648 219 return;
649 }
650 1875 $self->{line}++;
651  
652 # Determine the offset for a new leaf node
653 1875 ▶ if ($self->preface =~
Branch: 2 branches
BranchTrueFalseTotal
if ($self->preface =~ qr/(?:^|\s)(?:$FOLD_CHAR|$LIT_CHAR_RX)(?:-|\+)?(\d*)\s*$/) { } 56 1819 1875
elsif ($type == 2 and $self->preface =~ /^(\s*(\!\S*|\&\S+))*\s*$/) { } 596 1384 1980
654 qr/(?:^|\s)(?:$FOLD_CHAR|$LIT_CHAR_RX)(?:-|\+)?(\d*)\s*$/
655 ) {
656 56 ▶ $self->die('YAML_PARSE_ERR_ZERO_INDENT')
Branch: 1 branch
BranchTrueFalseTotal
if length $1 and $1 == 0 1 55 56
Condition100%3/3
length $1 and $1 == 0
!ll&&!rl&&r
5141
MC/DC100%2/2
length $1 and $1 == 0
length $1 $1 == 0
Truth table100%3/3
A and B
A= length $1B= $1 == 0
ABresult
0X0
100
111
657 if length($1) and $1 == 0;
658 55 $type = LEAF;
659 55 ▶ if (length($1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $1) { } 4 51 55
660 4 $self->offset->[$level + 1] = $offset + $1;
661 }
662 else {
663 # First get rid of any comments.
664 51 ▶ while (@{$self->lines} && ($self->lines->[0] =~ /^\s*#/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->lines;} and $self->lines->[0] =~ /^\s*#/) 1 50 51
Condition66%2/3
@{$self->lines;} and $self->lines->[0] =~ /^\s*#/
!ll&&!rl&&r
0501
MC/DC50%1/2
@{$self->lines;} and $self->lines->[0] =~ /^\s*#/
@{$self->lines;} $self->lines->[0] =~ /^\s*#/
Truth table66%2/3
A and B
A= @{$self->lines;}B= $self->lines->[0] =~ /^\s*#/
ABresult
0X0
100
111
665 1 $self->lines->[0] =~ /^( *)/;
666 1 ▶ last unless length($1) <= $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless length $1 <= $offset 1 0 1
667 0 shift @{$self->lines};
668 0 $self->{line}++;
669 }
670 51 $self->eos($self->{done} = not @{$self->lines});
671 51 ▶ return if $self->eos;
Branch: 1 branch
BranchTrueFalseTotal
if $self->eos 0 51 51
672 51 ▶ if ($self->lines->[0] =~ /^( *)\S/ and length($1) > $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lines->[0] =~ /^( *)\S/ and length $1 > $offset) { } 50 1 51
Condition66%2/3
$self->lines->[0] =~ /^( *)\S/ and length $1 > $offset
!ll&&!rl&&r
0150
MC/DC50%1/2
$self->lines->[0] =~ /^( *)\S/ and length $1 > $offset
$self->lines->[0] =~ /^( *)\S/ length $1 > $offset
Truth table66%2/3
A and B
A= $self->lines->[0] =~ /^( *)\S/B= length $1 > $offset
ABresult
0X0
100
111
673 50 $self->offset->[$level+1] = length($1);
674 }
675 else {
676 1 $self->offset->[$level+1] = $offset + 1;
677 }
678 }
679 55 $offset = $self->offset->[++$level];
680 }
681 # Determine the offset for a new collection level
682 ▶ elsif ($type == COLLECTION and
Condition100%3/3
$type == 2 and $self->preface =~ /^(\s*(\!\S*|\&\S+))*\s*$/
!ll&&!rl&&r
1611062596
MC/DC100%2/2
$type == 2 and $self->preface =~ /^(\s*(\!\S*|\&\S+))*\s*$/
$type == 2 $self->preface =~ /^(\s*(\!\S*|\&\S+))*\s*$/
Truth table100%3/3
A and B
A= $type == 2B= $self->preface =~ /^(\s*(\!\S*|\&\S+))*\s*$/
ABresult
0X0
100
111
683 $self->preface =~ /^(\s*(\!\S*|\&\S+))*\s*$/) {
684 596 $self->_parse_throwaway_comments();
685 596 ▶ if ($self->eos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eos) { } 0 596 596
686 0 $self->offset->[$level+1] = $offset + 1;
687 0 return;
688 }
689 else {
690 596 ▶ $self->lines->[0] =~ /^( *)\S/ or
Branch: 1 branch
BranchTrueFalseTotal
$self->lines->[0] =~ /^( *)\S/ or $self->die("YAML_PARSE_ERR_NONSPACE_INDENTATION") 595 1 596
691 $self->die('YAML_PARSE_ERR_NONSPACE_INDENTATION');
692 595 ▶ if (length($1) > $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $1 > $offset) { } 592 3 595
693 592 $self->offset->[$level+1] = length($1);
694 }
695 else {
696 3 $self->offset->[$level+1] = $offset + 1;
697 }
698 }
699 595 $offset = $self->offset->[++$level];
700 }
701  
702 1873 ▶ if ($type == LEAF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 1) { } 216 1657 1873
703 216 ▶ while (@{$self->lines} and
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/ and length $1 < $offset) 11 216 227
Condition100%6/6
@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/ and length $1 < $offset
!ll&&!rl&&r
208811
@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/
!ll&&!rl&&r
120719
MC/DC100%3/3
@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/ and length $1 < $offset
@{$self->lines;} $self->lines->[0] =~ /^( *)(\#)/ length $1 < $offset
Truth table100%4/4
A and B and C
A= @{$self->lines;}B= $self->lines->[0] =~ /^( *)(\#)/C= length $1 < $offset
ABCresult
0XX0
10X0
1100
1111
704 $self->lines->[0] =~ m{^( *)(\#)} and
705 length($1) < $offset
706 ) {
707 11 shift @{$self->lines};
708 11 $self->{line}++;
709 }
710 216 $self->eos($self->{done} = not @{$self->lines});
711 }
712 else {
713 1657 $self->_parse_throwaway_comments();
714 }
715 1873 ▶ return if $self->eos;
Branch: 1 branch
BranchTrueFalseTotal
if $self->eos 7 1866 1873
716  
717 1866 ▶ if ($self->lines->[0] =~ /^---(\s|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lines->[0] =~ /^---(\s|$)/) 38 1828 1866
718 38 $self->done(1);
719 38 return;
720 }
721 1828 ▶ if ($type == LEAF and
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 1 and $self->lines->[0] =~ /^ {$offset}(.*)$/) { } 169 1659 1828
elsif ($self->lines->[0] =~ /^\s*$/) { } 15 1644 1659
Condition100%3/3
$type == 1 and $self->lines->[0] =~ /^ {$offset}(.*)$/
!ll&&!rl&&r
161940169
MC/DC100%2/2
$type == 1 and $self->lines->[0] =~ /^ {$offset}(.*)$/
$type == 1 $self->lines->[0] =~ /^ {$offset}(.*)$/
Truth table100%3/3
A and B
A= $type == 1B= $self->lines->[0] =~ /^ {$offset}(.*)$/
ABresult
0X0
100
111
722 $self->lines->[0] =~ /^ {$offset}(.*)$/
723 ) {
724 169 $self->indent($offset);
725 169 $self->content($1);
726 }
727 elsif ($self->lines->[0] =~ /^\s*$/) {
728 15 $self->indent($offset);
729 15 $self->content('');
730 }
731 else {
732 1644 $self->lines->[0] =~ /^( *)(\S.*)$/;
733 1644 ▶ while ($self->offset->[$level] > length($1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->offset->[$level] > length $1) 380 1644 2024
734 380 $level--;
735 }
736 1644 ▶ $self->die('YAML_PARSE_ERR_INCONSISTENT_INDENTATION')
Branch: 1 branch
BranchTrueFalseTotal
if $self->offset->[$level] != length $1 4 1640 1644
737 if $self->offset->[$level] != length($1);
738 1640 $self->indent(length($1));
739 1640 $self->content($2);
740 }
741 1824 ▶ $self->die('YAML_PARSE_ERR_INDENTATION')
Branch: 1 branch
BranchTrueFalseTotal
if $self->indent - $offset > 1 0 1824 1824
742 if $self->indent - $offset > 1;
743 }
744  
745 #==============================================================================
746 # Utility subroutines.
747 #==============================================================================
748  
749 # Printable characters for escapes
750 32 my %unescapes = (
751 0 => "\x00",
752 a => "\x07",
753 t => "\x09",
754 n => "\x0a",
755 'v' => "\x0b", # Potential v-string error on 5.6.2 if not quoted
756 f => "\x0c",
757 r => "\x0d",
758 e => "\x1b",
759 '\\' => '\\',
760 );
761  
762 # Transform all the backslash style escape characters to their literal meaning
763 21 ▶sub _unescape {
Subroutine _unescape: called CC=2 SCAR=7.0
764 21 my $self = shift;
765 21 my ($node) = @_;
766 21 $node =~ s/\\([never\\fart0]|x([0-9a-fA-F]{2}))/
767 18 ▶ (length($1)>1)?pack("H2",$2):$unescapes{$1}/gex;
Branch: 1 branch
BranchTrueFalseTotal
length $1 > 1 ? : 0 18 18
768 21 return $node;
769 }
770  
771 32 1;
↑ Summary Old/Dumper.pm »