Old/Loader.pm

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