line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Load YAML into data with Parser and Constructor |
2
|
35
|
|
|
35
|
|
158827
|
use strict; |
|
35
|
|
|
|
|
92
|
|
|
35
|
|
|
|
|
1013
|
|
3
|
35
|
|
|
35
|
|
171
|
use warnings; |
|
35
|
|
|
|
|
91
|
|
|
35
|
|
|
|
|
1712
|
|
4
|
|
|
|
|
|
|
package YAML::PP::Loader; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.036_001'; # TRIAL VERSION |
7
|
|
|
|
|
|
|
|
8
|
35
|
|
|
35
|
|
17846
|
use YAML::PP::Parser; |
|
35
|
|
|
|
|
114
|
|
|
35
|
|
|
|
|
1288
|
|
9
|
35
|
|
|
35
|
|
16577
|
use YAML::PP::Constructor; |
|
35
|
|
|
|
|
94
|
|
|
35
|
|
|
|
|
1016
|
|
10
|
35
|
|
|
35
|
|
231
|
use YAML::PP::Reader; |
|
35
|
|
|
|
|
89
|
|
|
35
|
|
|
|
|
19356
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
748
|
|
|
748
|
0
|
3702
|
my ($class, %args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
748
|
|
100
|
|
|
2398
|
my $cyclic_refs = delete $args{cyclic_refs} || 'fatal'; |
16
|
748
|
|
100
|
|
|
1987
|
my $default_yaml_version = delete $args{default_yaml_version} || '1.2'; |
17
|
748
|
|
|
|
|
1347
|
my $preserve = delete $args{preserve}; |
18
|
748
|
|
|
|
|
1329
|
my $duplicate_keys = delete $args{duplicate_keys}; |
19
|
748
|
|
|
|
|
1186
|
my $schemas = delete $args{schemas}; |
20
|
748
|
|
100
|
|
|
1638
|
$schemas ||= { |
21
|
|
|
|
|
|
|
'1.2' => YAML::PP->default_schema( |
22
|
|
|
|
|
|
|
boolean => 'perl', |
23
|
|
|
|
|
|
|
) |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
748
|
|
66
|
|
|
3582
|
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
|
|
|
|
|
1401
|
my $parser = delete $args{parser}; |
34
|
747
|
50
|
|
|
|
1865
|
unless ($parser) { |
35
|
747
|
|
|
|
|
2622
|
$parser = YAML::PP::Parser->new( |
36
|
|
|
|
|
|
|
default_yaml_version => $default_yaml_version, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
747
|
50
|
|
|
|
1928
|
unless ($parser->receiver) { |
40
|
747
|
|
|
|
|
1863
|
$parser->set_receiver($constructor); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
747
|
100
|
|
|
|
1784
|
if (keys %args) { |
44
|
1
|
|
|
|
|
93
|
die "Unexpected arguments: " . join ', ', sort keys %args; |
45
|
|
|
|
|
|
|
} |
46
|
746
|
|
|
|
|
2165
|
my $self = bless { |
47
|
|
|
|
|
|
|
parser => $parser, |
48
|
|
|
|
|
|
|
constructor => $constructor, |
49
|
|
|
|
|
|
|
}, $class; |
50
|
746
|
|
|
|
|
2116
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub clone { |
54
|
9
|
|
|
9
|
0
|
17
|
my ($self) = @_; |
55
|
9
|
|
|
|
|
19
|
my $clone = { |
56
|
|
|
|
|
|
|
parser => $self->parser->clone, |
57
|
|
|
|
|
|
|
constructor => $self->constructor->clone, |
58
|
|
|
|
|
|
|
}; |
59
|
9
|
|
|
|
|
25
|
bless $clone, ref $self; |
60
|
9
|
|
|
|
|
17
|
$clone->parser->set_receiver($clone->constructor); |
61
|
9
|
|
|
|
|
26
|
return $clone; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
4397
|
|
|
4397
|
0
|
10701
|
sub parser { return $_[0]->{parser} } |
65
|
2210
|
|
|
2210
|
0
|
3602
|
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
|
6971
|
my ($self, $yaml) = @_; |
78
|
2169
|
|
|
|
|
4596
|
$self->parser->set_reader(YAML::PP::Reader->new( input => $yaml )); |
79
|
2169
|
|
|
|
|
4923
|
$self->load(); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub load_file { |
83
|
19
|
|
|
19
|
0
|
53
|
my ($self, $file) = @_; |
84
|
19
|
|
|
|
|
46
|
$self->parser->set_reader(YAML::PP::Reader::File->new( input => $file )); |
85
|
19
|
|
|
|
|
78
|
$self->load(); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub load { |
89
|
2188
|
|
|
2188
|
0
|
3605
|
my ($self) = @_; |
90
|
2188
|
|
|
|
|
3721
|
my $parser = $self->parser; |
91
|
2188
|
|
|
|
|
4062
|
my $constructor = $self->constructor; |
92
|
|
|
|
|
|
|
|
93
|
2188
|
|
|
|
|
6781
|
$constructor->init; |
94
|
2188
|
|
|
|
|
6401
|
$parser->parse(); |
95
|
|
|
|
|
|
|
|
96
|
2160
|
|
|
|
|
4589
|
my $docs = $constructor->docs; |
97
|
2160
|
100
|
|
|
|
10523
|
return wantarray ? @$docs : $docs->[0]; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |