line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Load YAML into data with Parser and Constructor |
2
|
35
|
|
|
35
|
|
156486
|
use strict; |
|
35
|
|
|
|
|
88
|
|
|
35
|
|
|
|
|
1061
|
|
3
|
35
|
|
|
35
|
|
188
|
use warnings; |
|
35
|
|
|
|
|
62
|
|
|
35
|
|
|
|
|
1636
|
|
4
|
|
|
|
|
|
|
package YAML::PP::Loader; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.036_002'; # TRIAL VERSION |
7
|
|
|
|
|
|
|
|
8
|
35
|
|
|
35
|
|
18001
|
use YAML::PP::Parser; |
|
35
|
|
|
|
|
97
|
|
|
35
|
|
|
|
|
1319
|
|
9
|
35
|
|
|
35
|
|
16972
|
use YAML::PP::Constructor; |
|
35
|
|
|
|
|
104
|
|
|
35
|
|
|
|
|
1035
|
|
10
|
35
|
|
|
35
|
|
255
|
use YAML::PP::Reader; |
|
35
|
|
|
|
|
98
|
|
|
35
|
|
|
|
|
19825
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
748
|
|
|
748
|
0
|
3579
|
my ($class, %args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
748
|
|
100
|
|
|
2404
|
my $cyclic_refs = delete $args{cyclic_refs} || 'fatal'; |
16
|
748
|
|
100
|
|
|
2252
|
my $default_yaml_version = delete $args{default_yaml_version} || '1.2'; |
17
|
748
|
|
|
|
|
1311
|
my $preserve = delete $args{preserve}; |
18
|
748
|
|
|
|
|
1208
|
my $duplicate_keys = delete $args{duplicate_keys}; |
19
|
748
|
|
|
|
|
1277
|
my $schemas = delete $args{schemas}; |
20
|
748
|
|
100
|
|
|
1706
|
$schemas ||= { |
21
|
|
|
|
|
|
|
'1.2' => YAML::PP->default_schema( |
22
|
|
|
|
|
|
|
boolean => 'perl', |
23
|
|
|
|
|
|
|
) |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
748
|
|
66
|
|
|
3585
|
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
|
747
|
|
|
|
|
1402
|
my $parser = delete $args{parser}; |
34
|
747
|
50
|
|
|
|
1636
|
unless ($parser) { |
35
|
747
|
|
|
|
|
2562
|
$parser = YAML::PP::Parser->new( |
36
|
|
|
|
|
|
|
default_yaml_version => $default_yaml_version, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
747
|
50
|
|
|
|
1864
|
unless ($parser->receiver) { |
40
|
747
|
|
|
|
|
1755
|
$parser->set_receiver($constructor); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
747
|
100
|
|
|
|
1884
|
if (keys %args) { |
44
|
1
|
|
|
|
|
65
|
die "Unexpected arguments: " . join ', ', sort keys %args; |
45
|
|
|
|
|
|
|
} |
46
|
746
|
|
|
|
|
2083
|
my $self = bless { |
47
|
|
|
|
|
|
|
parser => $parser, |
48
|
|
|
|
|
|
|
constructor => $constructor, |
49
|
|
|
|
|
|
|
}, $class; |
50
|
746
|
|
|
|
|
2050
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub clone { |
54
|
9
|
|
|
9
|
0
|
20
|
my ($self) = @_; |
55
|
9
|
|
|
|
|
21
|
my $clone = { |
56
|
|
|
|
|
|
|
parser => $self->parser->clone, |
57
|
|
|
|
|
|
|
constructor => $self->constructor->clone, |
58
|
|
|
|
|
|
|
}; |
59
|
9
|
|
|
|
|
22
|
bless $clone, ref $self; |
60
|
9
|
|
|
|
|
19
|
$clone->parser->set_receiver($clone->constructor); |
61
|
9
|
|
|
|
|
27
|
return $clone; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
4397
|
|
|
4397
|
0
|
10834
|
sub parser { return $_[0]->{parser} } |
65
|
2210
|
|
|
2210
|
0
|
3509
|
sub constructor { return $_[0]->{constructor} } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub filename { |
68
|
3
|
|
|
3
|
0
|
6
|
my ($self) = @_; |
69
|
3
|
|
|
|
|
7
|
my $reader = $self->parser->reader; |
70
|
3
|
50
|
|
|
|
19
|
if ($reader->isa('YAML::PP::Reader::File')) { |
71
|
3
|
|
|
|
|
11
|
return $reader->input; |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
0
|
die "Reader is not a YAML::PP::Reader::File"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub load_string { |
77
|
2169
|
|
|
2169
|
0
|
7095
|
my ($self, $yaml) = @_; |
78
|
2169
|
|
|
|
|
4816
|
$self->parser->set_reader(YAML::PP::Reader->new( input => $yaml )); |
79
|
2169
|
|
|
|
|
4970
|
$self->load(); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub load_file { |
83
|
19
|
|
|
19
|
0
|
58
|
my ($self, $file) = @_; |
84
|
19
|
|
|
|
|
57
|
$self->parser->set_reader(YAML::PP::Reader::File->new( input => $file )); |
85
|
19
|
|
|
|
|
71
|
$self->load(); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub load { |
89
|
2188
|
|
|
2188
|
0
|
3723
|
my ($self) = @_; |
90
|
2188
|
|
|
|
|
3816
|
my $parser = $self->parser; |
91
|
2188
|
|
|
|
|
3858
|
my $constructor = $self->constructor; |
92
|
|
|
|
|
|
|
|
93
|
2188
|
|
|
|
|
6911
|
$constructor->init; |
94
|
2188
|
|
|
|
|
5968
|
$parser->parse(); |
95
|
|
|
|
|
|
|
|
96
|
2160
|
|
|
|
|
4647
|
my $docs = $constructor->docs; |
97
|
2160
|
100
|
|
|
|
10394
|
return wantarray ? @$docs : $docs->[0]; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |