| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: Load YAML into data with Parser and Constructor |
|
2
|
43
|
|
|
43
|
|
351526
|
use strict; |
|
|
43
|
|
|
|
|
68
|
|
|
|
43
|
|
|
|
|
1358
|
|
|
3
|
43
|
|
|
43
|
|
145
|
use warnings; |
|
|
43
|
|
|
|
|
224
|
|
|
|
43
|
|
|
|
|
2879
|
|
|
4
|
|
|
|
|
|
|
package YAML::PP::Loader; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 'v0.40.0'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
43
|
|
|
43
|
|
19741
|
use YAML::PP::Parser; |
|
|
43
|
|
|
|
|
119
|
|
|
|
43
|
|
|
|
|
1522
|
|
|
9
|
43
|
|
|
43
|
|
18604
|
use YAML::PP::Constructor; |
|
|
43
|
|
|
|
|
115
|
|
|
|
43
|
|
|
|
|
1238
|
|
|
10
|
43
|
|
|
43
|
|
234
|
use YAML::PP::Reader; |
|
|
43
|
|
|
|
|
54
|
|
|
|
43
|
|
|
|
|
19565
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
757
|
|
|
757
|
0
|
343544
|
my ($class, %args) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
757
|
|
100
|
|
|
1927
|
my $cyclic_refs = delete $args{cyclic_refs} || 'fatal'; |
|
16
|
757
|
|
100
|
|
|
1667
|
my $default_yaml_version = delete $args{default_yaml_version} || '1.2'; |
|
17
|
757
|
|
|
|
|
1161
|
my $preserve = delete $args{preserve}; |
|
18
|
757
|
|
|
|
|
1032
|
my $duplicate_keys = delete $args{duplicate_keys}; |
|
19
|
757
|
|
|
|
|
910
|
my $require_footer = delete $args{require_footer}; |
|
20
|
757
|
|
|
|
|
975
|
my $max_depth = delete $args{max_depth}; |
|
21
|
757
|
|
|
|
|
907
|
my $schemas = delete $args{schemas}; |
|
22
|
757
|
|
100
|
|
|
1390
|
$schemas ||= { |
|
23
|
|
|
|
|
|
|
'1.2' => YAML::PP->default_schema( |
|
24
|
|
|
|
|
|
|
boolean => 'perl', |
|
25
|
|
|
|
|
|
|
) |
|
26
|
|
|
|
|
|
|
}; |
|
27
|
|
|
|
|
|
|
|
|
28
|
757
|
|
66
|
|
|
3707
|
my $constructor = delete $args{constructor} || YAML::PP::Constructor->new( |
|
29
|
|
|
|
|
|
|
schemas => $schemas, |
|
30
|
|
|
|
|
|
|
cyclic_refs => $cyclic_refs, |
|
31
|
|
|
|
|
|
|
default_yaml_version => $default_yaml_version, |
|
32
|
|
|
|
|
|
|
preserve => $preserve, |
|
33
|
|
|
|
|
|
|
duplicate_keys => $duplicate_keys, |
|
34
|
|
|
|
|
|
|
require_footer => $require_footer, |
|
35
|
|
|
|
|
|
|
max_depth => $max_depth, |
|
36
|
|
|
|
|
|
|
); |
|
37
|
756
|
|
|
|
|
1198
|
my $parser = delete $args{parser}; |
|
38
|
756
|
50
|
|
|
|
1404
|
unless ($parser) { |
|
39
|
756
|
|
|
|
|
2697
|
$parser = YAML::PP::Parser->new( |
|
40
|
|
|
|
|
|
|
default_yaml_version => $default_yaml_version, |
|
41
|
|
|
|
|
|
|
); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
756
|
50
|
|
|
|
1677
|
unless ($parser->receiver) { |
|
44
|
756
|
|
|
|
|
2728
|
$parser->set_receiver($constructor); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
756
|
100
|
|
|
|
1440
|
if (keys %args) { |
|
48
|
1
|
|
|
|
|
44
|
die "Unexpected arguments: " . join ', ', sort keys %args; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
755
|
|
|
|
|
1664
|
my $self = bless { |
|
51
|
|
|
|
|
|
|
parser => $parser, |
|
52
|
|
|
|
|
|
|
constructor => $constructor, |
|
53
|
|
|
|
|
|
|
}, $class; |
|
54
|
755
|
|
|
|
|
1916
|
return $self; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub clone { |
|
58
|
9
|
|
|
9
|
0
|
14
|
my ($self) = @_; |
|
59
|
9
|
|
|
|
|
17
|
my $clone = { |
|
60
|
|
|
|
|
|
|
parser => $self->parser->clone, |
|
61
|
|
|
|
|
|
|
constructor => $self->constructor->clone, |
|
62
|
|
|
|
|
|
|
}; |
|
63
|
9
|
|
|
|
|
21
|
bless $clone, ref $self; |
|
64
|
9
|
|
|
|
|
24
|
$clone->parser->set_receiver($clone->constructor); |
|
65
|
9
|
|
|
|
|
17
|
return $clone; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
4425
|
|
|
4425
|
0
|
10802
|
sub parser { return $_[0]->{parser} } |
|
69
|
2224
|
|
|
2224
|
0
|
2929
|
sub constructor { return $_[0]->{constructor} } |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub filename { |
|
72
|
3
|
|
|
3
|
0
|
5
|
my ($self) = @_; |
|
73
|
3
|
|
|
|
|
7
|
my $reader = $self->parser->reader; |
|
74
|
3
|
50
|
|
|
|
15
|
if ($reader->isa('YAML::PP::Reader::File')) { |
|
75
|
3
|
|
|
|
|
10
|
return $reader->input; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
0
|
|
|
|
|
0
|
die "Reader is not a YAML::PP::Reader::File"; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub load_string { |
|
81
|
2183
|
|
|
2183
|
0
|
6061
|
my ($self, $yaml) = @_; |
|
82
|
2183
|
|
|
|
|
4657
|
$self->parser->set_reader(YAML::PP::Reader->new( input => $yaml )); |
|
83
|
2183
|
|
|
|
|
4799
|
$self->load(); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub load_file { |
|
87
|
19
|
|
|
19
|
0
|
30
|
my ($self, $file) = @_; |
|
88
|
19
|
|
|
|
|
33
|
$self->parser->set_reader(YAML::PP::Reader::File->new( input => $file )); |
|
89
|
19
|
|
|
|
|
72
|
$self->load(); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub load { |
|
93
|
2202
|
|
|
2202
|
0
|
3278
|
my ($self) = @_; |
|
94
|
2202
|
|
|
|
|
3129
|
my $parser = $self->parser; |
|
95
|
2202
|
|
|
|
|
3665
|
my $constructor = $self->constructor; |
|
96
|
|
|
|
|
|
|
|
|
97
|
2202
|
|
|
|
|
6352
|
$constructor->init; |
|
98
|
2202
|
|
|
|
|
6245
|
$parser->parse(); |
|
99
|
|
|
|
|
|
|
|
|
100
|
2167
|
|
|
|
|
3599
|
my $docs = $constructor->docs; |
|
101
|
2167
|
100
|
|
|
|
10777
|
return wantarray ? @$docs : $docs->[0]; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |