YAML/Loader.pm

filter: Statementstmt 92.9% 459 / 494 Branchbran 87.6% 263 / 300 Conditioncond 87.1% 95 / 109 MC/DCmcdc 75.8% 47 / 62 Subroutinesub 100% 28 / 28 Podpod 0.0% 0 / 1 totaltotal 89.7% 892 / 994 CC 192 SCAR 30.8
CC
192
Cov
90%
_parse_inline
41.5
_parse_next_line
40.2
_parse_node
27.4
CRAP 21.8
↑ Summary YAML/Dumper.pm »
1 package YAML::Loader;
2  
3 36 ▶use YAML::Mo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 36 extends 'YAML::Loader::Base';
5  
6 36 ▶use YAML::Loader::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 36 ▶use YAML::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 36 ▶use YAML::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Context constants
11 36 ▶use constant LEAF => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 36 ▶use constant COLLECTION => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 36 ▶use constant VALUE => "\x07YAML\x07VALUE\x07";
Subroutine BEGIN: called CC=1 SCAR=0.0
14 36 ▶use constant COMMENT => "\x07YAML\x07COMMENT\x07";
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # Common YAML character sets
17 36 my $ESCAPE_CHAR = '[\\x00-\\x08\\x0b-\\x0d\\x0e-\\x1f]';
18 36 my $FOLD_CHAR = '>';
19 36 my $LIT_CHAR = '|';
20 36 my $LIT_CHAR_RX = "\\$LIT_CHAR";
21  
22 319 ▶sub load {
Subroutine load: called CC=2 SCAR=7.1
Pod undocumented
23 319 my $self = shift;
24 319 ▶ $self->stream($_[0] || '');
Condition50%1/2
$_[0] || ''
l!l
3190
MC/DC0%0/1
$_[0] || ''
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
25 319 return $self->_parse();
26 }
27  
28 # Top level function for parsing. Parse each document in order and
29 # handle processing for YAML headers.
30 319 ▶sub _parse {
Subroutine _parse: called CC=18 SCAR=28.9
31 319 my $self = shift;
32 319 my (%directives, $preface);
33 319 $self->{stream} =~ s|\015\012|\012|g;
34 319 $self->{stream} =~ s|\015|\012|g;
35 319 $self->line(0);
36 319 ▶ $self->die('YAML_PARSE_ERR_BAD_CHARS')
Branch: 1 branch
BranchTrueFalseTotal
if $self->stream =~ /$ESCAPE_CHAR/ 1 318 319
37 if $self->stream =~ /$ESCAPE_CHAR/;
38 318 $self->{stream} =~ s/(.)\n\Z/$1/s;
39 318 $self->lines([split /\x0a/, $self->stream, -1]);
40 318 $self->line(1);
41 # Throw away any comments or blanks before the header (or start of
42 # content for headerless streams)
43 318 $self->_parse_throwaway_comments();
44 318 $self->document(0);
45 318 $self->documents([]);
46 318 $self->zero_indent([]);
47 # Add an "assumed" header if there is no header and the stream is
48 # not empty (after initial throwaways).
49 318 ▶ if (not $self->eos) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eos) 280 38 318
50 280 ▶ if ($self->lines->[0] !~ /^---(\s|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->lines->[0] =~ /^---(\s|$)/) 36 244 280
51 36 unshift @{$self->lines}, '---';
52 36 $self->{line}--;
53 }
54 }
55  
56 # Main Loop. Parse out all the top level nodes and return them.
57 318 ▶ while (not $self->eos) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eos) 318 285 603
58 318 $self->anchor2node({});
59 318 $self->{document}++;
60 318 $self->done(0);
61 318 $self->level(0);
62 318 $self->offset->[0] = -1;
63  
64 318 ▶ if ($self->lines->[0] =~ /^---\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lines->[0] =~ /^---\s*(.*)$/) { } 318 0 318
65 318 my @words = split /\s/, $1;
66 318 %directives = ();
67 318 ▶ while (@words) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words) 127 208 335
68 127 ▶ if ($words[0] =~ /^#(\w+):(\S.*)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($words[0] =~ /^#(\w+):(\S.*)$/) { } 17 110 127
elsif ($words[0] eq '') { } 0 110 110
69 17 my ($key, $value) = ($1, $2);
70 17 shift(@words);
71 17 ▶ if (defined $directives{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $directives{$key}) 2 15 17
72 2 $self->warn('YAML_PARSE_WARN_MULTIPLE_DIRECTIVES',
73 $key, $self->document);
74 2 next;
75 }
76 15 $directives{$key} = $value;
77 }
78 elsif ($words[0] eq '') {
79 0 shift @words;
80 }
81 else {
82 110 last;
83 }
84 }
85 318 $self->preface(join ' ', @words);
86 }
87 else {
88 0 $self->die('YAML_PARSE_ERR_NO_SEPARATOR');
89 }
90  
91 318 ▶ if (not $self->done) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->done) 318 0 318
92 318 $self->_parse_next_line(COLLECTION);
93 }
94 316 ▶ if ($self->done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->done) 60 256 316
95 60 $self->{indent} = -1;
96 60 $self->content('');
97 }
98  
99 316 ▶ $directives{YAML} ||= '1.0';
Condition100%2/2
$directives{"YAML"} ||= "1.0"
l!l
12304
MC/DC100%1/1
$directives{"YAML"} ||= "1.0"
$directives{"YAML"}
Truth table100%2/2
A
A= $directives{"YAML"}
Aresult
11
00
100 316 ▶ $directives{TAB} ||= 'NONE';
Condition100%2/2
$directives{"TAB"} ||= "NONE"
l!l
2314
MC/DC100%1/1
$directives{"TAB"} ||= "NONE"
$directives{"TAB"}
Truth table100%2/2
A
A= $directives{"TAB"}
Aresult
11
00
101 ($self->{major_version}, $self->{minor_version}) =
102 316 split /\./, $directives{YAML}, 2;
103 $self->die('YAML_PARSE_ERR_BAD_MAJOR_VERSION', $directives{YAML})
104 316 ▶ if $self->major_version ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $self->major_version ne 1 1 315 316
105 $self->warn('YAML_PARSE_WARN_BAD_MINOR_VERSION', $directives{YAML})
106 315 ▶ if $self->minor_version ne '0';
Branch: 1 branch
BranchTrueFalseTotal
if $self->minor_version ne 0 1 314 315
107 $self->die('Unrecognized TAB policy')
108 315 ▶ unless $directives{TAB} =~ /^(NONE|\d+)(:HARD)?$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $directives{"TAB"} =~ /^(NONE|\d+)(:HARD)?$/ 1 314 315
109  
110 314 push @{$self->documents}, $self->_parse_node();
111 }
112 285 ▶ return wantarray ? @{$self->documents} : $self->documents->[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 151 134 285
113 }
114  
115 # This function is the dispatcher for parsing each node. Every node
116 # recurses back through here. (Inlines are an exception as they have
117 # their own sub-parser.)
118 2021 ▶sub _parse_node {
Subroutine _parse_node: called CC=26 SCAR=33.1
119 2021 my $self = shift;
120 2021 my $preface = $self->preface;
121 2021 $self->preface('');
122 2021 my ($node, $type, $indicator, $chomp, $parsed_inline) = ('') x 5;
123 2021 my ($anchor, $alias, $explicit, $implicit) = ('') x 4;
124 2021 ($anchor, $alias, $explicit, $implicit, $preface) =
125 $self->_parse_qualifiers($preface);
126 2012 ▶ if ($anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anchor) 20 1992 2012
127 20 $self->anchor2node->{$anchor} = CORE::bless [], 'YAML-anchor2node';
128 }
129 2012 $self->inline('');
130 2012 ▶ while (length $preface) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $preface) 1347 2011 3358
131 1347 ▶ if ($preface =~ s/^($FOLD_CHAR|$LIT_CHAR_RX)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preface =~ s/^($FOLD_CHAR|$LIT_CHAR_RX)//) { } 65 1282 1347
132 65 $indicator = $1;
133 65 ▶ if ($preface =~ s/^([+-])[0-9]*//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($preface =~ s/^([+-])[0-9]*//) { } 23 42 65
elsif ($preface =~ s/^[0-9]+([+-]?)//) { } 6 36 42
134 23 $chomp = $1;
135 }
136 elsif ($preface =~ s/^[0-9]+([+-]?)//) {
137 6 $chomp = $1;
138 }
139 65 ▶ if ($preface =~ s/^(?:\s+#.*$|\s*)$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preface =~ s/^(?:\s+#.*$|\s*)$//) { } 64 1 65
140 }
141 else {
142 1 $self->die('YAML_PARSE_ERR_TEXT_AFTER_INDICATOR');
143 }
144 }
145 else {
146 1282 $self->inline($preface);
147 1282 $preface = '';
148 }
149 }
150 2011 ▶ if ($alias) {
Branch: 4 branches
BranchTrueFalseTotal
if ($alias) { } 21 1990 2011
elsif (length $self->inline) { } 1282 708 1990
elsif ($indicator eq $LIT_CHAR) { } 44 664 708
elsif ($indicator eq $FOLD_CHAR) { } 20 644 664
151 $self->die('YAML_PARSE_ERR_NO_ANCHOR', $alias)
152 21 ▶ unless defined $self->anchor2node->{$alias};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->anchor2node->{$alias} 1 20 21
153 20 ▶ if (ref($self->anchor2node->{$alias}) ne 'YAML-anchor2node') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->anchor2node->{$alias} ne 'YAML-anchor2node') { } 20 0 20
154 20 $node = $self->anchor2node->{$alias};
155 }
156 else {
157 0 $node = do {my $sv = "*$alias"};
158 0 push @{$self->anchor2node->{$alias}}, [\$node, $self->line];
159 }
160 }
161 elsif (length $self->inline) {
162 1282 $node = $self->_parse_inline(1, $implicit, $explicit);
163 1274 $parsed_inline = 1;
164 1274 ▶ if (length $self->inline) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->inline) 1 1273 1274
165 1 $self->die('YAML_PARSE_ERR_SINGLE_LINE');
166 }
167 }
168 elsif ($indicator eq $LIT_CHAR) {
169 44 $self->{level}++;
170 44 $node = $self->_parse_block($chomp);
171 44 ▶ $node = $self->_parse_implicit($node) if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 0 44 44
172 44 $self->{level}--;
173 }
174 elsif ($indicator eq $FOLD_CHAR) {
175 20 $self->{level}++;
176 20 $node = $self->_parse_unfold($chomp);
177 20 ▶ $node = $self->_parse_implicit($node) if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 1 19 20
178 19 $self->{level}--;
179 }
180 else {
181 644 $self->{level}++;
182 644 ▶ $self->offset->[$self->level] ||= 0;
Condition100%2/2
$self->offset->[$self->level] ||= 0
l!l
406238
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
183 644 ▶ if ($self->indent == $self->offset->[$self->level]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->indent == $self->offset->[$self->level]) { } 629 15 644
184 629 ▶ if ($self->content =~ /^-( |$)/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->content =~ /^-( |$)/) { } 155 474 629
elsif ($self->content =~ /(^\?|\:( |$))/) { } 474 0 474
elsif ($preface =~ /^\s*$/) { } 0 0 0
185 155 $node = $self->_parse_seq($anchor);
186 }
187 elsif ($self->content =~ /(^\?|\:( |$))/) {
188 474 $node = $self->_parse_mapping($anchor);
189 }
190 elsif ($preface =~ /^\s*$/) {
191 0 $node = $self->_parse_implicit('');
192 }
193 else {
194 0 $self->die('YAML_PARSE_ERR_BAD_NODE');
195 }
196 }
197 else {
198 15 $node = undef;
199 }
200 616 $self->{level}--;
201 }
202 1972 $#{$self->offset} = $self->level;
203  
204 1972 ▶ if ($explicit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($explicit) 84 1888 1972
205 84 ▶ $node = $self->_parse_explicit($node, $explicit) if !$parsed_inline;
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed_inline 57 27 84
206 }
207 1971 ▶ if ($anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anchor) 20 1951 1971
208 20 ▶ if (ref($self->anchor2node->{$anchor}) eq 'YAML-anchor2node') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->anchor2node->{$anchor} eq "YAML-anchor2node") 10 10 20
209 # XXX Can't remember what this code actually does
210 10 for my $ref (@{$self->anchor2node->{$anchor}}) {
211 0 ${$ref->[0]} = $node;
212 0 $self->warn('YAML_LOAD_WARN_UNRESOLVED_ALIAS',
213 $anchor, $ref->[1]);
214 }
215 }
216 20 $self->anchor2node->{$anchor} = $node;
217 }
218 1971 return $node;
219 }
220  
221 # Preprocess the qualifiers that may be attached to any node.
222 4779 ▶sub _parse_qualifiers {
Subroutine _parse_qualifiers: called CC=14 SCAR=26.4
223 4779 my $self = shift;
224 4779 my ($preface) = @_;
225 4779 my ($anchor, $alias, $explicit, $implicit, $token) = ('') x 5;
226 4779 $self->inline('');
227 4779 ▶ while ($preface =~ /^[&*!]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preface =~ /^[&*!]/) 146 4770 4916
228 146 ▶ if ($preface =~ s/^\!(\S+)\s*//) {
Branch: 4 branches
BranchTrueFalseTotal
if ($preface =~ s/^\!(\S+)\s*//) { } 90 56 146
elsif ($preface =~ s/^\!\s*//) { } 5 51 56
elsif ($preface =~ s/^\&([^ ,:]*)\s*//) { } 25 26 51
elsif ($preface =~ s/^\*([^ ,:]*)\s*//) { } 26 0 26
229 90 ▶ $self->die('YAML_PARSE_ERR_MANY_EXPLICIT') if $explicit;
Branch: 1 branch
BranchTrueFalseTotal
if $explicit 1 89 90
230 89 $explicit = $1;
231 }
232 elsif ($preface =~ s/^\!\s*//) {
233 5 ▶ $self->die('YAML_PARSE_ERR_MANY_IMPLICIT') if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 1 4 5
234 4 $implicit = 1;
235 }
236 elsif ($preface =~ s/^\&([^ ,:]*)\s*//) {
237 25 $token = $1;
238 25 ▶ $self->die('YAML_PARSE_ERR_BAD_ANCHOR')
Branch: 1 branch
BranchTrueFalseTotal
unless $token =~ m[^[a-zA-Z0-9_./-]+$] 2 23 25
239 unless $token =~ /^[a-zA-Z0-9_.\/-]+$/;
240 23 ▶ $self->die('YAML_PARSE_ERR_MANY_ANCHOR') if $anchor;
Branch: 1 branch
BranchTrueFalseTotal
if $anchor 1 22 23
241 22 ▶ $self->die('YAML_PARSE_ERR_ANCHOR_ALIAS') if $alias;
Branch: 1 branch
BranchTrueFalseTotal
if $alias 0 22 22
242 22 $anchor = $token;
243 }
244 elsif ($preface =~ s/^\*([^ ,:]*)\s*//) {
245 26 $token = $1;
246 26 ▶ $self->die('YAML_PARSE_ERR_BAD_ALIAS')
Branch: 1 branch
BranchTrueFalseTotal
unless $token =~ m[^[a-zA-Z0-9_./-]+$] 2 24 26
247 unless $token =~ /^[a-zA-Z0-9_.\/-]+$/;
248 24 ▶ $self->die('YAML_PARSE_ERR_MANY_ALIAS') if $alias;
Branch: 1 branch
BranchTrueFalseTotal
if $alias 1 23 24
249 23 ▶ $self->die('YAML_PARSE_ERR_ANCHOR_ALIAS') if $anchor;
Branch: 1 branch
BranchTrueFalseTotal
if $anchor 1 22 23
250 22 $alias = $token;
251 }
252 }
253 4770 return ($anchor, $alias, $explicit, $implicit, $preface);
254 }
255  
256 # Morph a node to it's explicit type
257 88 ▶sub _parse_explicit {
Subroutine _parse_explicit: called CC=23 SCAR=31.6
258 88 my $self = shift;
259 88 my ($node, $explicit) = @_;
260 88 my ($type, $class);
261 88 ▶ if ($explicit =~ /^\!?perl\/(hash|array|ref|scalar)(?:\:(\w(\w|\:\:)*)?)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($explicit =~ m[^\!?perl/(hash|array|ref|scalar)(?:\:(\w(\w|\:\:)*)?)?$]) 44 44 88
262 44 ▶ ($type, $class) = (($1 || ''), ($2 || ''));
Condition75%3/4
$1 || ''
l!l
440
$2 || ''
l!l
1925
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
263  
264 # FIXME # die unless uc($type) eq ref($node) ?
265  
266 44 ▶ if ( $type eq "ref" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "ref") 22 22 44
267 $self->die('YAML_LOAD_ERR_NO_DEFAULT_VALUE', 'XXX', $explicit)
268 22 ▶ 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 21 22
Condition66%2/3
exists $node->{"\aYAML\aVALUE\a"} and scalar keys %$node == 1
!ll&&!rl&&r
1021
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
269  
270 21 my $value = $node->{VALUE()};
271 21 $node = \$value;
272 }
273  
274 43 ▶ 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) 4 39 43
Condition83%5/6
$type eq "scalar" and length $class and not ref $node
!ll&&!rl&&r
3904
$type eq "scalar" and length $class
!ll&&!rl&&r
3724
MC/DC66%2/3
$type eq "scalar" and length $class and not ref $node
$type eq "scalar" length $class not ref $node
Truth table75%3/4
A and B and not(C)
A= $type eq "scalar"B= length $classC= not ref $node
ABCresult
0XX0
10X0
1100
1111
275 4 my $value = $node;
276 4 $node = \$value;
277 }
278  
279 43 ▶ if ( length($class) and $YAML::LoadBlessed ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $class and $YAML::LoadBlessed) 9 34 43
Condition100%3/3
length $class and $YAML::LoadBlessed
!ll&&!rl&&r
24109
MC/DC100%2/2
length $class and $YAML::LoadBlessed
length $class $YAML::LoadBlessed
Truth table100%3/3
A and B
A= length $classB= $YAML::LoadBlessed
ABresult
0X0
100
111
280 9 CORE::bless($node, $class);
281 }
282  
283 43 return $node;
284 }
285 44 ▶ if ($explicit =~ m{^!?perl/(glob|regexp|code)(?:\:(\w(\w|\:\:)*)?)?$}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($explicit =~ m[^!?perl/(glob|regexp|code)(?:\:(\w(\w|\:\:)*)?)?$]) { } 22 22 44
elsif ($YAML::TagClass->{$explicit} or $explicit =~ m[^perl/(\@|\$)?([a-zA-Z](\w|::)+)$]) { } 15 7 22
elsif (ref $node) { } 5 2 7
286 22 ▶ ($type, $class) = (($1 || ''), ($2 || ''));
Condition75%3/4
$1 || ''
l!l
220
$2 || ''
l!l
517
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
287 22 my $type_class = "YAML::Type::$type";
288 36 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
289 22 ▶ if ($type_class->can('yaml_load')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_class->can('yaml_load')) { } 22 0 22
290 22 return $type_class->yaml_load($node, $class, $self);
291 }
292 else {
293 0 $self->die('YAML_LOAD_ERR_NO_CONVERT', 'XXX', $explicit);
294 }
295 }
296 # This !perl/@Foo and !perl/$Foo are deprecated but still parsed
297 ▶ elsif ($YAML::TagClass->{$explicit} ||
Condition100%3/3
$YAML::TagClass->{$explicit} or $explicit =~ m[^perl/(\@|\$)?([a-zA-Z](\w|::)+)$]
l!l&&r!l&&!r
2137
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
298 $explicit =~ m{^perl/(\@|\$)?([a-zA-Z](\w|::)+)$}
299 ) {
300 15 ▶ $class = $YAML::TagClass->{$explicit} || $2;
Condition66%2/3
$YAML::TagClass->{$explicit} || $2
l!l&&r!l&&!r
2130
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
301 15 ▶ if ($class->can('yaml_load')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class->can('yaml_load')) { } 4 11 15
elsif ($YAML::LoadBlessed) { } 5 6 11
302 4 require YAML::Node;
303 4 return $class->yaml_load(YAML::Node->new($node, $explicit));
304 }
305 elsif ($YAML::LoadBlessed) {
306 5 ▶ if (ref $node) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node) { } 5 0 5
307 5 return CORE::bless $node, $class;
308 }
309 else {
310 0 return CORE::bless \$node, $class;
311 }
312 }
313 else {
314 6 return $node;
315 }
316 }
317 elsif (ref $node) {
318 5 require YAML::Node;
319 5 return YAML::Node->new($node, $explicit);
320 }
321 else {
322 # XXX This is likely wrong. Failing test:
323 # --- !unknown 'scalar value'
324 2 return $node;
325 }
326 }
327  
328 # Parse a YAML mapping into a Perl hash
329 513 ▶sub _parse_mapping {
Subroutine _parse_mapping: called CC=9 SCAR=22.0
330 513 my $self = shift;
331 513 my ($anchor) = @_;
332 513 ▶ my $mapping = $self->preserve ? YAML::Node->new({}) : {};
Branch: 1 branch
BranchTrueFalseTotal
$self->preserve ? : 1 512 513
333 513 $self->anchor2node->{$anchor} = $mapping;
334 513 my $key;
335 513 ▶ 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]) 1386 506 1892
Condition100%3/3
not $self->done and $self->indent == $self->offset->[$self->level]
!ll&&!rl&&r
1753311386
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
336 # If structured key:
337 1386 ▶ if ($self->{content} =~ s/^\?\s*//) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'content'} =~ s/^\?\s*//) { } 5 1381 1386
elsif ($self->{'content'} =~ s/^\=\s*(?=:)//) { } 23 1358 1381
elsif ($self->{'content'} =~ s/^\=\s*(?=:)//) { } 0 1358 1358
338 5 $self->preface($self->content);
339 5 $self->_parse_next_line(COLLECTION);
340 5 $key = $self->_parse_node();
341 5 $key = "$key";
342 }
343 # If "default" key (equals sign)
344 elsif ($self->{content} =~ s/^\=\s*(?=:)//) {
345 23 $key = VALUE;
346 }
347 # If "comment" key (slash slash)
348 elsif ($self->{content} =~ s/^\=\s*(?=:)//) {
349 0 $key = COMMENT;
350 }
351 # Regular scalar key:
352 else {
353 1358 $self->inline($self->content);
354 1358 $key = $self->_parse_inline();
355 1358 $key = "$key";
356 1358 $self->content($self->inline);
357 1358 $self->inline('');
358 }
359  
360 1386 ▶ unless ($self->{content} =~ s/^:(?:\s+#.*$|\s*)//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"content"} =~ s/^:(?:\s+#.*$|\s*)//) 1 1385 1386
361 1 $self->die('YAML_LOAD_ERR_BAD_MAP_ELEMENT');
362 }
363 1385 $self->preface($self->content);
364 1385 my $level = $self->level;
365  
366 # we can get a zero indented sequence, possibly
367 1385 my $zero_indent = $self->zero_indent;
368 1385 $zero_indent->[ $level ] = 0;
369 1385 $self->_parse_next_line(COLLECTION);
370 1382 my $value = $self->_parse_node();
371 1379 $#$zero_indent = $level;
372  
373 1379 ▶ if (exists $mapping->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $mapping->{$key}) { } 2 1377 1379
374 2 $self->warn('YAML_LOAD_WARN_DUPLICATE_KEY', $key);
375 }
376 else {
377 1377 $mapping->{$key} = $value;
378 }
379 }
380 506 return $mapping;
381 }
382  
383 # Parse a YAML sequence into a Perl array
384 159 ▶sub _parse_seq {
Subroutine _parse_seq: called CC=11 SCAR=24.0
385 159 my $self = shift;
386 159 my ($anchor) = @_;
387 159 my $seq = [];
388 159 $self->anchor2node->{$anchor} = $seq;
389 159 ▶ 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]) 368 136 504
Condition100%3/3
not $self->done and $self->indent == $self->offset->[$self->level]
!ll&&!rl&&r
10828368
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
390 368 ▶ if ($self->content =~ /^-(?: (.*))?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->content =~ /^-(?: (.*))?$/) { } 365 3 368
391 365 ▶ $self->preface(defined($1) ? $1 : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 349 16 365
392 }
393 else {
394 3 ▶ if ($self->zero_indent->[ $self->level ]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->zero_indent->[$self->level]) 2 1 3
395 2 last;
396 }
397 1 $self->die('YAML_LOAD_ERR_BAD_SEQ_ELEMENT');
398 }
399  
400 # Check whether the preface looks like a YAML mapping ("key: value").
401 # This is complicated because it has to account for the possibility
402 # that a key is a quoted string, which itself may contain escaped
403 # quotes.
404 365 my $preface = $self->preface;
405 365 ▶ if ($preface =~ m/^ (\s*) ( - (?: \ .* | $ ) ) /x) {
Branch: 2 branches
BranchTrueFalseTotal
if ($preface =~ /^ (\s*) ( - (?: \ .* | $ ) ) /x) { } 4 361 365
elsif ($preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) (\?.*$)/x or $preface =~ /^ (\s*) ([^'"\s:#&!\[\]\{\},*|>].*\:(\ .*|$))/x) { } 39 322 361
406 4 $self->indent($self->offset->[$self->level] + 2 + length($1));
407 4 $self->content($2);
408 4 $self->level($self->level + 1);
409 4 $self->offset->[$self->level] = $self->indent;
410 4 $self->preface('');
411 4 push @$seq, $self->_parse_seq('');
412 4 $self->{level}--;
413 4 $#{$self->offset} = $self->level;
414 }
415 ▶ elsif (
Condition88%8/9
$preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) (\?.*$)/x or $preface =~ /^ (\s*) ([^'"\s:#&!\[\]\{\},*|>].*\:(\ .*|$))/x
l!l&&r!l&&!r
435322
$preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) (\?.*$)/x
l!l&&r!l&&!r
31357
$preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x
l!l&&r!l&&!r
30358
MC/DC75%3/4
$preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x or $preface =~ /^ (\s*) (\?.*$)/x or $preface =~ /^ (\s*) ([^'"\s:#&!\[\]\{\},*|>].*\:(\ .*|$))/x
$preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x $preface =~ /^ (\s*) (\?.*$)/x $preface =~ /^ (\s*) ([^'"\s:#&!\[\]\{\},*|>].*\:(\ .*|$))/x
Truth table80%4/5
A or B or C or D
A= $preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/xB= $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/xC= $preface =~ /^ (\s*) (\?.*$)/xD= $preface =~ /^ (\s*) ([^'"\s:#&!\[\]\{\},*|>].*\:(\ .*|$))/x
ABCDresult
1XXX1
01XX1
001X1
00011
00000
416 $preface =~ /^ (\s*) ((') (?:''|[^'])*? ' \s* \: (?:\ |$).*) $/x or
417 $preface =~ /^ (\s*) ((") (?:\\\\|[^"])*? " \s* \: (?:\ |$).*) $/x or
418 $preface =~ /^ (\s*) (\?.*$)/x or
419 $preface =~ /^ (\s*) ([^'"\s:#&!\[\]\{\},*|>].*\:(\ .*|$))/x
420 ) {
421 39 $self->indent($self->offset->[$self->level] + 2 + length($1));
422 39 $self->content($2);
423 39 $self->level($self->level + 1);
424 39 $self->offset->[$self->level] = $self->indent;
425 39 $self->preface('');
426 39 push @$seq, $self->_parse_mapping('');
427 39 $self->{level}--;
428 39 $#{$self->offset} = $self->level;
429 }
430 else {
431 322 $self->_parse_next_line(COLLECTION);
432 320 push @$seq, $self->_parse_node();
433 }
434 }
435 138 return $seq;
436 }
437  
438 # Parse an inline value. Since YAML supports inline collections, this is
439 # the top level of a sub parsing.
440 2758 ▶sub _parse_inline {
Subroutine _parse_inline: called CC=24 SCAR=37.2
441 2758 my $self = shift;
442 2758 my ($top, $top_implicit, $top_explicit) = (@_, '', '', '');
443 2758 $self->{inline} =~ s/^\s*(.*)\s*$/$1/; # OUCH - mugwump
444 2758 my ($node, $anchor, $alias, $explicit, $implicit) = ('') x 5;
445 2758 ($anchor, $alias, $explicit, $implicit, $self->{inline}) =
446 $self->_parse_qualifiers($self->inline);
447 2758 ▶ if ($anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anchor) 0 2758 2758
448 0 $self->anchor2node->{$anchor} = CORE::bless [], 'YAML-anchor2node';
449 }
450 2758 ▶ $implicit ||= $top_implicit;
Condition66%2/3
$implicit ||= $top_implicit
l!l&&r!l&&!r
022756
MC/DC50%1/2
$implicit ||= $top_implicit
$implicit $top_implicit
Truth table66%2/3
A ||= B
A= $implicitB= $top_implicit
ABresult
1X1
011
000
451 2758 ▶ $explicit ||= $top_explicit;
Condition100%3/3
$explicit ||= $top_explicit
l!l&&r!l&&!r
4272727
MC/DC100%2/2
$explicit ||= $top_explicit
$explicit $top_explicit
Truth table100%3/3
A ||= B
A= $explicitB= $top_explicit
ABresult
1X1
011
000
452 2758 ($top_implicit, $top_explicit) = ('', '');
453 2758 ▶ if ($alias) {
Branch: 5 branches
BranchTrueFalseTotal
if ($alias) { } 0 2758 2758
elsif ($self->inline =~ /^\{/) { } 27 2731 2758
elsif ($self->inline =~ /^\[/) { } 33 2698 2731
elsif ($self->inline =~ /^"/) { } 27 2671 2698
elsif ($self->inline =~ /^'/) { } 56 2615 2671
454 $self->die('YAML_PARSE_ERR_NO_ANCHOR', $alias)
455 0 ▶ unless defined $self->anchor2node->{$alias};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->anchor2node->{$alias} 0 0 0
456 0 ▶ if (ref($self->anchor2node->{$alias}) ne 'YAML-anchor2node') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->anchor2node->{$alias} ne 'YAML-anchor2node') { } 0 0 0
457 0 $node = $self->anchor2node->{$alias};
458 }
459 else {
460 0 $node = do {my $sv = "*$alias"};
461 0 push @{$self->anchor2node->{$alias}}, [\$node, $self->line];
462 }
463 }
464 elsif ($self->inline =~ /^\{/) {
465 27 $node = $self->_parse_inline_mapping($anchor);
466 }
467 elsif ($self->inline =~ /^\[/) {
468 33 $node = $self->_parse_inline_seq($anchor);
469 }
470 elsif ($self->inline =~ /^"/) {
471 27 $node = $self->_parse_inline_double_quoted();
472 25 $node = $self->_unescape($node);
473 25 ▶ $node = $self->_parse_implicit($node) if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 2 23 25
474 }
475 elsif ($self->inline =~ /^'/) {
476 56 $node = $self->_parse_inline_single_quoted();
477 54 ▶ $node = $self->_parse_implicit($node) if $implicit;
Branch: 1 branch
BranchTrueFalseTotal
if $implicit 0 54 54
478 }
479 else {
480 2615 ▶ if ($top) {
Branch: 1 branch
BranchTrueFalseTotal
if ($top) { } 1174 1441 2615
481 1174 $node = $self->inline;
482 1174 $self->inline('');
483 }
484 else {
485 1441 $node = $self->_parse_inline_simple();
486 }
487 2614 ▶ $node = $self->_parse_implicit($node) unless $explicit;
Branch: 1 branch
BranchTrueFalseTotal
unless $explicit 2598 16 2614
488  
489 2613 ▶ 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 2610 2613
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
260733
$self->numify and defined $node and not ref $node and length $node
!ll&&!rl&&r
260706
$self->numify and defined $node and not ref $node
!ll&&!rl&&r
260706
$self->numify and defined $node
!ll&&!rl&&r
260706
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
490 and $node =~ m/\A-?(?:0|[1-9][0-9]*)?(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?\z/) {
491 3 $node += 0;
492 }
493 }
494 2749 ▶ if ($explicit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($explicit) 31 2718 2749
495 31 $node = $self->_parse_explicit($node, $explicit);
496 }
497 2749 ▶ if ($anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anchor) 0 2749 2749
498 0 ▶ if (ref($self->anchor2node->{$anchor}) eq 'YAML-anchor2node') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->anchor2node->{$anchor} eq "YAML-anchor2node") 0 0 0
499 0 for my $ref (@{$self->anchor2node->{$anchor}}) {
500 0 ${$ref->[0]} = $node;
501 0 $self->warn('YAML_LOAD_WARN_UNRESOLVED_ALIAS',
502 $anchor, $ref->[1]);
503 }
504 }
505 0 $self->anchor2node->{$anchor} = $node;
506 }
507 2749 return $node;
508 }
509  
510 # Parse the inline YAML mapping into a Perl hash
511 27 ▶sub _parse_inline_mapping {
Subroutine _parse_inline_mapping: called CC=7 SCAR=19.7
512 27 my $self = shift;
513 27 my ($anchor) = @_;
514 27 my $node = {};
515 27 $self->anchor2node->{$anchor} = $node;
516  
517 $self->die('YAML_PARSE_ERR_INLINE_MAP')
518 27 ▶ unless $self->{inline} =~ s/^\{\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inline"} =~ s/^\{\s*// 0 27 27
519 27 ▶ while (not $self->{inline} =~ s/^\s*\}(\s+#.*$|\s*)//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inline"} =~ s/^\s*\}(\s+#.*$|\s*)//) 30 26 56
520 30 my $key = $self->_parse_inline();
521 $self->die('YAML_PARSE_ERR_INLINE_MAP')
522 30 ▶ unless $self->{inline} =~ s/^\: \s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inline"} =~ s/^\: \s*// 1 29 30
523 29 my $value = $self->_parse_inline();
524 29 ▶ if (exists $node->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{$key}) { } 0 29 29
525 0 $self->warn('YAML_LOAD_WARN_DUPLICATE_KEY', $key);
526 }
527 else {
528 29 $node->{$key} = $value;
529 }
530 29 ▶ next if $self->inline =~ /^\s*\}/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->inline =~ /^\s*\}/ 17 12 29
531 $self->die('YAML_PARSE_ERR_INLINE_MAP')
532 12 ▶ unless $self->{inline} =~ s/^\,\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inline"} =~ s/^\,\s*// 0 12 12
533 }
534 26 return $node;
535 }
536  
537 # Parse the inline YAML sequence into a Perl array
538 33 ▶sub _parse_inline_seq {
Subroutine _parse_inline_seq: called CC=5 SCAR=16.1
539 33 my $self = shift;
540 33 my ($anchor) = @_;
541 33 my $node = [];
542 33 $self->anchor2node->{$anchor} = $node;
543  
544 $self->die('YAML_PARSE_ERR_INLINE_SEQUENCE')
545 33 ▶ unless $self->{inline} =~ s/^\[\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inline"} =~ s/^\[\s*// 0 33 33
546 33 ▶ while (not $self->{inline} =~ s/^\s*\](\s+#.*$|\s*)//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inline"} =~ s/^\s*\](\s+#.*$|\s*)//) 59 31 90
547 59 my $value = $self->_parse_inline();
548 58 push @$node, $value;
549 58 ▶ next if $self->inline =~ /^\s*\]/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->inline =~ /^\s*\]/ 22 36 58
550 $self->die('YAML_PARSE_ERR_INLINE_SEQUENCE')
551 36 ▶ unless $self->{inline} =~ s/^\,\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inline"} =~ s/^\,\s*// 1 35 36
552 }
553 31 return $node;
554 }
555  
556 # Parse the inline double quoted string.
557 27 ▶sub _parse_inline_double_quoted {
Subroutine _parse_inline_double_quoted: called CC=5 SCAR=16.1
558 27 my $self = shift;
559 27 my $inline = $self->inline;
560 27 ▶ if ($inline =~ s/^"//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline =~ s/^"//) 27 0 27
561 27 my $node = '';
562  
563 27 ▶ while ($inline =~ s/^(\\.|[^"\\]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline =~ s/^(\\.|[^"\\]+)//) 160061 25 160086
564 160061 my $capture = $1;
565 160061 $capture =~ s/^\\"/"/;
566 160061 $node .= $capture;
567 160061 ▶ last unless length $inline;
Branch: 1 branch
BranchTrueFalseTotal
unless length $inline 2 160059 160061
568 }
569 27 ▶ if ($inline =~ s/^"(?:\s+#.*|\s*)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline =~ s/^"(?:\s+#.*|\s*)//) 25 2 27
570 25 $self->inline($inline);
571 25 return $node;
572 }
573 }
574 2 $self->die('YAML_PARSE_ERR_BAD_DOUBLE');
575 }
576  
577  
578 # Parse the inline single quoted string.
579 56 ▶sub _parse_inline_single_quoted {
Subroutine _parse_inline_single_quoted: called CC=5 SCAR=16.1
580 56 my $self = shift;
581 56 my $inline = $self->inline;
582 56 ▶ if ($inline =~ s/^'//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline =~ s/^'//) 56 0 56
583 56 my $node = '';
584 56 ▶ while ($inline =~ s/^(''|[^']+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline =~ s/^(''|[^']+)//) 52 54 106
585 52 my $capture = $1;
586 52 $capture =~ s/^''/'/;
587 52 $node .= $capture;
588 52 ▶ last unless length $inline;
Branch: 1 branch
BranchTrueFalseTotal
unless length $inline 2 50 52
589 }
590 56 ▶ if ($inline =~ s/^'(?:\s+#.*|\s*)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline =~ s/^'(?:\s+#.*|\s*)//) 54 2 56
591 54 $self->inline($inline);
592 54 return $node;
593 }
594 }
595 2 $self->die('YAML_PARSE_ERR_BAD_SINGLE');
596 }
597  
598 # Parse the inline unquoted string and do implicit typing.
599 1441 ▶sub _parse_inline_simple {
Subroutine _parse_inline_simple: called CC=2 SCAR=6.9
600 1441 my $self = shift;
601 1441 my $value;
602 1441 ▶ if ($self->inline =~ /^(|[^!@#%^&*].*?)(?=[\[\]\{\},]|, |: |- |:\s*$|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inline =~ /^(|[^!\@#%^&*].*?)(?=[\[\]\{\},]|, |: |- |:\s*$|$)/) { } 1440 1 1441
603 1440 $value = $1;
604 1440 substr($self->{inline}, 0, length($1)) = '';
605 }
606 else {
607 1 $self->die('YAML_PARSE_ERR_BAD_INLINE_IMPLICIT', $value);
608 }
609 1440 return $value;
610 }
611  
612 2601 ▶sub _parse_implicit {
Subroutine _parse_implicit: called CC=5 SCAR=16.1
613 2601 my $self = shift;
614 2601 my ($value) = @_;
615 # remove trailing comments and whitespace
616 2601 $value =~ s/^#.*$//;
617 2601 $value =~ s/\s+#.*$//;
618 2601 $value =~ s/\s+$//;
619 2601 ▶ return $value if $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "" 5 2596 2601
620 2596 ▶ return undef if $value =~ /^~$/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^~$/ 4 2592 2596
621 2592 ▶ return $value
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^[\@\`]/ or $value =~ /^[\-\?]\s/ 2590 2 2592
Condition100%3/3
$value =~ /^[\@\`]/ or $value =~ /^[\-\?]\s/
l!l&&r!l&&!r
112590
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
622 unless $value =~ /^[\@\`]/ or
623 $value =~ /^[\-\?]\s/;
624 2 $self->die('YAML_PARSE_ERR_BAD_IMPLICIT', $value);
625 }
626  
627 # Unfold a YAML multiline scalar into a single string.
628 20 ▶sub _parse_unfold {
Subroutine _parse_unfold: called CC=5 SCAR=16.1
629 20 my $self = shift;
630 20 my ($chomp) = @_;
631 20 my $node = '';
632 20 my $space = 0;
633 20 ▶ 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]) 57 20 77
Condition100%3/3
not $self->done and $self->indent == $self->offset->[$self->level]
!ll&&!rl&&r
14657
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
634 57 $node .= $self->content. "\n";
635 57 $self->_parse_next_line(LEAF);
636 }
637 20 $node =~ s/^(\S.*)\n(?=\S)/$1 /gm;
638 20 $node =~ s/^(\S.*)\n(\n+\S)/$1$2/gm;
639 20 ▶ $node =~ s/\n*\Z// unless $chomp eq '+';
Branch: 1 branch
BranchTrueFalseTotal
unless $chomp eq "+" 17 3 20
640 20 ▶ $node .= "\n" unless $chomp;
Branch: 1 branch
BranchTrueFalseTotal
unless $chomp 15 5 20
641 20 return $node;
642 }
643  
644 # Parse a YAML block style scalar. This is like a Perl here-document.
645 44 ▶sub _parse_block {
Subroutine _parse_block: called CC=5 SCAR=16.1
646 44 my $self = shift;
647 44 my ($chomp) = @_;
648 44 my $node = '';
649 44 ▶ 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]) 141 44 185
Condition100%3/3
not $self->done and $self->indent == $self->offset->[$self->level]
!ll&&!rl&&r
2222141
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
650 141 $node .= $self->content . "\n";
651 141 $self->_parse_next_line(LEAF);
652 }
653 44 ▶ return $node if '+' eq $chomp;
Branch: 1 branch
BranchTrueFalseTotal
if "+" eq $chomp 3 41 44
654 41 $node =~ s/\n*\Z/\n/;
655 41 ▶ $node =~ s/\n\Z// if $chomp eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $chomp eq "-" 17 24 41
656 41 return $node;
657 }
658  
659 # Handle Perl style '#' comments. Comments must be at the same indentation
660 # level as the collection line following them.
661 2697 ▶sub _parse_throwaway_comments {
Subroutine _parse_throwaway_comments: called CC=3 SCAR=11.0
662 2697 my $self = shift;
663 2697 ▶ while (@{$self->lines} and
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->lines;} and $self->lines->[0] =~ /^\s*(\#|$)/) 529 2697 3226
Condition100%3/3
@{$self->lines;} and $self->lines->[0] =~ /^\s*(\#|$)/
!ll&&!rl&&r
442653529
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
664 $self->lines->[0] =~ m{^\s*(\#|$)}
665 ) {
666 529 shift @{$self->lines};
667 529 $self->{line}++;
668 }
669 2697 $self->eos($self->{done} = not @{$self->lines});
670 }
671  
672 # This is the routine that controls what line is being parsed. It gets called
673 # once for each line in the YAML stream.
674 #
675 # This routine must:
676 # 1) Skip past the current line
677 # 2) Determine the indentation offset for a new level
678 # 3) Find the next _content_ line
679 # A) Skip over any throwaways (Comments/blanks)
680 # B) Set $self->indent, $self->content, $self->line
681 # 4) Expand tabs appropriately
682 2228 ▶sub _parse_next_line {
Subroutine _parse_next_line: called CC=39 SCAR=36.9
683 2228 my $self = shift;
684 2228 my ($type) = @_;
685 2228 my $level = $self->level;
686 2228 my $offset = $self->offset->[$level];
687 2228 ▶ $self->die('YAML_EMIT_ERR_BAD_LEVEL') unless defined $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 2228 2228
688 2228 shift @{$self->lines};
689 2228 $self->eos($self->{done} = not @{$self->lines});
690 2228 ▶ if ($self->eos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eos) 258 1970 2228
691 258 $self->offset->[$level + 1] = $offset + 1;
692 258 return;
693 }
694 1970 $self->{line}++;
695  
696 # Determine the offset for a new leaf node
697 # TODO
698 1970 ▶ if ($self->preface =~
Branch: 2 branches
BranchTrueFalseTotal
if ($self->preface =~ qr/(?:^|\s)(?:$FOLD_CHAR|$LIT_CHAR_RX)(?:[+-]([0-9]*)|([0-9]*)[+-]?)(?:\s+#.*|\s*)$/) { } 62 1908 1970
elsif ($type == 2 and $self->preface =~ /^(\s*(\!\S*|\&\S+))*\s*$/) { } 644 1436 2080
699 qr/(?:^|\s)(?:$FOLD_CHAR|$LIT_CHAR_RX)(?:[+-]([0-9]*)|([0-9]*)[+-]?)(?:\s+#.*|\s*)$/
700 ) {
701 62 ▶ my $explicit_indent = defined $1 ? $1 : defined $2 ? $2 : '';
Branch: 2 branches
BranchTrueFalseTotal
defined $1 ? : 20 42 62
defined $2 ? : 42 0 42
702 62 ▶ $self->die('YAML_PARSE_ERR_ZERO_INDENT')
Branch: 1 branch
BranchTrueFalseTotal
if length $explicit_indent and $explicit_indent == 0 1 61 62
Condition100%3/3
length $explicit_indent and $explicit_indent == 0
!ll&&!rl&&r
5381
MC/DC100%2/2
length $explicit_indent and $explicit_indent == 0
length $explicit_indent $explicit_indent == 0
Truth table100%3/3
A and B
A= length $explicit_indentB= $explicit_indent == 0
ABresult
0X0
100
111
703 if length($explicit_indent) and $explicit_indent == 0;
704 61 $type = LEAF;
705 61 ▶ if (length($explicit_indent)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $explicit_indent) { } 8 53 61
706 8 $self->offset->[$level + 1] = $offset + $explicit_indent;
707 }
708 else {
709 # First get rid of any comments.
710 53 ▶ while (@{$self->lines} && ($self->lines->[0] =~ /^\s*#/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->lines;} and $self->lines->[0] =~ /^\s*#/) 1 52 53
Condition66%2/3
@{$self->lines;} and $self->lines->[0] =~ /^\s*#/
!ll&&!rl&&r
0521
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
711 1 $self->lines->[0] =~ /^( *)/;
712 1 ▶ last unless length($1) <= $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless length $1 <= $offset 1 0 1
713 0 shift @{$self->lines};
714 0 $self->{line}++;
715 }
716 53 $self->eos($self->{done} = not @{$self->lines});
717 53 ▶ return if $self->eos;
Branch: 1 branch
BranchTrueFalseTotal
if $self->eos 0 53 53
718 53 ▶ if ($self->lines->[0] =~ /^( *)\S/ and length($1) > $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lines->[0] =~ /^( *)\S/ and length $1 > $offset) { } 52 1 53
Condition66%2/3
$self->lines->[0] =~ /^( *)\S/ and length $1 > $offset
!ll&&!rl&&r
0152
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
719 52 $self->offset->[$level+1] = length($1);
720 }
721 else {
722 1 $self->offset->[$level+1] = $offset + 1;
723 }
724 }
725 61 $offset = $self->offset->[++$level];
726 }
727 # Determine the offset for a new collection level
728 ▶ elsif ($type == COLLECTION and
Condition100%3/3
$type == 2 and $self->preface =~ /^(\s*(\!\S*|\&\S+))*\s*$/
!ll&&!rl&&r
1721092644
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
729 $self->preface =~ /^(\s*(\!\S*|\&\S+))*\s*$/) {
730 644 $self->_parse_throwaway_comments();
731 644 my $zero_indent = $self->zero_indent;
732 644 ▶ if ($self->eos) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->eos) { } 0 644 644
elsif (defined $zero_indent->[$level] and not $zero_indent->[$level] and $self->lines->[0] =~ /^( {$offset,})-(?: |$)/) { } 49 595 644
733 0 $self->offset->[$level+1] = $offset + 1;
734 0 return;
735 }
736 ▶ elsif (
Condition100%6/6
defined $zero_indent->[$level] and not $zero_indent->[$level] and $self->lines->[0] =~ /^( {$offset,})-(?: |$)/
!ll&&!rl&&r
26832749
defined $zero_indent->[$level] and not $zero_indent->[$level]
!ll&&!rl&&r
2662376
MC/DC100%3/3
defined $zero_indent->[$level] and not $zero_indent->[$level] and $self->lines->[0] =~ /^( {$offset,})-(?: |$)/
defined $zero_indent->[$level] not $zero_indent->[$level] $self->lines->[0] =~ /^( {$offset,})-(?: |$)/
Truth table100%4/4
A and not(B) and C
A= defined $zero_indent->[$level]B= not $zero_indent->[$level]C= $self->lines->[0] =~ /^( {$offset,})-(?: |$)/
ABCresult
0XX0
10X0
1100
1111
737 defined $zero_indent->[ $level ]
738 and not $zero_indent->[ $level ]
739 and $self->lines->[0] =~ /^( {$offset,})-(?: |$)/
740 ) {
741 49 my $new_offset = length($1);
742 49 $self->offset->[$level+1] = $new_offset;
743 49 ▶ if ($new_offset == $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_offset == $offset) 3 46 49
744 3 $zero_indent->[ $level+1 ] = 1;
745 }
746 }
747 else {
748 595 ▶ $self->lines->[0] =~ /^( *)\S/ or
Branch: 1 branch
BranchTrueFalseTotal
$self->lines->[0] =~ /^( *)\S/ or $self->die("YAML_PARSE_ERR_NONSPACE_INDENTATION") 594 1 595
749 $self->die('YAML_PARSE_ERR_NONSPACE_INDENTATION');
750 594 ▶ if (length($1) > $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $1 > $offset) { } 585 9 594
751 585 $self->offset->[$level+1] = length($1);
752 }
753 else {
754 9 $self->offset->[$level+1] = $offset + 1;
755 }
756 }
757 643 $offset = $self->offset->[++$level];
758 }
759  
760 1968 ▶ if ($type == LEAF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 1) { } 233 1735 1968
761 233 ▶ if (@{$self->lines} and
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/ and length $1 < $offset) 5 228 233
Condition83%5/6
@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/ and length $1 < $offset
!ll&&!rl&&r
22175
@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/
!ll&&!rl&&r
022112
MC/DC66%2/3
@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/ and length $1 < $offset
@{$self->lines;} $self->lines->[0] =~ /^( *)(\#)/ length $1 < $offset
Truth table75%3/4
A and B and C
A= @{$self->lines;}B= $self->lines->[0] =~ /^( *)(\#)/C= length $1 < $offset
ABCresult
0XX0
10X0
1100
1111
762 $self->lines->[0] =~ m{^( *)(\#)} and
763 length($1) < $offset
764 ) {
765 5 ▶ if ( length($1) < $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $1 < $offset) 5 0 5
766 5 shift @{$self->lines};
767 5 $self->{line}++;
768 # every comment after that is also thrown away regardless
769 # of identation
770 5 ▶ while (@{$self->lines} and
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/) 7 5 12
Condition100%3/3
@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/
!ll&&!rl&&r
147
MC/DC100%2/2
@{$self->lines;} and $self->lines->[0] =~ /^( *)(\#)/
@{$self->lines;} $self->lines->[0] =~ /^( *)(\#)/
Truth table100%3/3
A and B
A= @{$self->lines;}B= $self->lines->[0] =~ /^( *)(\#)/
ABresult
0X0
100
111
771 $self->lines->[0] =~ m{^( *)(\#)}
772 ) {
773 7 shift @{$self->lines};
774 7 $self->{line}++;
775 }
776 }
777 }
778 233 $self->eos($self->{done} = not @{$self->lines});
779 }
780 else {
781 1735 $self->_parse_throwaway_comments();
782 }
783 1968 ▶ return if $self->eos;
Branch: 1 branch
BranchTrueFalseTotal
if $self->eos 7 1961 1968
784  
785 1961 ▶ if ($self->lines->[0] =~ /^---(\s|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lines->[0] =~ /^---(\s|$)/) 38 1923 1961
786 38 $self->done(1);
787 38 return;
788 }
789 1923 ▶ if ($type == LEAF and
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 1 and $self->lines->[0] =~ /^ {$offset}(.*)$/) { } 183 1740 1923
elsif ($self->lines->[0] =~ /^\s*$/) { } 15 1725 1740
Condition100%3/3
$type == 1 and $self->lines->[0] =~ /^ {$offset}(.*)$/
!ll&&!rl&&r
169743183
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
790 $self->lines->[0] =~ /^ {$offset}(.*)$/
791 ) {
792 183 $self->indent($offset);
793 183 $self->content($1);
794 }
795 elsif ($self->lines->[0] =~ /^\s*$/) {
796 15 $self->indent($offset);
797 15 $self->content('');
798 }
799 else {
800 1725 $self->lines->[0] =~ /^( *)(\S.*)$/;
801 1725 ▶ while ($self->offset->[$level] > length($1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->offset->[$level] > length $1) 397 1725 2122
802 397 $level--;
803 }
804 1725 ▶ $self->die('YAML_PARSE_ERR_INCONSISTENT_INDENTATION')
Branch: 1 branch
BranchTrueFalseTotal
if $self->offset->[$level] != length $1 5 1720 1725
805 if $self->offset->[$level] != length($1);
806 1720 $self->indent(length($1));
807 1720 $self->content($2);
808 }
809 1918 ▶ $self->die('YAML_PARSE_ERR_INDENTATION')
Branch: 1 branch
BranchTrueFalseTotal
if $self->indent - $offset > 1 0 1918 1918
810 if $self->indent - $offset > 1;
811 }
812  
813 #==============================================================================
814 # Utility subroutines.
815 #==============================================================================
816  
817 # Printable characters for escapes
818 36 my %unescapes = (
819 0 => "\x00",
820 a => "\x07",
821 t => "\x09",
822 n => "\x0a",
823 'v' => "\x0b", # Potential v-string error on 5.6.2 if not quoted
824 f => "\x0c",
825 r => "\x0d",
826 e => "\x1b",
827 '\\' => '\\',
828 );
829  
830 # Transform all the backslash style escape characters to their literal meaning
831 25 ▶sub _unescape {
Subroutine _unescape: called CC=2 SCAR=7.0
832 25 my $self = shift;
833 25 my ($node) = @_;
834 25 $node =~ s/\\([never\\fart0]|x([0-9a-fA-F]{2}))/
835 22 ▶ (length($1)>1)?pack("H2",$2):$unescapes{$1}/gex;
Branch: 1 branch
BranchTrueFalseTotal
length $1 > 1 ? : 0 22 22
836 25 return $node;
837 }
838  
839 36 1;
↑ Summary YAML/Dumper.pm »