line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YAML::PP::Ref::Parser; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Scalar::Util qw/ openhandle /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
8
|
1
|
|
|
1
|
|
695
|
use YAML::Parser; |
|
1
|
|
|
|
|
63408
|
|
|
1
|
|
|
|
|
85
|
|
9
|
1
|
|
|
|
|
78
|
use YAML::PP::Common qw( |
10
|
|
|
|
|
|
|
YAML_PLAIN_SCALAR_STYLE |
11
|
|
|
|
|
|
|
YAML_SINGLE_QUOTED_SCALAR_STYLE YAML_DOUBLE_QUOTED_SCALAR_STYLE |
12
|
|
|
|
|
|
|
YAML_LITERAL_SCALAR_STYLE YAML_FOLDED_SCALAR_STYLE |
13
|
|
|
|
|
|
|
YAML_BLOCK_SEQUENCE_STYLE YAML_FLOW_SEQUENCE_STYLE |
14
|
|
|
|
|
|
|
YAML_BLOCK_MAPPING_STYLE YAML_FLOW_MAPPING_STYLE |
15
|
1
|
|
|
1
|
|
10
|
); |
|
1
|
|
|
|
|
3
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
6
|
use base 'YAML::PP::Parser'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
687
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my %style_map = ( |
20
|
|
|
|
|
|
|
plain => YAML_PLAIN_SCALAR_STYLE, |
21
|
|
|
|
|
|
|
single => YAML_SINGLE_QUOTED_SCALAR_STYLE, |
22
|
|
|
|
|
|
|
double => YAML_DOUBLE_QUOTED_SCALAR_STYLE, |
23
|
|
|
|
|
|
|
literal => YAML_LITERAL_SCALAR_STYLE, |
24
|
|
|
|
|
|
|
folded => YAML_FOLDED_SCALAR_STYLE, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub parse { |
28
|
4
|
|
|
4
|
0
|
8527
|
my ($self) = @_; |
29
|
4
|
|
|
|
|
17
|
my $reader = $self->reader; |
30
|
4
|
|
|
|
|
18
|
my $string; |
31
|
4
|
100
|
|
|
|
24
|
if ($reader->can('open_handle')) { |
32
|
2
|
100
|
|
|
|
8
|
if (openhandle($reader->input)) { |
33
|
1
|
|
|
|
|
6
|
$string = do { local $/; $reader->open_handle->getline }; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
4
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
1
|
|
|
1
|
|
44
|
open my $fh, '<:encoding(UTF-8)', $reader->input; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
11
|
|
37
|
1
|
|
|
|
|
1103
|
$string = do { local $/; <$fh> }; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
79
|
|
38
|
1
|
|
|
|
|
36
|
close $fh; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
2
|
|
|
|
|
7
|
$string = $reader->read; |
43
|
|
|
|
|
|
|
} |
44
|
4
|
|
|
|
|
7349
|
my $co = $self->receiver; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $cb = sub { |
47
|
51
|
|
|
51
|
|
2312571
|
my ($info) = @_; |
48
|
|
|
|
|
|
|
# Transform events becayse YAML::Parser uses something |
49
|
|
|
|
|
|
|
# very differnt from libyaml and YAML::PP |
50
|
51
|
|
|
|
|
113
|
my $event = (delete $info->{event}) . '_event'; |
51
|
51
|
100
|
|
|
|
193
|
if ($event eq 'alias_event') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
52
|
1
|
|
|
|
|
2
|
$info->{value} = delete $info->{name}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ($event eq 'scalar_event') { |
55
|
16
|
|
|
|
|
36
|
my $style = $style_map{ $info->{style} }; |
56
|
16
|
|
|
|
|
24
|
$info->{style} = $style; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif ($event eq 'document_start_event') { |
59
|
4
|
50
|
|
|
|
15
|
$info->{implicit} = delete $info->{explicit} ? 0 : 1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
elsif ($event eq 'document_end_event') { |
62
|
4
|
100
|
|
|
|
11
|
$info->{implicit} = delete $info->{explicit} ? 0 : 1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif ($event eq 'sequence_start_event') { |
65
|
4
|
50
|
|
|
|
15
|
if (delete $info->{flow}) { |
66
|
4
|
|
|
|
|
31
|
$info->{style} = YAML_FLOW_SEQUENCE_STYLE; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
0
|
|
|
|
|
0
|
$info->{style} = YAML_BLOCK_SEQUENCE_STYLE; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif ($event eq 'mapping_start_event') { |
73
|
5
|
100
|
|
|
|
16
|
if (delete $info->{flow}) { |
74
|
1
|
|
|
|
|
8
|
$info->{style} = YAML_FLOW_MAPPING_STYLE; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
4
|
|
|
|
|
29
|
$info->{style} = YAML_BLOCK_MAPPING_STYLE; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
51
|
|
|
|
|
127
|
$info->{name} = $event; |
81
|
51
|
50
|
|
|
|
92
|
if (ref $co eq 'CODE') { |
82
|
0
|
|
|
|
|
0
|
$co->($self, $event, $info); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
51
|
|
|
|
|
166
|
return $co->$event($info); |
86
|
|
|
|
|
|
|
} |
87
|
4
|
|
|
|
|
56
|
}; |
88
|
4
|
|
|
|
|
26
|
my $refrec = PerlYamlReferenceParserReceiver->new( |
89
|
|
|
|
|
|
|
callback => $cb, |
90
|
|
|
|
|
|
|
); |
91
|
4
|
|
|
|
|
56
|
my $p = YAML::Parser->new(receiver => $refrec); |
92
|
4
|
|
|
|
|
48
|
$p->parse($string); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |