Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/YAML/PP/Common.pm |
Statements | Executed 15 statements in 813µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 48µs | 70µs | BEGIN@2 | YAML::PP::Schema::
1 | 1 | 1 | 22µs | 24µs | BEGIN@1 | YAML::PP::Schema::
1 | 1 | 1 | 12µs | 202µs | BEGIN@32 | YAML::PP::Common::
1 | 1 | 1 | 6µs | 67µs | BEGIN@7 | YAML::PP::Common::
0 | 0 | 0 | 0s | 0s | event_to_test_suite | YAML::PP::Common::
0 | 0 | 0 | 0s | 0s | test_suite_to_event | YAML::PP::Common::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 2 | 24µs | 2 | 26µs | # spent 24µs (22+2) within YAML::PP::Schema::BEGIN@1 which was called:
# once (22µs+2µs) by YAML::PP::Schema::BEGIN@9 at line 1 # spent 24µs making 1 call to YAML::PP::Schema::BEGIN@1
# spent 2µs making 1 call to strict::import |
2 | 2 | 36µs | 2 | 92µs | # spent 70µs (48+22) within YAML::PP::Schema::BEGIN@2 which was called:
# once (48µs+22µs) by YAML::PP::Schema::BEGIN@9 at line 2 # spent 70µs making 1 call to YAML::PP::Schema::BEGIN@2
# spent 22µs making 1 call to warnings::import |
3 | package YAML::PP::Common; | ||||
4 | |||||
5 | 1 | 1µs | our $VERSION = '0.035'; # VERSION | ||
6 | |||||
7 | 2 | 82µs | 2 | 128µs | # spent 67µs (6+61) within YAML::PP::Common::BEGIN@7 which was called:
# once (6µs+61µs) by YAML::PP::Schema::BEGIN@9 at line 7 # spent 67µs making 1 call to YAML::PP::Common::BEGIN@7
# spent 61µs making 1 call to base::import |
8 | |||||
9 | 1 | 1µs | my @p = qw/ | ||
10 | PRESERVE_ALL PRESERVE_ORDER PRESERVE_SCALAR_STYLE PRESERVE_FLOW_STYLE | ||||
11 | PRESERVE_ALIAS | ||||
12 | /; | ||||
13 | 1 | 1µs | my @s = qw/ | ||
14 | YAML_ANY_SCALAR_STYLE YAML_PLAIN_SCALAR_STYLE | ||||
15 | YAML_SINGLE_QUOTED_SCALAR_STYLE YAML_DOUBLE_QUOTED_SCALAR_STYLE | ||||
16 | YAML_LITERAL_SCALAR_STYLE YAML_FOLDED_SCALAR_STYLE | ||||
17 | YAML_QUOTED_SCALAR_STYLE | ||||
18 | |||||
19 | YAML_ANY_SEQUENCE_STYLE | ||||
20 | YAML_BLOCK_SEQUENCE_STYLE YAML_FLOW_SEQUENCE_STYLE | ||||
21 | |||||
22 | YAML_ANY_MAPPING_STYLE | ||||
23 | YAML_BLOCK_MAPPING_STYLE YAML_FLOW_MAPPING_STYLE | ||||
24 | /; | ||||
25 | 1 | 1µs | our @EXPORT_OK = (@s, @p); | ||
26 | |||||
27 | 1 | 2µs | our %EXPORT_TAGS = ( | ||
28 | PRESERVE => [@p], | ||||
29 | STYLES => [@s], | ||||
30 | ); | ||||
31 | |||||
32 | # spent 202µs (12+190) within YAML::PP::Common::BEGIN@32 which was called:
# once (12µs+190µs) by YAML::PP::Schema::BEGIN@9 at line 55 | ||||
33 | 1 | 0s | YAML_ANY_SCALAR_STYLE => 0, | ||
34 | YAML_PLAIN_SCALAR_STYLE => 1, | ||||
35 | YAML_SINGLE_QUOTED_SCALAR_STYLE => 2, | ||||
36 | YAML_DOUBLE_QUOTED_SCALAR_STYLE => 3, | ||||
37 | YAML_LITERAL_SCALAR_STYLE => 4, | ||||
38 | YAML_FOLDED_SCALAR_STYLE => 5, | ||||
39 | YAML_QUOTED_SCALAR_STYLE => 'Q', # deprecated | ||||
40 | |||||
41 | YAML_ANY_SEQUENCE_STYLE => 0, | ||||
42 | YAML_BLOCK_SEQUENCE_STYLE => 1, | ||||
43 | YAML_FLOW_SEQUENCE_STYLE => 2, | ||||
44 | |||||
45 | YAML_ANY_MAPPING_STYLE => 0, | ||||
46 | YAML_BLOCK_MAPPING_STYLE => 1, | ||||
47 | YAML_FLOW_MAPPING_STYLE => 2, | ||||
48 | |||||
49 | PRESERVE_ORDER => 2, | ||||
50 | PRESERVE_SCALAR_STYLE => 4, | ||||
51 | PRESERVE_FLOW_STYLE => 8, | ||||
52 | PRESERVE_ALIAS => 16, | ||||
53 | |||||
54 | PRESERVE_ALL => 31, | ||||
55 | 1 | 656µs | 2 | 392µs | }; # spent 202µs making 1 call to YAML::PP::Common::BEGIN@32
# spent 190µs making 1 call to constant::import |
56 | |||||
57 | 1 | 3µs | my %scalar_style_to_string = ( | ||
58 | YAML_PLAIN_SCALAR_STYLE() => ':', | ||||
59 | YAML_SINGLE_QUOTED_SCALAR_STYLE() => "'", | ||||
60 | YAML_DOUBLE_QUOTED_SCALAR_STYLE() => '"', | ||||
61 | YAML_LITERAL_SCALAR_STYLE() => '|', | ||||
62 | YAML_FOLDED_SCALAR_STYLE() => '>', | ||||
63 | ); | ||||
64 | |||||
65 | |||||
66 | sub event_to_test_suite { | ||||
67 | my ($event, $args) = @_; | ||||
68 | my $ev = $event->{name}; | ||||
69 | my $string; | ||||
70 | my $content = $event->{value}; | ||||
71 | |||||
72 | my $properties = ''; | ||||
73 | $properties .= " &$event->{anchor}" if defined $event->{anchor}; | ||||
74 | $properties .= " <$event->{tag}>" if defined $event->{tag}; | ||||
75 | |||||
76 | if ($ev eq 'document_start_event') { | ||||
77 | $string = "+DOC"; | ||||
78 | $string .= " ---" unless $event->{implicit}; | ||||
79 | } | ||||
80 | elsif ($ev eq 'document_end_event') { | ||||
81 | $string = "-DOC"; | ||||
82 | $string .= " ..." unless $event->{implicit}; | ||||
83 | } | ||||
84 | elsif ($ev eq 'stream_start_event') { | ||||
85 | $string = "+STR"; | ||||
86 | } | ||||
87 | elsif ($ev eq 'stream_end_event') { | ||||
88 | $string = "-STR"; | ||||
89 | } | ||||
90 | elsif ($ev eq 'mapping_start_event') { | ||||
91 | $string = "+MAP"; | ||||
92 | if ($event->{style} and $event->{style} eq YAML_FLOW_MAPPING_STYLE) { | ||||
93 | $string .= ' {}' if $args->{flow}; | ||||
94 | } | ||||
95 | $string .= $properties; | ||||
96 | if (0) { | ||||
97 | # doesn't match yaml-test-suite format | ||||
98 | } | ||||
99 | } | ||||
100 | elsif ($ev eq 'sequence_start_event') { | ||||
101 | $string = "+SEQ"; | ||||
102 | if ($event->{style} and $event->{style} eq YAML_FLOW_SEQUENCE_STYLE) { | ||||
103 | $string .= ' []' if $args->{flow}; | ||||
104 | } | ||||
105 | $string .= $properties; | ||||
106 | if (0) { | ||||
107 | # doesn't match yaml-test-suite format | ||||
108 | } | ||||
109 | } | ||||
110 | elsif ($ev eq 'mapping_end_event') { | ||||
111 | $string = "-MAP"; | ||||
112 | } | ||||
113 | elsif ($ev eq 'sequence_end_event') { | ||||
114 | $string = "-SEQ"; | ||||
115 | } | ||||
116 | elsif ($ev eq 'scalar_event') { | ||||
117 | $string = '=VAL'; | ||||
118 | $string .= $properties; | ||||
119 | |||||
120 | $content =~ s/\\/\\\\/g; | ||||
121 | $content =~ s/\t/\\t/g; | ||||
122 | $content =~ s/\r/\\r/g; | ||||
123 | $content =~ s/\n/\\n/g; | ||||
124 | $content =~ s/[\b]/\\b/g; | ||||
125 | |||||
126 | $string .= ' ' | ||||
127 | . $scalar_style_to_string{ $event->{style} } | ||||
128 | . $content; | ||||
129 | } | ||||
130 | elsif ($ev eq 'alias_event') { | ||||
131 | $string = "=ALI *$content"; | ||||
132 | } | ||||
133 | return $string; | ||||
134 | } | ||||
135 | |||||
136 | sub test_suite_to_event { | ||||
137 | my ($str) = @_; | ||||
138 | my $event = {}; | ||||
139 | if ($str =~ s/^\+STR//) { | ||||
140 | $event->{name} = 'stream_start_event'; | ||||
141 | } | ||||
142 | elsif ($str =~ s/^\-STR//) { | ||||
143 | $event->{name} = 'stream_end_event'; | ||||
144 | } | ||||
145 | elsif ($str =~ s/^\+DOC//) { | ||||
146 | $event->{name} = 'document_start_event'; | ||||
147 | if ($str =~ s/^ ---//) { | ||||
148 | $event->{implicit} = 0; | ||||
149 | } | ||||
150 | else { | ||||
151 | $event->{implicit} = 1; | ||||
152 | } | ||||
153 | } | ||||
154 | elsif ($str =~ s/^\-DOC//) { | ||||
155 | $event->{name} = 'document_end_event'; | ||||
156 | if ($str =~ s/^ \.\.\.//) { | ||||
157 | $event->{implicit} = 0; | ||||
158 | } | ||||
159 | else { | ||||
160 | $event->{implicit} = 1; | ||||
161 | } | ||||
162 | } | ||||
163 | elsif ($str =~ s/^\+SEQ//) { | ||||
164 | $event->{name} = 'sequence_start_event'; | ||||
165 | if ($str =~ s/^ \&(\S+)//) { | ||||
166 | $event->{anchor} = $1; | ||||
167 | } | ||||
168 | if ($str =~ s/^ <(\S+)>//) { | ||||
169 | $event->{tag} = $1; | ||||
170 | } | ||||
171 | } | ||||
172 | elsif ($str =~ s/^\-SEQ//) { | ||||
173 | $event->{name} = 'sequence_end_event'; | ||||
174 | } | ||||
175 | elsif ($str =~ s/^\+MAP//) { | ||||
176 | $event->{name} = 'mapping_start_event'; | ||||
177 | if ($str =~ s/^ \&(\S+)//) { | ||||
178 | $event->{anchor} = $1; | ||||
179 | } | ||||
180 | if ($str =~ s/^ <(\S+)>//) { | ||||
181 | $event->{tag} = $1; | ||||
182 | } | ||||
183 | } | ||||
184 | elsif ($str =~ s/^\-MAP//) { | ||||
185 | $event->{name} = 'mapping_end_event'; | ||||
186 | } | ||||
187 | elsif ($str =~ s/^=VAL//) { | ||||
188 | $event->{name} = 'scalar_event'; | ||||
189 | if ($str =~ s/^ <(\S+)>//) { | ||||
190 | $event->{tag} = $1; | ||||
191 | } | ||||
192 | if ($str =~ s/^ [:'">|]//) { | ||||
193 | $event->{style} = $1; | ||||
194 | } | ||||
195 | if ($str =~ s/^(.*)//) { | ||||
196 | $event->{value} = $1; | ||||
197 | } | ||||
198 | } | ||||
199 | elsif ($str =~ s/^=ALI//) { | ||||
200 | $event->{name} = 'alias_event'; | ||||
201 | if ($str =~ s/^ \*(.*)//) { | ||||
202 | $event->{value} = $1; | ||||
203 | } | ||||
204 | } | ||||
205 | else { | ||||
206 | die "Could not parse event '$str'"; | ||||
207 | } | ||||
208 | return $event; | ||||
209 | } | ||||
210 | |||||
211 | |||||
212 | 1 | 6µs | 1; | ||
213 | |||||
214 | __END__ |