line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Load YAML into data with Parser and Constructor |
2
|
35
|
|
|
35
|
|
165297
|
use strict; |
|
35
|
|
|
|
|
98
|
|
|
35
|
|
|
|
|
1038
|
|
3
|
35
|
|
|
35
|
|
210
|
use warnings; |
|
35
|
|
|
|
|
84
|
|
|
35
|
|
|
|
|
1695
|
|
4
|
|
|
|
|
|
|
package YAML::PP::Loader; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.036'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
35
|
|
|
35
|
|
18169
|
use YAML::PP::Parser; |
|
35
|
|
|
|
|
112
|
|
|
35
|
|
|
|
|
1247
|
|
9
|
35
|
|
|
35
|
|
16854
|
use YAML::PP::Constructor; |
|
35
|
|
|
|
|
109
|
|
|
35
|
|
|
|
|
1056
|
|
10
|
35
|
|
|
35
|
|
247
|
use YAML::PP::Reader; |
|
35
|
|
|
|
|
85
|
|
|
35
|
|
|
|
|
20451
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
186
|
|
|
186
|
0
|
1126
|
my ($class, %args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
186
|
|
100
|
|
|
642
|
my $cyclic_refs = delete $args{cyclic_refs} || 'allow'; |
16
|
186
|
|
100
|
|
|
513
|
my $default_yaml_version = delete $args{default_yaml_version} || '1.2'; |
17
|
186
|
|
|
|
|
337
|
my $preserve = delete $args{preserve}; |
18
|
186
|
|
|
|
|
307
|
my $duplicate_keys = delete $args{duplicate_keys}; |
19
|
186
|
|
|
|
|
299
|
my $schemas = delete $args{schemas}; |
20
|
186
|
|
100
|
|
|
444
|
$schemas ||= { |
21
|
|
|
|
|
|
|
'1.2' => YAML::PP->default_schema( |
22
|
|
|
|
|
|
|
boolean => 'perl', |
23
|
|
|
|
|
|
|
) |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
186
|
|
66
|
|
|
1105
|
my $constructor = delete $args{constructor} || YAML::PP::Constructor->new( |
27
|
|
|
|
|
|
|
schemas => $schemas, |
28
|
|
|
|
|
|
|
cyclic_refs => $cyclic_refs, |
29
|
|
|
|
|
|
|
default_yaml_version => $default_yaml_version, |
30
|
|
|
|
|
|
|
preserve => $preserve, |
31
|
|
|
|
|
|
|
duplicate_keys => $duplicate_keys, |
32
|
|
|
|
|
|
|
); |
33
|
185
|
|
|
|
|
378
|
my $parser = delete $args{parser}; |
34
|
185
|
50
|
|
|
|
479
|
unless ($parser) { |
35
|
185
|
|
|
|
|
753
|
$parser = YAML::PP::Parser->new( |
36
|
|
|
|
|
|
|
default_yaml_version => $default_yaml_version, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
185
|
50
|
|
|
|
515
|
unless ($parser->receiver) { |
40
|
185
|
|
|
|
|
522
|
$parser->set_receiver($constructor); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
185
|
100
|
|
|
|
514
|
if (keys %args) { |
44
|
1
|
|
|
|
|
59
|
die "Unexpected arguments: " . join ', ', sort keys %args; |
45
|
|
|
|
|
|
|
} |
46
|
184
|
|
|
|
|
589
|
my $self = bless { |
47
|
|
|
|
|
|
|
parser => $parser, |
48
|
|
|
|
|
|
|
constructor => $constructor, |
49
|
|
|
|
|
|
|
}, $class; |
50
|
184
|
|
|
|
|
543
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub clone { |
54
|
9
|
|
|
9
|
0
|
21
|
my ($self) = @_; |
55
|
9
|
|
|
|
|
19
|
my $clone = { |
56
|
|
|
|
|
|
|
parser => $self->parser->clone, |
57
|
|
|
|
|
|
|
constructor => $self->constructor->clone, |
58
|
|
|
|
|
|
|
}; |
59
|
9
|
|
|
|
|
23
|
bless $clone, ref $self; |
60
|
9
|
|
|
|
|
21
|
$clone->parser->set_receiver($clone->constructor); |
61
|
9
|
|
|
|
|
23
|
return $clone; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
2689
|
|
|
2689
|
0
|
6719
|
sub parser { return $_[0]->{parser} } |
65
|
1356
|
|
|
1356
|
0
|
2242
|
sub constructor { return $_[0]->{constructor} } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub filename { |
68
|
3
|
|
|
3
|
0
|
10
|
my ($self) = @_; |
69
|
3
|
|
|
|
|
6
|
my $reader = $self->parser->reader; |
70
|
3
|
50
|
|
|
|
19
|
if ($reader->isa('YAML::PP::Reader::File')) { |
71
|
3
|
|
|
|
|
10
|
return $reader->input; |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
0
|
die "Reader is not a YAML::PP::Reader::File"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub load_string { |
77
|
1315
|
|
|
1315
|
0
|
4897
|
my ($self, $yaml) = @_; |
78
|
1315
|
|
|
|
|
3002
|
$self->parser->set_reader(YAML::PP::Reader->new( input => $yaml )); |
79
|
1315
|
|
|
|
|
3237
|
$self->load(); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub load_file { |
83
|
19
|
|
|
19
|
0
|
44
|
my ($self, $file) = @_; |
84
|
19
|
|
|
|
|
49
|
$self->parser->set_reader(YAML::PP::Reader::File->new( input => $file )); |
85
|
19
|
|
|
|
|
79
|
$self->load(); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub load { |
89
|
1334
|
|
|
1334
|
0
|
2269
|
my ($self) = @_; |
90
|
1334
|
|
|
|
|
2158
|
my $parser = $self->parser; |
91
|
1334
|
|
|
|
|
2337
|
my $constructor = $self->constructor; |
92
|
|
|
|
|
|
|
|
93
|
1334
|
|
|
|
|
4685
|
$constructor->init; |
94
|
1334
|
|
|
|
|
3699
|
$parser->parse(); |
95
|
|
|
|
|
|
|
|
96
|
1307
|
|
|
|
|
2907
|
my $docs = $constructor->docs; |
97
|
1307
|
100
|
|
|
|
5671
|
return wantarray ? @$docs : $docs->[0]; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |