blib/lib/YATT/Lite/XHF.pm

filter: Statementstmt 90.7% 197 / 217 Branchbran 76.5% 75 / 98 Conditioncond 60.9% 25 / 41 MC/DCmcdc 24.0% 6 / 25 Subroutinesub 93.9% 31 / 33 Podpod 20.0% 4 / 20 totaltotal 77.8% 338 / 434 CC 66 SCAR 22.8
CC
66
Cov
83%
tokenize_1
26.2
organize_hash
11.4
tokenize
10.4
CRAP 9.8
« blib/lib/YATT/Lite/Partial/Gettext.pm ↑ Summary blib/lib/YATT/Lite/Site.pm »
1 package YATT::Lite::XHF; sub MY () {__PACKAGE__}
2 64 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 64 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 64 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 64 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 64 our $VERSION = "0.03";
8  
9 64 ▶use constant TRACE => $ENV{TRACE_XHF_PARSER};
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 64 ▶use base qw(YATT::Lite::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 64 ▶use fields qw(FH filename string tokens
Subroutine BEGIN: called CC=1 SCAR=0.0
13 _fh_configured
14 allow_empty_name
15 encoding crlf
16 nocr subst
17 first_lineno
18 _depth
19 64 skip_comment bytes);
20  
21 64 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 64 our @EXPORT = qw(read_file_xhf);
23 64 our @EXPORT_OK = (@EXPORT, qw(parse_xhf $cc_name));
24  
25 64 ▶use YATT::Lite::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 64 ▶use YATT::Lite::Util::Enum _ => [qw(NAME SIGIL VALUE LINENO)];
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 64 our $cc_name = qr{[0-9A-Za-z_\.\-/~!]};
29 64 our $re_suffix= qr{\[$cc_name*\]};
30 64 our $cc_sigil = qr{[:\#,\-=\[\]\{\}]};
31 64 our $cc_tabsp = qr{[\ \t]};
32  
33 64 our %OPN = ('[' => \&organize_array, '{' => \&organize_hash
34 , '=' => \&organize_expr);
35 64 our %CLO = (']' => '[', '}' => '{');
36 64 our %NAME_LESS = (%CLO, '-' => 1);
37 64 our %ALLOW_EMPTY_NAME = (':' => 1);
38  
39 115 ▶sub after_new {
Subroutine after_new: called CC=2 SCAR=7.2
Pod documented
40 115 (my MY $self) = @_;
41 115 ▶ $self->{skip_comment} //= 1;
Condition50%1/2
$self->{"skip_comment"} //= 1
l!l
0115
MC/DC0%0/1
$self->{"skip_comment"} //= 1
$self->{"skip_comment"}
Truth table50%1/2
A
A= $self->{"skip_comment"}
Aresult
11
00
42 }
43  
44 29 ▶sub read_file_xhf {
Subroutine read_file_xhf: called CC=4 SCAR=15.2
Pod documented
45 29 my ($pack, $fn, %rest) = @_;
46 29 my $method = do {
47 29 my $single = delete $rest{single};
48 29 ▶ my $all = delete $rest{all} // 1;
Condition50%1/2
delete $rest{"all"} // 1
l!l
029
MC/DC0%0/1
delete $rest{"all"} // 1
delete $rest{"all"}
Truth table50%1/2
A
A= delete $rest{"all"}
Aresult
11
00
49 29 ▶ if ($single or not $all) {
Branch: 1 branch
BranchTrueFalseTotal
if ($single or not $all) { } 0 29 29
Condition33%1/3
$single or not $all
l!l&&r!l&&!r
0029
MC/DC0%0/2
$single or not $all
$single not $all
Truth table33%1/3
A or not(B)
A= $singleB= not $all
ABresult
1X1
011
000
50 0 'read';
51 } else {
52 29 'read_all';
53 }
54 };
55 29 MY->new(filename => $fn, encoding => 'utf8', %rest)->$method;
56 }
57  
58 3 ▶sub parse_xhf {
Subroutine parse_xhf: called CC=1 SCAR=0.0
Pod documented
59 3 MY->new(string => @_)->read;
60 }
61  
62 64 *configure_file = \&configure_filename;
63 64 *configure_file = \&configure_filename;
64 47 ▶sub configure_filename {
Subroutine configure_filename: called CC=2 SCAR=7.0
Pod undocumented
65 47 (my MY $self, my ($fn)) = @_;
66 47 ▶ open $self->{FH}, '<', $fn
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"FH"}, "<", $fn or croak("Can't open file '${fn}': $!") 47 0 47
67 or croak "Can't open file '$fn': $!";
68 47 $self->{_fh_configured} = 0;
69 47 $self->{filename} = $fn;
70 47 $self;
71 }
72  
73 1 ▶sub configure_filename_for_error {
Subroutine configure_filename_for_error: called CC=1 SCAR=0.0
Pod undocumented
74 1 (my MY $self, my ($fn)) = @_;
75 1 $self->{filename} = $fn;
76 }
77  
78 # To accept in-stream encoding spec.
79 # (See YATT::Lite::Test::XHFTest::load and t/lite_xhf.t)
80 31 ▶sub configure_encoding {
Subroutine configure_encoding: called CC=1 SCAR=0.0
Pod undocumented
81 31 (my MY $self, my $value) = @_;
82 31 $self->{_fh_configured} = 0;
83 31 $self->{encoding} = $value;
84 }
85  
86 0 ▶sub configure_binary {
Subroutine configure_binary: not called CC=1 SCAR=6.9
Pod undocumented
87 0 (my MY $self, my $value) = @_;
88 0 warnings::warnif(deprecated =>
89 "XHF option 'binary' is deprecated, use 'bytes' instead");
90 0 $self->{bytes} = $value;
91 }
92  
93 68 ▶sub configure_string {
Subroutine configure_string: called CC=2 SCAR=7.0
Pod undocumented
94 68 my MY $self = shift;
95 68 ($self->{string}) = @_;
96 open $self->{FH}, '<', \ $self->{string}
97 68 ▶ or croak "Can't create string stream: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"FH"}, "<", \$self->{"string"} or croak("Can't create string stream: $!") 68 0 68
98 68 $self;
99 }
100  
101 0 ▶sub trace {
Subroutine trace: not called CC=1 SCAR=6.9
Pod undocumented
102 0 (my MY $reader, my ($msg, @desc)) = @_;
103 0 print STDERR " " x $reader->{_depth}, $msg, terse_dump(@desc), "\n";
104 }
105  
106 29 ▶sub read_all {
Subroutine read_all: called CC=3 SCAR=11.0
Pod undocumented
107 29 (my MY $self) = @_;
108 29 my @res;
109 29 ▶ while (my @block = $self->read) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@block) = $self->read) 29 29 58
110 29 push @res, @block;
111 }
112 29 ▶ wantarray ? @res : do {
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 23 6 29
113 6 my %dict = @res;
114 6 \%dict;
115 };
116 }
117  
118 # XXX: Should I rename this to read_one()?
119 414 ▶sub read {
Subroutine read: called CC=1 SCAR=0.0
Pod documented
120 414 my MY $self = shift;
121 414 ▶ $self->cf_let(\@_, sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
122 414 ▶ if (my @tokens = $self->tokenize) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@tokens) = $self->tokenize) { } 348 66 414
123 348 $self->organize(@tokens);
124 } else {
125 66 return;
126 }
127 414 });
128 }
129  
130 414 ▶sub tokenize {
Subroutine tokenize: called CC=10 SCAR=23.4
Pod undocumented
131 414 (my MY $self) = @_;
132 414 local $/ = "";
133 414 my $fh = $$self{FH};
134 414 ▶ unless ($self->{_fh_configured}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_fh_configured"}++) 117 297 414
135 117 ▶ if (not $self->{bytes} and not $self->{string}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"bytes"} || $self->{"string"} and $self->{"encoding"}) 31 86 117
Condition83%5/6
not $self->{"bytes"} || $self->{"string"} and $self->{"encoding"}
!ll&&!rl&&r
662031
$self->{'bytes'} || $self->{'string'}
l!l&&r!l&&!r
06651
MC/DC66%2/3
not $self->{"bytes"} || $self->{"string"} and $self->{"encoding"}
$self->{'bytes'} $self->{'string'} $self->{"encoding"}
Truth table75%3/4
not(A || B) and C
A= $self->{'bytes'}B= $self->{'string'}C= $self->{"encoding"}
ABCresult
1XX0
01X0
0000
0011
136 and $self->{encoding}) {
137 31 binmode $fh, ":encoding($self->{encoding})";
138 }
139 117 ▶ if ($self->{crlf}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"crlf"}) 0 117 117
140 0 binmode $fh, ":crlf";
141 }
142 }
143  
144 414 my @tokens;
145 LOOP: {
146 414 do {
147 414 ▶ defined (my $para = <$fh>) or last LOOP;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $para = readline $fh) or last LOOP 360 54 414
148 $para = untaint_unless_tainted
149 ($self->{filename} // $self->{string}
150 360 ▶ , $para);
Condition66%2/3
$self->{"filename"} // $self->{"string"}
l!l&&r!l&&!r
293670
MC/DC0%0/2
$self->{"filename"} // $self->{"string"}
$self->{"filename"} $self->{"string"}
Truth table66%2/3
A // B
A= $self->{"filename"}B= $self->{"string"}
ABresult
1X1
011
000
151 360 @tokens = $self->tokenize_1($para);
152 414 ▶ } until (not $self->{skip_comment} or @tokens);
Branch: 1 branch
BranchTrueFalseTotal
(not $self->{"skip_comment"} or @tokens) or do { do { defined(my $para = readline $fh) or last LOOP; $para = untaint_unless_tainted($self->{"filename"} // $self->{"string"}, $para); @tokens = $self->tokenize_1($para) } } 360 0 360
Condition66%2/3
not $self->{"skip_comment"} or @tokens
l!l&&r!l&&!r
183420
MC/DC0%0/2
not $self->{"skip_comment"} or @tokens
not $self->{"skip_comment"} @tokens
Truth table66%2/3
not(A) or B
A= not $self->{"skip_comment"}B= @tokens
ABresult
1X1
011
000
153 }
154 414 @tokens;
155 }
156  
157 360 ▶sub tokenize_1 {
Subroutine tokenize_1: called CC=20 SCAR=32.7
Pod undocumented
158 360 my MY $reader = shift;
159 360 $_[0] =~ s{\n+$}{\n}s;
160 360 ▶ $_[0] =~ s{\r+}{}g if $reader->{nocr};
Branch: 1 branch
BranchTrueFalseTotal
if $reader->{"nocr"} 0 360 360
161 360 ▶ if (my $sub = $reader->{subst}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $reader->{"subst"}) 0 360 360
162 0 local $_;
163 0 *_ = \ $_[0];
164 0 $sub->($_);
165 }
166 360 ▶ my $lineno = $reader->{first_lineno} // 1;
Condition100%2/2
$reader->{"first_lineno"} // 1
l!l
1359
MC/DC100%1/1
$reader->{"first_lineno"} // 1
$reader->{"first_lineno"}
Truth table100%2/2
A
A= $reader->{"first_lineno"}
Aresult
11
00
167 360 my ($pos, $ncomments, @tokens, @result);
168 360 foreach my $token (@tokens = split /(?<=\n)(?=[^\ \t])/, $_[0]) {
169 1658 $pos++;
170 1658 ▶ if ($token =~ s{^(?:\#[^\n]*(?:\n|$))+}{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token =~ s/^(?:\#[^\n]*(?:\n|$))+//) 47 1611 1658
171 47 $ncomments++;
172 47 ▶ next if $token eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "" 47 0 47
173 }
174  
175 1611 ▶ unless ($token =~ s{^($cc_name*$re_suffix*) ($cc_sigil) (?:($cc_tabsp)|(\n|$))}{}x) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token =~ s/^($YATT::Lite::XHF::cc_name*$YATT::Lite::XHF::re_suffix*) ($YATT::Lite::XHF::cc_sigil) (?:($YATT::Lite::XHF::cc_tabsp)|(\n|$))//x) 0 1611 1611
176 0 croak "Invalid XHF token '$token' ".$reader->fileinfo_lineno($lineno)."\n";
177 }
178 1611 my ($name, $sigil, $tabsp, $eol) = ($1, $2, $3, $4);
179  
180 1611 ▶ if ($name eq '') {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq '') { } 627 984 1611
elsif ($YATT::Lite::XHF::NAME_LESS{$sigil}) { } 0 984 984
181 croak "Invalid XHF token(name is empty for '$token') "
182 .$reader->fileinfo_lineno($lineno)."\n"
183 627 ▶ if $sigil eq ':' and not $reader->{allow_empty_name};
Branch: 1 branch
BranchTrueFalseTotal
if $sigil eq ":" and not $reader->{"allow_empty_name"} 0 627 627
Condition33%1/3
$sigil eq ":" and not $reader->{"allow_empty_name"}
!ll&&!rl&&r
62700
MC/DC0%0/2
$sigil eq ":" and not $reader->{"allow_empty_name"}
$sigil eq ":" not $reader->{"allow_empty_name"}
Truth table33%1/3
A and not(B)
A= $sigil eq ":"B= not $reader->{"allow_empty_name"}
ABresult
0X0
100
111
184 } elsif ($NAME_LESS{$sigil}) {
185 0 croak "Invalid XHF token('$sigil' should not be prefixed by name '$name') "
186 .$reader->fileinfo_lineno($lineno)."\n";
187 }
188  
189 # Comment fields are ignored.
190 1611 ▶ $ncomments++, next if $sigil eq "#";
Branch: 1 branch
BranchTrueFalseTotal
if $sigil eq "#" 0 1611 1611
191  
192 1611 ▶ if ($CLO{$sigil}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YATT::Lite::XHF::CLO{$sigil}) 231 1380 1611
193 231 undef $name;
194 }
195  
196 # Line continuation.
197 1611 $token =~ s/\n[\ \t]/\n/g;
198  
199 1611 ▶ unless (defined $eol) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $eol) { } 861 750 1611
200 # Values are trimmed unless $eol
201 750 $token =~ s/^\s+|\s+$//gs;
202 } else {
203 # Deny: name{ foo
204 # Allow: name[ foo
205 croak "Invalid XHF token(container with value) "
206 861 ▶ . join("", grep {defined $_} $name, $sigil, $tabsp, $token)
Branch: 1 branch
BranchTrueFalseTotal
if $sigil eq "{" and $token ne "" 0 861 861
Condition66%2/3
$sigil eq "{" and $token ne ""
!ll&&!rl&&r
838230
MC/DC0%0/2
$sigil eq "{" and $token ne ""
$sigil eq "{" $token ne ""
Truth table66%2/3
A and B
A= $sigil eq "{"B= $token ne ""
ABresult
0X0
100
111
207 . $reader->fileinfo_lineno($lineno)."\n"
208 if $sigil eq '{' and $token ne "";
209  
210 # Trim leading space for $tabsp eq "\n".
211 861 $token =~ s/^[\ \t]//;
212 }
213 1611 push @result, [$name, $sigil, $token, $lineno];
214 } continue {
215 1658 $lineno++;
216 }
217  
218 # Comment only paragraph should return nothing.
219 360 ▶ return if $ncomments && !@result;
Branch: 1 branch
BranchTrueFalseTotal
if $ncomments and not @result 12 348 360
Condition100%3/3
$ncomments and not @result
!ll&&!rl&&r
3331512
MC/DC100%2/2
$ncomments and not @result
$ncomments not @result
Truth table100%3/3
A and not(B)
A= $ncommentsB= not @result
ABresult
0X0
100
111
220  
221 348 ▶ wantarray ? @result : \@result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 348 0 348
222 }
223  
224 6 ▶sub fileinfo {
Subroutine fileinfo: called CC=1 SCAR=0.0
Pod undocumented
225 6 (my MY $reader, my $desc) = @_;
226 6 $reader->fileinfo_lineno($desc->[_LINENO]);
227 }
228  
229 6 ▶sub fileinfo_lineno {
Subroutine fileinfo_lineno: called CC=2 SCAR=7.2
Pod undocumented
230 6 (my MY $reader, my $lineno) = @_;
231 sprintf("at %s line %d"
232 6 ▶ , $reader->{filename} // "(unknown)"
Condition50%1/2
$reader->{"filename"} // "(unknown)"
l!l
06
MC/DC0%0/1
$reader->{"filename"} // "(unknown)"
$reader->{"filename"}
Truth table50%1/2
A
A= $reader->{"filename"}
Aresult
11
00
233 , $lineno);
234 }
235  
236 348 ▶sub organize {
Subroutine organize: called CC=7 SCAR=19.5
Pod undocumented
237 348 my MY $reader = shift;
238 348 local $reader->{_depth} = -1;
239 348 my $pos = 0;
240 348 my @result;
241 348 ▶ while ($pos < @_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < @_) 976 342 1318
242 976 my $desc = $_[$pos++];
243 976 ▶ unless (defined $desc->[_NAME]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $desc->[0]) 2 974 976
244 2 croak "Invalid XHF: Field close '$desc->[_SIGIL]'"
245 ." (line $desc->[_LINENO]) without open! "
246 .$reader->fileinfo($desc)."\n";
247 }
248 push @result, $desc->[_NAME] if $desc->[_NAME] ne ''
249 974 ▶ or $ALLOW_EMPTY_NAME{$desc->[_SIGIL]};
Branch: 1 branch
BranchTrueFalseTotal
if $desc->[0] ne "" or $YATT::Lite::XHF::ALLOW_EMPTY_NAME{$desc->[1]} 919 55 974
Condition66%2/3
$desc->[0] ne "" or $YATT::Lite::XHF::ALLOW_EMPTY_NAME{$desc->[1]}
l!l&&r!l&&!r
919055
MC/DC50%1/2
$desc->[0] ne "" or $YATT::Lite::XHF::ALLOW_EMPTY_NAME{$desc->[1]}
$desc->[0] ne "" $YATT::Lite::XHF::ALLOW_EMPTY_NAME{$desc->[1]}
Truth table66%2/3
A or B
A= $desc->[0] ne ""B= $YATT::Lite::XHF::ALLOW_EMPTY_NAME{$desc->[1]}
ABresult
1X1
011
000
250 974 ▶ if (my $sub = $OPN{$desc->[_SIGIL]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $YATT::Lite::XHF::OPN{$desc->[1]}) { } 188 786 974
251 # sigil がある時、value を無視して、良いのか?
252 188 push @result, $sub->($reader, \$pos, \@_, $desc);
253 } else {
254 786 push @result, $desc->[_VALUE];
255 }
256 }
257 342 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 337 5 342
258 @result
259 337 } else {
260 5 my %hash = @result;
261 5 \%hash;
262 }
263 }
264  
265 # '[' block
266 208 ▶sub organize_array {
Subroutine organize_array: called CC=8 SCAR=20.9
Pod undocumented
267 208 (my MY $reader, my ($posref, $tokens, $first)) = @_;
268 208 local $reader->{_depth} = $reader->{_depth} + 1;
269 208 $reader->trace("> ", $first) if TRACE;
270 208 my @result;
271 208 ▶ push @result, $first->[_VALUE] if defined $first and $first->[_VALUE] ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $first and $first->[2] ne "" 0 208 208
Condition33%1/3
defined $first and $first->[2] ne ""
!ll&&!rl&&r
02080
MC/DC0%0/2
defined $first and $first->[2] ne ""
defined $first $first->[2] ne ""
Truth table33%1/3
A and B
A= defined $firstB= $first->[2] ne ""
ABresult
0X0
100
111
272 208 ▶ while ($$posref < @$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$posref < @$tokens) 571 1 572
273 571 my $desc = $tokens->[$$posref++];
274 # NAME
275 571 ▶ unless (defined $desc->[_NAME]) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $desc->[0]) { } 364 207 571
if (do { $desc->[0] ne "" }) 37 327 364
276 207 ▶ if ($desc->[_SIGIL] ne ']') {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc->[1] ne "]") 1 206 207
277 1 croak "Invalid XHF: paren mismatch. '['"
278 ." (line $first->[_LINENO]) is closed by '$desc->[_SIGIL]' "
279 .$reader->fileinfo($desc)."\n";
280 }
281 206 $reader->trace("< ", $first, $desc) if TRACE;
282 206 return \@result;
283 }
284 0 elsif ($desc->[_NAME] ne '') {
285 37 $reader->trace("| ", $desc) if TRACE;
286 37 push @result, $desc->[_NAME];
287 }
288 # VALUE
289 364 ▶ if (my $sub = $OPN{$desc->[_SIGIL]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $YATT::Lite::XHF::OPN{$desc->[1]}) { } 60 304 364
290 # sigil がある時、value があったらどうするかは、子供次第。
291 60 push @result, $sub->($reader, $posref, $tokens, $desc);
292 }
293 else {
294 304 $reader->trace("| ", $desc) if TRACE;
295 304 push @result, $desc->[_VALUE];
296 }
297 }
298 1 croak "Invalid XHF: Missing close ']' for '[' "
299 .$reader->fileinfo($first)."\n";
300 }
301  
302 # '{' block.
303 23 ▶sub organize_hash {
Subroutine organize_hash: called CC=11 SCAR=24.3
Pod undocumented
304 23 (my MY $reader, my ($posref, $tokens, $first)) = @_;
305 23 ▶ croak "Invalid XHF hash block beginning! "
Branch: 1 branch
BranchTrueFalseTotal
if defined $first and $first->[2] ne "" 0 23 23
Condition33%1/3
defined $first and $first->[2] ne ""
!ll&&!rl&&r
0230
MC/DC0%0/2
defined $first and $first->[2] ne ""
defined $first $first->[2] ne ""
Truth table33%1/3
A and B
A= defined $firstB= $first->[2] ne ""
ABresult
0X0
100
111
306 . join("", @$first).$reader->fileinfo($first)."\n"
307 if defined $first and $first->[_VALUE] ne '';
308 23 local $reader->{_depth} = $reader->{_depth} + 1;
309 23 $reader->trace("> ", $first) if TRACE;
310 23 my %result;
311 23 ▶ while ($$posref < @$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$posref < @$tokens) 57 1 58
312 57 my $desc = $tokens->[$$posref++];
313 # NAME
314 57 ▶ unless (defined $desc->[_NAME]) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $desc->[0]) { } 35 22 57
if (do { $desc->[1] eq '-' }) { } 7 28 35
315 22 ▶ if ($desc->[_SIGIL] ne '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc->[1] ne "}") 1 21 22
316 1 croak "Invalid XHF: paren mismatch. '{'"
317 ." (line $first->[_LINENO]) is closed by '$desc->[_SIGIL]' "
318 .$reader->fileinfo($desc)."\n";
319 }
320 21 $reader->trace("< ", $first, $desc) if TRACE;
321 21 return \%result;
322 }
323 elsif ($desc->[_SIGIL] eq '-') {
324 # Should treat two lines as one key value pair.
325 7 ▶ unless ($$posref < @$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$posref < @$tokens) 0 7 7
326 0 croak "Invalid XHF hash:"
327 ." key '- $desc->[_VALUE]' doesn't have value! "
328 .$reader->fileinfo($desc)."\n";
329 }
330 7 my $valdesc = $tokens->[$$posref++];
331 7 my $value = do {
332 7 ▶ if (my $sub = $OPN{$valdesc->[_SIGIL]}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $sub = $YATT::Lite::XHF::OPN{$valdesc->[1]}) { } 2 5 7
elsif ($valdesc->[1] eq '-') { } 5 0 5
333 2 $sub->($reader, $posref, $tokens, $valdesc);
334 } elsif ($valdesc->[_SIGIL] eq '-') {
335 5 $valdesc->[_VALUE];
336 } else {
337 0 croak "Invalid XHF hash value:"
338 . " key '$desc->[_VALUE]' has invalid sigil '$valdesc->[_SIGIL]' "
339 .$reader->fileinfo($valdesc)."\n"
340 }
341 };
342 7 $reader->add_value($result{$desc->[_VALUE]}, $value);
343 } else {
344 28 $reader->trace("| ", $desc) if TRACE;
345 28 ▶ if (my $sub = $OPN{$desc->[_SIGIL]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $YATT::Lite::XHF::OPN{$desc->[1]}) 6 22 28
346 # sigil がある時、value を無視して、良いのか?
347 6 $desc->[_VALUE] = $sub->($reader, $posref, $tokens, $desc);
348 }
349 28 $reader->add_value($result{$desc->[_NAME]}, $desc->[_VALUE]);
350 }
351 }
352 1 croak "Invalid XHF: Missing close '}' for '{' "
353 .$reader->fileinfo($first)."\n";
354 }
355  
356 # '=' value
357 25 ▶sub _undef {undef}
Subroutine _undef: called CC=1 SCAR=0.0
358 64 our %EXPR = (null => \&_undef, 'undef' => \&_undef);
359 25 ▶sub organize_expr {
Subroutine organize_expr: called CC=3 SCAR=12.0
Pod undocumented
360 25 (my MY $reader, my ($posref, $tokens, $first)) = @_;
361 25 ▶ if ((my $val = $first->[_VALUE]) =~ s/^\#(\w+)\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $val = $first->[2]) =~ s/^\#(\w+)\s*//) { } 25 0 25
362 25 ▶ my $sub = $EXPR{$1}
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $YATT::Lite::XHF::EXPR{$1} or croak("Invalid XHF keyword: '= #$1'") 25 0 25
363 or croak "Invalid XHF keyword: '= #$1'";
364 25 $sub->($reader, $val, $tokens);
365 } else {
366 0 croak "Not yet implemented XHF token: '@$first'";
367 }
368 }
369  
370 35 ▶sub add_value {
Subroutine add_value: called CC=3 SCAR=16.0
Pod undocumented
371 35 my MY $reader = shift;
372 35 ▶ unless (defined $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_[0]) { } 0 35 35
if (do { ref $_[0] ne 'ARRAY' }) { } 0 0 0
373 35 $_[0] = $_[1];
374 } elsif (ref $_[0] ne 'ARRAY') {
375 0 $_[0] = [$_[0], $_[1]];
376 } else {
377 0 push @{$_[0]}, $_[1];
378 }
379 }
380  
381 64 ▶use YATT::Lite::Breakpoint;
Subroutine BEGIN: called CC=1 SCAR=0.0
382 64 YATT::Lite::Breakpoint::break_load_xhf();
383  
384 64 1;
385  
386 __END__
« blib/lib/YATT/Lite/Partial/Gettext.pm ↑ Summary blib/lib/YATT/Lite/Site.pm »