blib/lib/YATT/Lite/CGen/Perl.pm

filter: Statementstmt 87.5% 699 / 798 Branchbran 80.9% 298 / 368 Conditioncond 69.7% 138 / 198 MC/DCmcdc 46.7% 51 / 109 Subroutinesub 83.1% 94 / 113 Podpod 0.0% 0 / 92 totaltotal 76.2% 1280 / 1678 CC 266 SCAR 23.5
CC
266
Cov
83%
macro_foreach
27.5
gen_lcmsg
26.8
gen_putargs
24.0
CRAP 10.5
« blib/lib/YATT/Lite/Core.pm ↑ Summary blib/lib/YATT/Lite/Partial/Gettext.pm »
1 package YATT::Lite::CGen::Perl;
2 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 46 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 46 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 46 require 5.010; # For named capture.
7  
8 46 ▶use constant DEBUG_MRO => $ENV{DEBUG_YATT_MRO};
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 46 ▶use YATT::Lite::Core qw(Folder Template Part Widget Action Entity ArgMacro Import);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 46 ▶use YATT::Lite::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # Naming convention:
14 # generate_SRC -- Public Interface.
15 # gen_DETAIL -- Internal higher/large tasks.
16 # from_NODETYPE -- Node Type specific dispatch entry.
17 # as_WHATHOW_FROM -- Miscellaneous dispatching (for var type and others)
18  
19 {
20 #========================================
21 package YATT::Lite::CGen::Perl; sub MY () {__PACKAGE__}
22 46 ▶ use base qw(YATT::Lite::CGen);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 46 ▶ use YATT::Lite::MFields;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 46 ▶ use YATT::Lite::Util qw(lexpand numLines globref terse_dump catch);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 46 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 #========================================
27 866 ▶ sub list_inheritance {
Subroutine list_inheritance: called CC=3 SCAR=11.8
Pod undocumented
28 866 (my MY $self, my Template $tmpl) = @_;
29 # XXX: Duplicate detection should be handled higer layer.
30 866 my %dup;
31 map {
32 866 my Folder $f = $_;
33 896 ▶ unless (defined $f->{entns}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $f->{"entns"}) 0 896 896
34 0 die "BUG: EntNS is empty for ".terse_dump($f->{name})."!";
35 }
36 896 ▶ if ($dup{$f->{entns}}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dup{$f->{'entns'}}++) { } 0 896 896
37 ()
38 0 } else {
39 $f->{entns}
40 896 }
41 } $tmpl->list_base
42 }
43 433 ▶ sub setup_inheritance_for {
Subroutine setup_inheritance_for: called CC=5 SCAR=18.2
Pod undocumented
44 433 (my MY $self, my $spec, my Template $tmpl) = @_;
45 433 ▶ unless (defined $tmpl->{entns}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tmpl->{"entns"}) 0 433 433
46 0 die "BUG: EntNS is empty for '$tmpl->{name}'!";
47 }
48 433 my $glob = globref($$tmpl{entns}, 'ISA');
49 # XXX: base change should be reflected when reloaded, but...
50 433 ▶ unless (defined $glob) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $glob) 0 433 433
51 0 die "BUG: ISA glob for '$tmpl->{name}' is empty!";
52 }
53 433 $self->ensure_generated_for_folders($spec, $tmpl->list_base);
54 433 my @isa = $self->list_inheritance($tmpl);
55 433 ▶ if (grep {not defined} @isa) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not defined $_;} @isa) 0 433 433
56 0 die "BUG: ISA for '$tmpl->{name}' contains undef!";
57 }
58 433 ▶ if (my $err = catch {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = &catch(sub { *$glob = \@isa; } )) 0 433 433
59 433 *$glob = \@isa;
60 }) {
61 die $self->generror("Can't set ISA for '%s' as [%s]: %s"
62 , $tmpl->{name}
63 0 , join(", ", @isa)
64 , $err
65 );
66 }
67 }
68 433 ▶ sub generate_inheritance {
Subroutine generate_inheritance: called CC=1 SCAR=0.0
Pod undocumented
69 433 (my MY $self, my Template $tmpl) = @_;
70 433 my @isa = $self->list_inheritance($tmpl);
71 433 my $mro = mro::get_mro($tmpl->{entns});
72 433 print STDERR "($mro) [$tmpl->{path}] $tmpl->{entns}::ISA = @isa\n"
73 if DEBUG_MRO;
74 433 sprintf q{use mro '%s'; our @ISA = qw(%s); }, $mro, join " ", @isa;
75 }
76 #========================================
77 433 ▶ sub generate_preamble {
Subroutine generate_preamble: called CC=6 SCAR=18.0
Pod undocumented
78 433 (my MY $self, my Template $tmpl) = @_;
79 433 ▶ $tmpl ||= $self->{_curtmpl};
Condition33%1/3
$tmpl ||= $self->{"_curtmpl"}
l!l&&r!l&&!r
43300
MC/DC0%0/2
$tmpl ||= $self->{"_curtmpl"}
$tmpl $self->{"_curtmpl"}
Truth table33%1/3
A ||= B
A= $tmplB= $self->{"_curtmpl"}
ABresult
1X1
011
000
80 433 my @stats;
81 433 ▶ unless ($self->{no_lineinfo}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"no_lineinfo"}) 433 0 433
82 433 my $line = qq{#line }. $self->{_curline};
83 433 ▶ if (defined(my $fn = $tmpl->fake_filename)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $fn = $tmpl->fake_filename)) 429 4 433
84 # cf_name is dummy filename.
85 429 $line .= qq{ "$fn"};
86 }
87 433 push @stats, $line .= "\n";
88 }
89 push @stats, sprintf q{package %s; use strict; use warnings; use 5.010; }
90 433 , $$tmpl{entns};
91 433 push @stats, $self->generate_inheritance($tmpl);
92 433 ▶ push @stats, "use utf8; " if $$tmpl{utf8};
Branch: 1 branch
BranchTrueFalseTotal
if $tmpl->{"utf8"} 238 195 433
93 433 ▶ push @stats, q|no warnings qw(redefine); | if $$tmpl{age}++;
Branch: 1 branch
BranchTrueFalseTotal
if $tmpl->{"age"}++ 16 417 433
94 433 push @stats, sprintf q|sub filename {__FILE__}; |;
95 @stats
96 433 }
97 439 ▶ sub generate_page {
Subroutine generate_page: called CC=1 SCAR=0.0
Pod undocumented
98 # XXX: 本物へ。 public フラグ?
99 439 shift->generate_widget(@_);
100 }
101 600 ▶ sub generate_widget {
Subroutine generate_widget: called CC=3 SCAR=11.0
Pod undocumented
102 600 (my MY $self, my Widget $widget, my ($widget_name, $tmpl_path)) = @_;
103 600 ▶ if ($widget->{suppressed}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($widget->{"suppressed"}) 2 598 600
104 # Implicit default widget which contains no content.
105 2 return $self->sync_curline($widget->{endln});
106 }
107 598 break_cgen();
108 598 local $self->{_curwidget} = $widget;
109 # XXX: calling convention 周り, body の code 型
110 local $self->{_scope} = $self->mkscope
111 ({}, $widget->{_var_dict}, $widget->{_arg_dict} ||= {}
112 598 ▶ , {this => $self->mkvar_at(undef, text => 'this')
Condition50%1/2
$widget->{"_arg_dict"} ||= {}
l!l
5980
MC/DC0%0/1
$widget->{"_arg_dict"} ||= {}
$widget->{"_arg_dict"}
Truth table50%1/2
A
A= $widget->{"_arg_dict"}
Aresult
11
00
113 , 'CON' => $self->mkvar_at(undef, text => 'CON')
114 , '_' => $self->mkvar_at(undef, text => '_')}
115 );
116 598 local $self->{_curtoks} = [@{$widget->{_tree}}];
117 ($self->sync_curline($widget->{startln})
118 , "sub render_$$widget{name} {"
119 , $self->gen_preamble($widget)
120 , $self->gen_getargs($widget, not $widget->{implicit})
121 598 , $self->as_print("}")
122 );
123 }
124 13 ▶ sub generate_action {
Subroutine generate_action: called CC=4 SCAR=13.9
Pod undocumented
125 13 (my MY $self, my Action $action) = @_;
126 # XXX: 改行の調整が必要。
127 my @src = ($self->sync_curline($action->{startln})
128 13 , "sub do_$$action{name} {");
129 13 my $src = $self->{_curtmpl}->part_body_source($action);
130  
131 13 ▶ if (lexpand($action->{_arg_order})
Branch: 1 branch
BranchTrueFalseTotal
if (lexpand($action->{"_arg_order"}) or not $src =~ /^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;/) 11 2 13
Condition100%3/3
lexpand($action->{"_arg_order"}) or not $src =~ /^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;/
l!l&&r!l&&!r
472
MC/DC100%2/2
lexpand($action->{"_arg_order"}) or not $src =~ /^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;/
lexpand($action->{"_arg_order"}) not $src =~ /^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;/
Truth table100%3/3
A or not(B)
A= lexpand($action->{"_arg_order"})B= not $src =~ /^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;/
ABresult
1X1
011
000
132 or $src !~ m{^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;}) {
133 # If an action has no arguments
134 # and its source doesn't start with my (...) = @_;,
135 # insert preamble and getargs.
136 push @src, $self->gen_preamble($action)
137 11 , $self->gen_getargs($action, not $action->{implicit});
138 }
139  
140 13 my $has_nl = $src =~ s/\r?\n\Z//;
141 13 ▶ $self->{_curline} = $action->{bodyln} + numLines($src)
Branch: 1 branch
BranchTrueFalseTotal
$has_nl ? : 13 0 13
142 + ($has_nl ? 1 : 0);
143 13 (@src, $src, "}");
144 }
145  
146 # XXX: As you see, dup code.
147 # XXX: Should define common base class for Action and Entity.
148 15 ▶ sub generate_entity {
Subroutine generate_entity: called CC=4 SCAR=14.0
Pod undocumented
149 15 (my MY $self, my Entity $entity) = @_;
150 # XXX: 改行の調整が必要。
151 my @src = ($self->sync_curline($entity->{startln})
152 15 , "sub entity_$$entity{name} {");
153 15 my $src = $self->{_curtmpl}->part_body_source($entity);
154  
155 15 ▶ if (lexpand($entity->{_arg_order})
Branch: 1 branch
BranchTrueFalseTotal
if (lexpand($entity->{"_arg_order"}) or not $src =~ /^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;/) 15 0 15
Condition66%2/3
lexpand($entity->{"_arg_order"}) or not $src =~ /^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;/
l!l&&r!l&&!r
4110
MC/DC0%0/2
lexpand($entity->{"_arg_order"}) or not $src =~ /^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;/
lexpand($entity->{"_arg_order"}) not $src =~ /^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;/
Truth table66%2/3
A or not(B)
A= lexpand($entity->{"_arg_order"})B= not $src =~ /^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;/
ABresult
1X1
011
000
156 or $src !~ m{^([\ \t\r\n]*)my\s*\([^;\)]+\)\s*=\s*\@_\s*;}) {
157 # If an entity has no arguments
158 # and its source doesn't start with my (...) = @_;,
159 # insert preamble and getargs.
160 push @src, q{ my ($this) = shift; my $CON = $this->CON;}
161 15 , $self->gen_getargs($entity, not $entity->{implicit});
162 }
163  
164 15 my $has_nl = $src =~ s/\r?\n\Z//;
165 15 ▶ $self->{_curline} = $entity->{bodyln} + numLines($src)
Branch: 1 branch
BranchTrueFalseTotal
$has_nl ? : 13 2 15
166 + ($has_nl ? 1 : 0);
167 15 (@src, $src, "}");
168 }
169  
170 # <!yatt:import> の alias Part は glob 代入として生成する。GH-256
171 # coderef コピー (\&) にするとソース再コンパイルへ追随できないので必ず glob。
172 19 ▶ sub generate_import {
Subroutine generate_import: called CC=1 SCAR=0.0
Pod undocumented
173 19 (my MY $self, my Import $import) = @_;
174 19 my Template $tmpl = $self->{_curtmpl};
175 19 my Part $src = $import->resolve_alias($self->{vfs});
176 19 my Template $srcTmpl = $src->{folder};
177 ($self->sync_curline($import->{startln})
178 , sprintf(q{*%s::%s = *%s::%s; }
179 , $tmpl->{entns}, $import->method_name
180 19 , $srcTmpl->{entns}, $src->method_name));
181 }
182  
183 #========================================
184 609 ▶ sub gen_preamble {q{ my ($this, $CON) = splice @_, 0, 2;}}
Subroutine gen_preamble: called CC=1 SCAR=0.0
Pod undocumented
185 664 ▶ sub gen_getargs {
Subroutine gen_getargs: called CC=5 SCAR=16.4
Pod undocumented
186 664 (my MY $self, my Widget $widget, my $for_decl) = @_;
187 664 my @res;
188 664 foreach my $argName (lexpand($widget->{_arg_order})) {
189 # デフォルト値と、型と。
190 1024 my $var = $widget->{_arg_dict}{$argName};
191 1024 ▶ push @res, $for_decl ? $self->sync_curline($var->lineno) : ()
Branch: 1 branch
BranchTrueFalseTotal
$for_decl ? : 814 210 1024
192 , sprintf q{ my %s = %s;}, $self->as_lvalue($var)
193 , $self->as_getarg($var);
194 # shift しない方が、debug 時に stack trace に引数値が見えて嬉しい。
195 }
196 # <!yatt:widget ...> 末尾の改行
197 664 ▶ push @res, "\n" and $self->{_curline}++ if $for_decl;
Branch: 1 branch
BranchTrueFalseTotal
if $for_decl 434 230 664
Condition50%3/6
$for_decl && (push(@res, "\n") && ++$self->{'_curline'})
!ll
2304340
push @res, "\n" and ++$self->{"_curline"}
!ll
04340
MC/DC0%0/3
$for_decl && (push(@res, "\n") && ++$self->{'_curline'})
$for_decl push @res, "\n" ++$self->{"_curline"}
Truth table0%0/4
A && B and C
A= $for_declB= push @res, "\n"C= ++$self->{"_curline"}
ABCresult
0XX0
10X0
1100
1111
198 (@res, $self->sync_curline($widget->{bodyln})
199 664 , $self->cut_next_nl);
200 }
201 1024 ▶ sub as_getarg {
Subroutine as_getarg: called CC=7 SCAR=19.6
Pod undocumented
202 1024 (my MY $self, my $var) = @_;
203 1024 my $actual = '$_['.$var->argno.']';
204 1024 ▶ return $actual unless defined (my $default = $var->default)
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $default = $var->default) and defined(my $mode = $var->dflag) 972 52 1024
Condition66%2/3
defined(my $default = $var->default) and defined(my $mode = $var->dflag)
!ll&&!rl&&r
972052
MC/DC50%1/2
defined(my $default = $var->default) and defined(my $mode = $var->dflag)
defined(my $default = $var->default) defined(my $mode = $var->dflag)
Truth table66%2/3
A and B
A= defined(my $default = $var->default)B= defined(my $mode = $var->dflag)
ABresult
0X0
100
111
205 and defined (my $mode = $var->dflag);
206 52 my $varname = $self->as_lvalue($var);
207 52 ▶ if ($mode eq "!") {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "!") 7 45 52
208 7 return qq{defined $actual ? $actual : }
209 7 . qq{die q|Argument '@{[$var->varname]}' is undef!|};
210 }
211 # XXX: do given/when は値を返さないから、ここでは使えない! void context 扱いになっちまう。
212 45 my ($cond) = do {
213 45 ▶ if ($mode eq "|") {
Branch: 3 branches
BranchTrueFalseTotal
if ($mode eq '|') { } 2 43 45
elsif ($mode eq '?') { } 40 3 43
elsif ($mode eq '/') { } 3 0 3
214 2 qq{$actual}
215 } elsif ($mode eq "?") {
216 40 qq{defined $actual && $actual ne ""}
217 } elsif ($mode eq "/") {
218 3 qq{defined $actual}
219 } else {
220 0 die "Unknown defaulting mode: $mode"
221 }
222 };
223 45 sprintf q{(%s ? %s : %s)}, $cond, $actual
224 , $self->as_cast_to($var, $default);
225 # XXX: html 型変数へ text 型変数の混じったデフォルト値を入れるときには、 as_text じゃだめ
226 # as_text に、やはり escape flag を渡せるようにするのが筋か?
227 }
228 #========================================
229 46 our @DISPATCH;
230 46 $DISPATCH[TYPE_LINEINFO] = \&from_lineinfo;
231 46 $DISPATCH[TYPE_COMMENT] = \&from_comment;
232 46 $DISPATCH[TYPE_LCMSG] = \&from_lcmsg;
233 46 $DISPATCH[TYPE_ENTITY] = \&from_entity;
234 46 $DISPATCH[TYPE_PI] = \&from_pi;
235 46 $DISPATCH[TYPE_ELEMENT] = \&from_element;
236 46 $DISPATCH[TYPE_ATT_NESTED] = \&from_elematt;
237 685 ▶ sub as_print {
Subroutine as_print: called CC=21 SCAR=30.6
Pod undocumented
238 685 (my MY $self, my ($last, $localtoks)) = @_;
239 685 ▶ push @{$self->{_curtoks}}, @$localtoks if $localtoks;
Branch: 1 branch
BranchTrueFalseTotal
if $localtoks 0 685 685
240 685 local $self->{_needs_escaping} = 1;
241 685 my (@result, @queue) = '';
242 # curline は queue 詰めの外側で操作する。
243 # $last は一回だけ出力するように、undef が必要。
244 1930 ▶ my $flush = sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
245 1930 my ($has_nl, $task, $pad) = @_;
246 1930 ▶ push @result, $pad if defined $pad;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pad 362 1568 1930
247 1930 ▶ push @result, q{print $CON (}.join(", ", @queue).");" if @queue;
Branch: 1 branch
BranchTrueFalseTotal
if @queue 1026 904 1930
248 # もう token が残っていなくて、かつ $last が与えられていたら、 $last を足す。
249 1930 ▶ push @result, $task->() if $task;
Branch: 1 branch
BranchTrueFalseTotal
if $task 359 1571 1930
250 1930 ▶ $result[-1] .= $last and undef $last if $last and not @{$self->{_curtoks}};
Branch: 1 branch
BranchTrueFalseTotal
if $last and not @{$self->{"_curtoks"};} 648 1282 1930
Condition75%6/8
$last && !@{$self->{'_curtoks'};} && (($result[-1] .= $last) && undef $last)
!ll
12826480
$last and not @{$self->{"_curtoks"};}
!ll&&!rl&&r
570712648
$result[-1] .= $last and undef $last
!ll
0648
MC/DC0%0/3
$last && !@{$self->{'_curtoks'};} && (($result[-1] .= $last) && undef $last)
$last not @{$self->{"_curtoks"};} $result[-1] .= $last
Truth table50%2/4
A and not(B) && C
A= $lastB= not @{$self->{"_curtoks"};}C= $result[-1] .= $last
ABCresult
0XX0
10X0
1100
1111
251 # 明示 "\n" が来ていた場合は、 ";" と同時に改行する。
252 1930 ▶ $result[-1] .= "\n" if $has_nl;
Branch: 1 branch
BranchTrueFalseTotal
if $has_nl 884 1046 1930
253 1930 undef @queue;
254 685 };
255 685 ▶ while (@{$self->{_curtoks}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_curtoks"};}) 2574 648 3222
256 2574 my $node = shift @{$self->{_curtoks}};
257 2574 ▶ unless (ref $node) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node) 1621 953 2574
258 # 次が element な時は、先行する indent を捨てる
259 1621 ▶ if (@{$self->{_curtoks}} and ref $self->{_curtoks}[0]
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_curtoks"};} and ref $self->{"_curtoks"}[0] and $self->{"_curtoks"}[0][0] == 5 and $node =~ /^[\ \t]+\z/) 17 1604 1621
Condition100%9/9
@{$self->{"_curtoks"};} and ref $self->{"_curtoks"}[0] and $self->{"_curtoks"}[0][0] == 5 and $node =~ /^[\ \t]+\z/
!ll&&!rl&&r
15287617
@{$self->{"_curtoks"};} and ref $self->{"_curtoks"}[0] and $self->{"_curtoks"}[0][0] == 5
!ll&&!rl&&r
103349593
@{$self->{"_curtoks"};} and ref $self->{"_curtoks"}[0]
!ll&&!rl&&r
633400588
MC/DC100%4/4
@{$self->{"_curtoks"};} and ref $self->{"_curtoks"}[0] and $self->{"_curtoks"}[0][0] == 5 and $node =~ /^[\ \t]+\z/
@{$self->{"_curtoks"};} ref $self->{"_curtoks"}[0] $self->{"_curtoks"}[0][0] == 5 $node =~ /^[\ \t]+\z/
Truth table100%5/5
A and B and C and D
A= @{$self->{"_curtoks"};}B= ref $self->{"_curtoks"}[0]C= $self->{"_curtoks"}[0][0] == 5D= $node =~ /^[\ \t]+\z/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
260 and $self->{_curtoks}[0][0] == TYPE_ELEMENT
261 and $node =~ /^[\ \t]+\z/
262 ) {
263 17 next;
264 }
265 # text node の末尾が改行で終わっている場合、 明示的に "\n" を生成する
266 1604 my $has_nl = $node =~ s/\r?\n\Z//s;
267 1604 ▶ push @queue, qtext($node) if $node ne ''; # 削ったら空になるかも。
Branch: 1 branch
BranchTrueFalseTotal
if $node ne "" 886 718 1604
268 1604 $self->{_curline} += numLines($node);
269 1604 ▶ $self->{_curline}++ if $has_nl;
Branch: 1 branch
BranchTrueFalseTotal
if $has_nl 884 720 1604
270 push @queue, q{"\n"} if $has_nl
271 1604 ▶ and @{$self->{_curtoks}} || not $self->{_no_last_newline};
Branch: 1 branch
BranchTrueFalseTotal
if $has_nl and @{$self->{"_curtoks"};} || !$self->{"_no_last_newline"} 854 750 1604
Condition100%6/6
$has_nl and @{$self->{"_curtoks"};} || !$self->{"_no_last_newline"}
!ll&&!rl&&r
72030854
@{$self->{"_curtoks"};} or not $self->{"_no_last_newline"}
l!l&&r!l&&!r
32353130
MC/DC100%3/3
$has_nl and @{$self->{"_curtoks"};} || !$self->{"_no_last_newline"}
$has_nl @{$self->{"_curtoks"};} not $self->{"_no_last_newline"}
Truth table100%4/4
A and B or not(C)
A= $has_nlB= @{$self->{"_curtoks"};}C= not $self->{"_no_last_newline"}
ABCresult
0XX0
1000
11X1
1011
272 1604 ▶ $flush->($has_nl) if $has_nl || $node =~ /\n/;
Branch: 1 branch
BranchTrueFalseTotal
if $has_nl or $node =~ /\n/ 920 684 1604
Condition100%3/3
$has_nl or $node =~ /\n/
l!l&&r!l&&!r
88436684
MC/DC100%2/2
$has_nl or $node =~ /\n/
$has_nl $node =~ /\n/
Truth table100%3/3
A or B
A= $has_nlB= $node =~ /\n/
ABresult
1X1
011
000
273 1604 next;
274 }
275 953 ▶ my $pad = $self->sync_curline($node->[NODE_LNO]) // '';
Condition100%2/2
$self->sync_curline($node->[3]) // ""
l!l
8945
MC/DC100%1/1
$self->sync_curline($node->[3]) // ""
$self->sync_curline($node->[3])
Truth table100%2/2
A
A= $self->sync_curline($node->[3])
Aresult
11
00
276 953 ▶ my $sub = $DISPATCH[$node->[0]]
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $YATT::Lite::CGen::Perl::DISPATCH[$node->[0]] or die $self->generror("Unknown node type: %d", $node->[0]) 953 0 953
277 or die $self->generror("Unknown node type: %d", $node->[0]);
278 953 my $expr = $sub->($self, $node);
279 916 ▶ unless (defined $expr) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $expr) 0 916 916
280 0 push @result, $self->cut_next_nl;
281 0 next;
282 }
283 916 ▶ if (ref $expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $expr) { } 359 557 916
284 359 ▶ $flush->(undef, sub { ("$$expr;", $self->cut_next_nl) }, $pad);
Subroutine __ANON__: called CC=1 SCAR=0.0
285 } else {
286 557 ▶ $flush->(undef, undef, $pad) if length $pad;
Branch: 1 branch
BranchTrueFalseTotal
if length $pad 3 554 557
287 557 push @queue, $expr;
288 557 ▶ $flush->() if $expr =~ /\n/;
Branch: 1 branch
BranchTrueFalseTotal
if $expr =~ /\n/ 0 557 557
289 }
290 # Following can remove trailing newline from </yatt:foreach>,
291 # but it affects all of yatt tags.
292 # if (@{$self->{_curtoks}} and $self->{_curtoks}[0] eq "\n") {
293 # shift @{$self->{_curtoks}};
294 # }
295 }
296 648 $flush->();
297 648 join " ", @result;
298 }
299 121 ▶ sub gen_as {
Subroutine gen_as: called CC=10 SCAR=23.4
Pod undocumented
300 121 (my MY $self, my ($type, $dispatch, $escape, $text_quote))
301 = splice @_, 0, 5;
302 121 local $self->{_needs_escaping} = $escape;
303 121 my (@result);
304 # Empty expr (ie <:yatt:arg></:yatt:arg>) should generate q|| as code.
305 121 ▶ if (not @_ and $text_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @_ and $text_quote) 1 120 121
Condition66%2/3
not @_ and $text_quote
!ll&&!rl&&r
12001
MC/DC50%1/2
not @_ and $text_quote
not @_ $text_quote
Truth table66%2/3
not(A) and B
A= not @_B= $text_quote
ABresult
0X0
100
111
306 1 push @result, qtext('');
307 }
308 121 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 184 121 305
309 184 my $node = shift;
310 184 ▶ unless (ref $node) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node) 131 53 184
311 131 ▶ push @result, ($text_quote ? qtext($node) : $node);
Branch: 1 branch
BranchTrueFalseTotal
$text_quote ? : 47 84 131
312 131 $self->{_curline} += numLines($node);
313 131 next;
314 }
315 # 許されるのは entity だけでは? でもないか。 element 引数の時は、capture したいはず。
316 53 ▶ my $sub = $dispatch->[$node->[0]] or do {
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $$dispatch[$node->[0]] or do { die $self->generror("gen_as %s: Unknown node type: %d", $type, $node->[0]) } 53 0 53
317 0 die $self->generror("gen_as %s: Unknown node type: %d"
318 , $type, $node->[0]);
319 };
320 53 my $expr = $sub->($self, $node);
321 53 ▶ next unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 53 53
322 53 ▶ if (ref $expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $expr) 0 53 53
323 0 die $self->generror("Syntax error, not allowed here: %s", $$expr);
324 }
325 53 push @result, $expr;
326 }
327 121 ▶ wantarray ? @result : join("", @result);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 116 5 121
328 }
329  
330 # as_list と対になる。
331 46 our @AS_TEXT;
332 46 $AS_TEXT[TYPE_LCMSG] = \&from_lcmsg;
333 46 $AS_TEXT[TYPE_ENTITY] = \&from_entity;
334 46 $AS_TEXT[TYPE_PI] = \&text_from_pi;
335 46 $AS_TEXT[TYPE_ELEMENT] = \&text_from_element; # XXX: ?? Used??
336 0 ▶ $AS_TEXT[TYPE_ATT_NESTED] = sub {undef}; # gen_as が scalar 受けゆえ
Subroutine __ANON__: not called CC=1 SCAR=1.2
337 # as_text は、escape 不要。なぜなら、 print 時に escape されるから。
338 # でも、 escape 有無を flag で渡せた方が、 html 型にも使えて便利では?
339 # というか、 html 型には capture が必要か。 capture は buffering したいよね?
340 18 ▶ sub as_text {
Subroutine as_text: called CC=1 SCAR=0.0
Pod undocumented
341 18 join '.', shift->gen_as(text => \@AS_TEXT, 0, 1, @_);
342 }
343  
344 46 our @AS_LIST;
345 46 $AS_LIST[TYPE_ENTITY] = \&from_entity;
346 46 $AS_LIST[TYPE_PI] = \&list_from_pi;
347 46 $AS_LIST[TYPE_ELEMENT] = \&list_from_element;
348 0 ▶ $AS_LIST[TYPE_ATT_NESTED] = sub {undef}; # XXX: 微妙
Subroutine __ANON__: not called CC=1 SCAR=1.2
349 91 ▶ sub as_list {
Subroutine as_list: called CC=1 SCAR=0.0
Pod undocumented
350 91 shift->gen_as(list => \@AS_LIST, 0, 0, @_);
351 }
352 #========================================
353 325 ▶ sub from_element {
Subroutine from_element: called CC=5 SCAR=16.4
Pod undocumented
354 # XXX: macro (if, foreach, my, format) (error if は?)
355 325 (my MY $self, my $node) = @_;
356 325 my $path = $node->[NODE_PATH];
357 325 ▶ if (my $alt = $self->altgen($path->[0])) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $alt = $self->altgen($path->[0])) { } 0 325 325
elsif (@$path == 2 and my $macro = $self->can('macro_' . join('_', @$path)) || $self->can("macro_$path->[-1]")) { } 73 252 325
358 0 qtext($alt->($node));
359 ▶ } elsif (@$path == 2
Condition83%5/6
@$path == 2 and my $macro = $self->can('macro_' . join("_", @$path)) || $self->can("macro_$path->[-1]")
!ll&&!rl&&r
924373
$self->can('macro_' . join('_', @$path)) || $self->can("macro_$path->[-1]")
l!l&&r!l&&!r
073243
MC/DC66%2/3
@$path == 2 and my $macro = $self->can('macro_' . join("_", @$path)) || $self->can("macro_$path->[-1]")
@$path == 2 $self->can('macro_' . join('_', @$path)) $self->can("macro_$path->[-1]")
Truth table75%3/4
A and B || C
A= @$path == 2B= $self->can('macro_' . join('_', @$path))C= $self->can("macro_$path->[-1]")
ABCresult
0XX0
1000
11X1
1011
360 and my $macro = $self->can("macro_" . join "_", @$path)
361 || $self->can("macro_$path->[-1]")) {
362 73 $macro->($self, $node);
363 } else {
364 # stack trace に現れるように, 敢えて展開。
365 252 $self->gen_call($node, @{$node->[NODE_PATH]});
366 }
367 }
368 1 ▶ sub text_from_element {
Subroutine text_from_element: called CC=1 SCAR=0.0
Pod undocumented
369 1 (my MY $self, my $node) = @_;
370 1 my $call_ref = $self->from_element($node);
371 1 sprintf q{(YATT::Lite::Util::captured {my ($CON) = @_; %s})}, $$call_ref;
372 }
373 0 ▶ sub text_from_pi {
Subroutine text_from_pi: not called CC=1 SCAR=6.9
Pod undocumented
374 0 (my MY $self, my $node) = @_;
375 0 my $statements = $self->from_pi($node);
376 0 sprintf q{(YATT::Lite::Util::captured {my ($CON) = @_; %s})}, $statements;
377 }
378  
379 257 ▶ sub gen_call {
Subroutine gen_call: called CC=7 SCAR=19.5
Pod undocumented
380 257 (my MY $self, my ($node, @path)) = @_;
381 257 ▶ if (my ($kw, $condNode, $stripped) = $self->cut_conditional_arg($node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $self->cut_conditional_arg($node)) 5 250 255
382 # Generate the condition before the call, like macro_if does.
383 5 my $cond = join "", $self->as_list(lexpand(argValue($condNode)));
384 5 my $call = $self->gen_call($stripped, @path);
385 5 return \ sprintf(q{%s %s (%s)}, $$call, $kw, $cond);
386 }
387 250 my $wname = join ":", @path;
388 250 ▶ if (@path == 2 and my $var = $self->find_callable_var($path[-1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path == 2 and my $var = $self->find_callable_var($path[-1])) 28 222 250
Condition100%3/3
@path == 2 and my $var = $self->find_callable_var($path[-1])
!ll&&!rl&&r
921328
MC/DC100%2/2
@path == 2 and my $var = $self->find_callable_var($path[-1])
@path == 2 my $var = $self->find_callable_var($path[-1])
Truth table100%3/3
A and B
A= @path == 2B= my $var = $self->find_callable_var($path[-1])
ABresult
0X0
100
111
389 # code 引数の中の引数のデフォルト値の中に、改行が有ったら??
390 # XXX: body の引数宣言が無い場合に <yatt:body/> は、ちゃんと呼び出せるか?
391 28 return $self->can("as_varcall_" . $var->type->[0])
392 ->($self, $var, $node);
393 }
394  
395 222 ▶ my Widget $widget = $self->lookup_widget(@path) or do {
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::Core::Widget $widget = $self->lookup_widget(@path) or do { my $err = $self->generror("No such widget <%s>", $wname); die $err } 212 10 222
396 10 my $err = $self->generror(q{No such widget <%s>}, $wname);
397 2 die $err;
398 };
399  
400 212 $self->ensure_generated(perl => my Template $tmpl = $widget->{folder});
401 212 my $use_this = $tmpl == $self->{_curtmpl};
402 212 ▶ unless ($use_this) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($use_this) 52 160 212
403 52 $self->{_curtmpl}->add_dependency($wname, $tmpl);
404 }
405 212 ▶ my $that = $use_this ? '$this' : $tmpl->{entns};
Branch: 1 branch
BranchTrueFalseTotal
$use_this ? : 160 52 212
406 \ sprintf(q{%s->render_%s($CON, %s)}
407 , $that, $widget->{name}
408 212 , $self->gen_putargs($widget, $node)
409 );
410 }
411 # `<yatt:foo if="COND">` (or unless=) makes the call conditional,
412 # like Perl's postfix if/unless. Note this always wins over formal args
413 # named if/unless, as in original yatt (yatt-pm).
414 257 ▶ sub cut_conditional_arg {
Subroutine cut_conditional_arg: called CC=12 SCAR=24.9
Pod undocumented
415 257 (my MY $self, my $node) = @_;
416 257 ▶ return if $self->{no_conditional_call};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"no_conditional_call"} 2 255 257
417 255 my $attlist = $node->[NODE_ATTLIST];
418 255 ▶ return unless $attlist and ref $attlist eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless $attlist and ref $attlist eq "ARRAY" 151 104 255
Condition66%2/3
$attlist and ref $attlist eq "ARRAY"
!ll&&!rl&&r
1510104
MC/DC50%1/2
$attlist and ref $attlist eq "ARRAY"
$attlist ref $attlist eq "ARRAY"
Truth table66%2/3
A and B
A= $attlistB= ref $attlist eq "ARRAY"
ABresult
0X0
100
111
419 104 my ($kw, $condNode, @rest);
420 104 foreach my $arg (@$attlist) {
421 149 my $name = $arg->[NODE_PATH];
422 149 ▶ if (defined $name and not ref $name
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and not ref $name and $name eq 'if' || $name eq 'unless') { } 8 141 149
Condition88%8/9
defined $name and not ref $name and $name eq "if" || $name eq "unless"
!ll&&!rl&&r
121298
defined $name and not ref $name
!ll&&!rl&&r
120137
$name eq "if" or $name eq "unless"
l!l&&r!l&&!r
62129
MC/DC75%3/4
defined $name and not ref $name and $name eq "if" || $name eq "unless"
defined $name not ref $name $name eq "if" $name eq "unless"
Truth table80%4/5
A and not(B) and C or D
A= defined $nameB= not ref $nameC= $name eq "if"D= $name eq "unless"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
423 and ($name eq 'if' or $name eq 'unless')) {
424 8 ▶ if ($condNode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($condNode) 1 7 8
425 1 die $self->generror(q{Too many conditions in one call: %s and %s}
426 , $kw, $name);
427 }
428 7 ▶ defined argValue($arg)
Branch: 1 branch
BranchTrueFalseTotal
defined argValue($arg) or die $self->generror("Condition '%s' requires a value", $name) 6 1 7
429 or die $self->generror(q{Condition '%s' requires a value}, $name);
430 6 ($kw, $condNode) = ($name, $arg);
431 } else {
432 141 push @rest, $arg;
433 }
434 }
435 102 ▶ return unless $condNode;
Branch: 1 branch
BranchTrueFalseTotal
unless $condNode 97 5 102
436 5 my $stripped = [@$node];
437 5 $stripped->[NODE_ATTLIST] = \@rest;
438 5 ($kw, $condNode, $stripped);
439 }
440  
441 240 ▶ sub gen_putargs {
Subroutine gen_putargs: called CC=24 SCAR=31.8
Pod undocumented
442 240 (my MY $self, my Widget $widget, my $node, my $delegate_vars) = @_;
443 240 my ($path, $body, $primary, $head, $foot) = nx($node);
444 return '' if not $delegate_vars and not $widget->{_has_required_arg}
445 240 ▶ and not $primary and not $body;
Branch: 1 branch
BranchTrueFalseTotal
unless $delegate_vars or $widget->{"_has_required_arg"} or $primary or $body 118 122 240
Condition100%9/9
$delegate_vars or $widget->{"_has_required_arg"} or $primary or $body
l!l&&r!l&&!r
10220118
$delegate_vars or $widget->{"_has_required_arg"} or $primary
l!l&&r!l&&!r
795138
$delegate_vars or $widget->{"_has_required_arg"}
l!l&&r!l&&!r
43233
MC/DC100%4/4
$delegate_vars or $widget->{"_has_required_arg"} or $primary or $body
$delegate_vars $widget->{"_has_required_arg"} $primary $body
Truth table100%5/5
A or B or C or D
A= $delegate_varsB= $widget->{"_has_required_arg"}C= $primaryD= $body
ABCDresult
1XXX1
01XX1
001X1
00011
00000
446  
447 122 ▶ if ($widget->{_argmacro_instance_list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($widget->{"_argmacro_instance_list"}) 10 112 122
448 $primary = YATT::Lite::CGen::ArgMacro->expand_all_argmacro(
449 $self,
450 $primary,
451 $widget->{_argmacro_trigger_dict},
452 $widget->{_argmacro_instance_list},
453 $widget->{_argmacro_instance_dict},
454 10 );
455 }
456  
457 122 my $wname = join ":", @$path;
458 122 my ($posArgs, $actualNo, @argOrder);
459 197 ▶ my $add_arg = sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
460 197 my ($name) = @_;
461 197 ▶ my $formal = $widget->{_arg_dict}{$name} or do {
Branch: 1 branch
BranchTrueFalseTotal
my $formal = $widget->{"_arg_dict"}{$name} or do { die $self->generror("Unknown arg '%s' in widget <%s>", $name, $wname) } 194 3 197
462 3 die $self->generror(q{Unknown arg '%s' in widget <%s>}, $name, $wname);
463 };
464 194 ▶ if (defined $argOrder[my $argno = $formal->argno]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argOrder[my $argno = $formal->argno]) { } 0 194 194
465 0 die $self->generror(q{Duplicate arg '%s'}, $name);
466 } else {
467 194 $argOrder[$argno] = ++$actualNo;
468 }
469 194 $formal;
470 122 };
471 # primary 引数
472 my @argExpr = map {
473 122 $self->sync_curline($_->[NODE_LNO]), ", ", $self->add_curline(do {
474 147 my $name = argName($_);
475 147 ▶ unless (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 10 137 147
476 10 ▶ defined($name = $widget->{_arg_order}[$posArgs //= 0])
Branch: 1 branch
BranchTrueFalseTotal
defined($name = $widget->{"_arg_order"}[$posArgs //= 0]) or die $self->generror("Too many arguments for widget <%s>") 10 0 10
Condition100%2/2
$posArgs //= 0
l!l
28
MC/DC100%1/1
$posArgs //= 0
$posArgs
Truth table100%2/2
A
A= $posArgs
Aresult
11
00
477 or die $self->generror("Too many arguments for widget <%s>"); # This may not be called.
478  
479 # Positional arguments should not be treated as body argument.
480 10 ▶ if ($widget->{_arg_dict}{$name}->is_body_argument) {
Branch: 1 branch
BranchTrueFalseTotal
if ($widget->{"_arg_dict"}{$name}->is_body_argument) 1 9 10
481 die $self->generror(
482 "Too many arguments for widget <%s>: %s", $wname
483 1 , $self->{_curtmpl}->source_region($primary->[$posArgs][NODE_BEGIN],
484 $primary->[$#$primary][NODE_END])
485 );
486 }
487  
488 9 $posArgs++;
489 }
490  
491 146 my $formal = $add_arg->($name);
492 143 ▶ unless (my $passThruVar = passThruVar($_)) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $passThruVar = passThruVar($_)) { } 45 98 143
if (do { my $actual = $self->find_var($passThruVar) }) { } 38 7 45
elsif (not defined argValue($_) and defined(my $v = $formal->flag)) { } 4 3 7
493 98 $self->as_cast_to($formal, argValue($_));
494 } elsif (my $actual = $self->find_var($passThruVar)) {
495 38 ▶ if ($formal->already_escaped and not $actual->already_escaped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($formal->already_escaped and not $actual->already_escaped) { } 2 36 38
Condition100%3/3
$formal->already_escaped and not $actual->already_escaped
!ll&&!rl&&r
3512
MC/DC100%2/2
$formal->already_escaped and not $actual->already_escaped
$formal->already_escaped not $actual->already_escaped
Truth table100%3/3
A and not(B)
A= $formal->already_escapedB= not $actual->already_escaped
ABresult
0X0
100
111
496 # 受け手が escape 済みを期待しているのに、送り手がまだ escape されてないケース
497 2 $self->as_escaped($actual);
498 } else {
499 36 $self->as_lvalue($actual);
500 }
501 ▶ } elsif (not defined argValue($_) and defined(my $v = $formal->flag)) {
Condition66%2/3
not defined argValue($_) and defined(my $v = $formal->flag)
!ll&&!rl&&r
034
MC/DC50%1/2
not defined argValue($_) and defined(my $v = $formal->flag)
not defined argValue($_) defined(my $v = $formal->flag)
Truth table66%2/3
not(A) and B
A= not defined argValue($_)B= defined(my $v = $formal->flag)
ABresult
0X0
100
111
502 # フラグ立てとして扱って良い型の場合。
503 4 $v;
504 } else {
505 3 die $self->generror(q{argument '%s' requires value expression like '=...'}, $passThruVar);
506 }
507 });
508 } @$primary;
509  
510 # element 引数
511 114 ▶ foreach my $arg (lexpand($head), $body ? $body : (), lexpand($foot)) {
Branch: 1 branch
BranchTrueFalseTotal
$body ? : 34 80 114
512 51 my ($name, $expr) = @$arg[NODE_PATH, NODE_VALUE];
513 51 ▶ my $formal = $add_arg->(ref $name ? $name->[-1] : $name);
Branch: 1 branch
BranchTrueFalseTotal
ref $name ? : 17 34 51
514 51 push @argExpr, ", ", $self->as_cast_to($formal, $expr);
515 }
516  
517 # delegate の補間と、必須引数検査
518 112 foreach my $i (0 .. $#{$widget->{_arg_order}}) {
519 308 ▶ next if defined $argOrder[$i];
Branch: 1 branch
BranchTrueFalseTotal
if defined $argOrder[$i] 187 121 308
520 121 my $argName = $widget->{_arg_order}[$i];
521 121 ▶ if (my $inherit = $delegate_vars->{$argName}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $inherit = $delegate_vars->{$argName}) { } 8 113 121
elsif ($widget->{'_arg_dict'}{$argName}->is_required) { } 1 112 113
522 8 push @argExpr, ', '. $self->as_lvalue($inherit);
523 8 $argOrder[$inherit->argno] = ++$actualNo;
524 } elsif ($widget->{_arg_dict}{$argName}->is_required) {
525 1 die $self->generror("Argument '%s' is missing", $argName);
526 }
527 }
528 sprintf q{(undef%s)[%s]}
529 307 ▶ , join("", @argExpr), join(", ", map {defined $_ ? $_ : 0}
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 195 112 307
530 111 @argOrder[0 .. $#{$widget->{_arg_order}}]);
531 }
532 1502 ▶ sub as_lvalue {
Subroutine as_lvalue: called CC=3 SCAR=11.2
Pod undocumented
533 1502 (my MY $self, my $var) = @_;
534 1502 my $type = $var->type;
535 1502 ▶ unless (defined $type) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $type) { } 1502 0 1502
if (do { my $sub = $self->can('as_lvalue_' . $type->[0]) }) { } 48 1454 1502
536 0 die $self->generror("undefined var type");
537 } elsif (my $sub = $self->can("as_lvalue_" . $type->[0])) {
538 48 $sub->($self, $var);
539 } else {
540 1454 "\$".$var->varname;
541 }
542 }
543 71 ▶ sub as_lvalue_html {
Subroutine as_lvalue_html: called CC=1 SCAR=0.0
Pod undocumented
544 71 (my MY $self, my $var) = @_;
545 71 '$html_'.$var->varname;
546 }
547 24 ▶ sub as_varcall_code {
Subroutine as_varcall_code: called CC=1 SCAR=0.0
Pod undocumented
548 24 (my MY $self, my ($codeVar, $node)) = @_;
549 24 return \ sprintf q{$%1$s && $%1$s->(%2$s)}, $codeVar->varname
550 , $self->gen_putargs($codeVar->widget, $node);
551 # XXX: デフォルト body のように、引数宣言が無いケースも考慮せよ。
552 }
553 4 ▶ sub as_varcall_delegate {
Subroutine as_varcall_delegate: called CC=3 SCAR=11.6
Pod undocumented
554 4 (my MY $self, my ($var, $node)) = @_;
555 4 my Widget $delegate = $var->widget;
556 4 ▶ unless (defined $delegate) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $delegate) 0 4 4
557 0 Carp::croak "delegate target widget is empty!";
558 }
559 4 $self->ensure_generated(perl => my Template $tmpl = $delegate->{folder});
560 4 ▶ my $that = $tmpl == $self->{_curtmpl} ? '$this' : $tmpl->{entns};
Branch: 1 branch
BranchTrueFalseTotal
$tmpl == $self->{'_curtmpl'} ? : 4 0 4
561 \ sprintf(q{%s->render_%s($CON, %s)}
562 , $that, $delegate->{name}
563 4 , $self->gen_putargs($delegate, $node, $var->delegate_vars));
564 }
565 6 ▶ sub as_escaped {
Subroutine as_escaped: called CC=2 SCAR=7.6
Pod undocumented
566 6 (my MY $self, my $var) = @_;
567 6 ▶ if (my $sub = $self->can("as_escaped_" . $var->type->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can('as_escaped_' . $var->type->[0])) { } 0 6 6
568 0 $sub->($self, $var);
569 } else {
570 6 'YATT::Lite::Util::escape($'.$var->varname.')';
571 }
572 }
573  
574 #========================================
575 232 ▶ sub as_cast_to {
Subroutine as_cast_to: called CC=2 SCAR=7.0
Pod undocumented
576 232 (my MY $self, my $var, my $value) = @_;
577 232 my $type = $var->type->[0];
578 232 ▶ my $sub = $self->can("as_cast_to_$type")
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $self->can("as_cast_to_$type") or die $self->generror("Can't cast to type: %s", $type) 232 0 232
579 or die $self->generror(q{Can't cast to type: %s}, $type);
580 232 $sub->($self, $var, $value);
581 }
582 138 ▶ sub as_cast_to_text {
Subroutine as_cast_to_text: called CC=2 SCAR=6.9
Pod undocumented
583 138 (my MY $self, my ($var, $value)) = @_;
584 138 ▶ return qtext($value) unless ref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value 120 18 138
585 18 $self->as_text(@$value);
586 }
587 2 ▶ sub as_cast_to_attr {
Subroutine as_cast_to_attr: called CC=1 SCAR=0.0
Pod undocumented
588 2 shift->as_cast_to_text(@_);
589 }
590 33 ▶ sub as_cast_to_html {
Subroutine as_cast_to_html: called CC=2 SCAR=6.9
Pod undocumented
591 33 (my MY $self, my ($var, $value)) = @_;
592 33 ▶ unless (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value) 21 12 33
593 21 $self->{_curline} += numLines($value);
594 21 return qtext($value);
595 }
596 12 join '.', shift->gen_as(text => \@AS_TEXT, 1, 1, @$value);
597 }
598 14 ▶ sub as_cast_to_scalar {
Subroutine as_cast_to_scalar: called CC=2 SCAR=6.9
Pod undocumented
599 14 (my MY $self, my ($var, $value)) = @_;
600 14 ▶ 'scalar(do {'.(ref $value ? $self->as_list(@$value) : $value).'})';
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 3 11 14
601 }
602 1 ▶ sub as_cast_to_bool {
Subroutine as_cast_to_bool: called CC=1 SCAR=0.0
Pod undocumented
603 1 shift->as_cast_to_scalar(@_);
604 }
605 6 ▶ sub as_cast_to_list {
Subroutine as_cast_to_list: called CC=2 SCAR=6.9
Pod undocumented
606 6 (my MY $self, my ($var, $value)) = @_;
607 6 ▶ '['.(ref $value ? $self->as_list(@$value) : $value).']';
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 1 5 6
608 }
609 41 ▶ sub as_cast_to_code {
Subroutine as_cast_to_code: called CC=3 SCAR=11.0
Pod undocumented
610 41 (my MY $self, my ($var, $value)) = @_;
611 41 ▶ unless (ref $value eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value eq "ARRAY") 1 40 41
612 1 die $self->generror(q{Invalid text expression for variable '%s': %s}, $var->varname, $value);
613 }
614 40 local $self->{_curtoks} = [@$value];
615 40 my Widget $virtual = $var->widget;
616 local $self->{_scope} = $self->mkscope
617 40 ▶ ({}, $virtual->{_arg_dict} ||= {}, $self->{_scope});
Condition100%2/2
$virtual->{"_arg_dict"} ||= {}
l!l
931
MC/DC100%1/1
$virtual->{"_arg_dict"} ||= {}
$virtual->{"_arg_dict"}
Truth table100%2/2
A
A= $virtual->{"_arg_dict"}
Aresult
11
00
618 40 local $self->{_no_last_newline} = 1;
619 40 q|sub {|. join('', $self->gen_getargs($virtual)
620 , $self->as_print("}"));
621 }
622 #----------------------------------------
623 254 ▶ sub argName {
Subroutine argName: called CC=5 SCAR=16.2
Pod undocumented
624 254 my ($arg, $skip) = @_;
625 254 my $name = $$arg[NODE_PATH];
626 254 ▶ if (array_of_array($name)) {
Branch: 3 branches
BranchTrueFalseTotal
if (array_of_array($name)) { } 0 254 254
elsif (not wantarray && ref $name) { } 240 14 254
elsif (defined $skip) { } 2 12 14
627 0 Carp::croak("namelist is given for argName()!");
628 ▶ } elsif (not (wantarray and ref $name)) {
Condition100%3/3
wantarray && ref $name
!ll&&!rl&&r
1637714
MC/DC100%2/2
wantarray && ref $name
wantarray ref $name
Truth table100%3/3
A && B
A= wantarrayB= ref $name
ABresult
0X0
100
111
629 240 $name;
630 } elsif (defined $skip) {
631 2 @{$name}[$skip .. $#$name];
632 } else {
633 12 @$name;
634 }
635 }
636 180 ▶ sub argValue { my $arg = shift; $$arg[NODE_VALUE] }
Subroutine argValue: called CC=1 SCAR=0.0
Pod undocumented
637 158 ▶ sub passThruVar {
Subroutine passThruVar: called CC=3 SCAR=11.0
Pod undocumented
638 158 my $arg = shift;
639 158 ▶ if ($arg->[NODE_TYPE] == TYPE_ATT_NAMEONLY) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arg->[0] == 6) { } 44 114 158
elsif ($arg->[0] == 7) { } 15 99 114
640 44 $$arg[NODE_PATH]
641 } elsif ($arg->[NODE_TYPE] == TYPE_ATT_BARENAME) {
642 15 $$arg[NODE_VALUE]
643 }
644 }
645 #========================================
646 60 ▶ sub from_pi {
Subroutine from_pi: called CC=6 SCAR=18.0
Pod undocumented
647 60 (my MY $self, my $node) = @_;
648 # pi の ns 毎の役割を拡張可能に
649 60 ▶ if (my $sub = $self->can("pi_of_" . $node->[NODE_PATH][0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can('pi_of_' . $node->[7][0])) 0 60 60
650 0 return $sub->($self, $node);
651 }
652 60 $self->sync_curline($node->[NODE_LNO]);
653 60 my @body = nx($node, 1);
654 60 my ($fmt, $is_statement) = do {
655 60 ▶ unless ($body[0] =~ s/^=+//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($body[0] =~ s/^=+//) { } 20 40 60
if (do { length $& >= 3 }) { } 6 14 20
656 40 (q{%s}, 1);
657 } elsif (length $& >= 3) {
658 6 q{do {%s}};
659 } else {
660 14 q{YATT::Lite::Util::escape(do {%s})};
661 }
662 };
663 60 my $expr = join '', $self->as_list(@body);
664 60 ▶ return \ "" unless $expr =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $expr =~ /\S/ 1 59 60
665 59 my $script = sprintf $fmt, $expr;
666 59 ▶ $is_statement ? \ $script : $script;
Branch: 1 branch
BranchTrueFalseTotal
$is_statement ? : 39 20 59
667 }
668 #========================================
669 0 ▶ sub from_lineinfo { }
Subroutine from_lineinfo: not called CC=1 SCAR=0.0
Pod undocumented
670 8 ▶ sub from_comment {
Subroutine from_comment: called CC=1 SCAR=0.0
Pod undocumented
671 8 (my MY $self, my $node) = @_;
672 8 (undef, my ($nlines, $body)) = nx($node); # XXX: ok?
673 8 $self->{_curline} += $nlines;
674 8 return \ ("\n" x $nlines);
675 }
676 3 ▶ sub from_lcmsg {
Subroutine from_lcmsg: called CC=5 SCAR=16.2
Pod undocumented
677 3 (my MY $self, my $node) = @_;
678 3 my ($path, $body) = nx($node);
679 # $body is list of tokenlist.
680 3 my $place = $self->{_curtmpl}->fake_filename . ":" . $node->[NODE_LNO];
681  
682 # XXX: builtin xgettext
683 3 ▶ if (@$body >= 2 or @$path >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$body >= 2 or @$path >= 2) { } 1 2 3
Condition66%2/3
@$body >= 2 or @$path >= 2
l!l&&r!l&&!r
102
MC/DC50%1/2
@$body >= 2 or @$path >= 2
@$body >= 2 @$path >= 2
Truth table66%2/3
A or B
A= @$body >= 2B= @$path >= 2
ABresult
1X1
011
000
684 # ngettext
685 1 my ($uniq, $args, $numexpr) = ({}, []);
686 my ($msgid, @plural) = map {
687 1 scalar $self->gen_lcmsg($node, $_, $uniq, $args, \$numexpr);
688 } @$body;
689 1 ▶ if (my $sub = $self->{lcmsg_sink}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->{"lcmsg_sink"}) 1 0 1
690 1 $sub->($place, $msgid, \@plural, $args);
691 }
692 sprintf q{sprintf($CON->ngettext(%s, %s), %s)}
693 1 , join(", ", map {qtext($_)} ($msgid, @plural))
694 , $numexpr, join(", ", @$args);
695 } else {
696 2 my ($msgid, @args) = $self->gen_lcmsg($node, $body->[0]);
697 2 ▶ if (my $sub = $self->{lcmsg_sink}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->{"lcmsg_sink"}) 2 0 2
698 2 $sub->($place, $msgid, undef, \@args);
699 }
700 2 sprintf q{sprintf($CON->gettext(%s), %s)}
701 , qtext($msgid), join(", ", @args);
702 }
703 }
704 4 ▶ sub gen_lcmsg {
Subroutine gen_lcmsg: called CC=20 SCAR=32.9
Pod undocumented
705 4 (my MY $self, my ($node, $list, $uniq, $args, $ref_numeric)) = @_;
706 4 my ($msgid, $vspec) = ("");
707 4 ▶ if (@$list >= 2 and not ref $list->[0] and not ref $list->[-1]
Branch: 1 branch
BranchTrueFalseTotal
if (@$list >= 2 and not ref $list->[0] and not ref $list->[-1] and $list->[0] =~ /^\n+$/ and $list->[-1] =~ /^\n+$/) 2 2 4
Condition50%6/12
@$list >= 2 and not ref $list->[0] and not ref $list->[-1] and $list->[0] =~ /^\n+$/ and $list->[-1] =~ /^\n+$/
!ll&&!rl&&r
202
@$list >= 2 and not ref $list->[0] and not ref $list->[-1] and $list->[0] =~ /^\n+$/
!ll&&!rl&&r
022
@$list >= 2 and not ref $list->[0] and not ref $list->[-1]
!ll&&!rl&&r
004
@$list >= 2 and not ref $list->[0]
!ll&&!rl&&r
004
MC/DC20%1/5
@$list >= 2 and not ref $list->[0] and not ref $list->[-1] and $list->[0] =~ /^\n+$/ and $list->[-1] =~ /^\n+$/
@$list >= 2 not ref $list->[0] not ref $list->[-1] $list->[0] =~ /^\n+$/ $list->[-1] =~ /^\n+$/
Truth table33%2/6
A and not(B) and not(C) and D and E
A= @$list >= 2B= not ref $list->[0]C= not ref $list->[-1]D= $list->[0] =~ /^\n+$/E= $list->[-1] =~ /^\n+$/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
708 and $list->[0] =~ /^\n+$/ and $list->[-1] =~ /^\n+$/) {
709 2 shift @$list; pop @$list;
710 2 ▶ if (@$list and not ref $list->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$list and not ref $list->[0]) 2 0 2
Condition33%1/3
@$list and not ref $list->[0]
!ll&&!rl&&r
002
MC/DC0%0/2
@$list and not ref $list->[0]
@$list not ref $list->[0]
Truth table33%1/3
A and not(B)
A= @$listB= not ref $list->[0]
ABresult
0X0
100
111
711 2 $list->[0] =~ s/^\s+//;
712 }
713 }
714 4 foreach my $item (@$list) {
715 12 ▶ unless (ref $item) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $item) { } 5 7 12
if (do { $item->[0] != 3 }) { } 0 5 5
elsif (ref($vspec = $item->[8]) ne 'ARRAY' or $vspec->[0] ne 'var') { } 0 5 5
716 # XXX: How about backslash?
717 7 (my $cp = $item) =~ s/%/%%/g;
718 7 $msgid .= $cp;
719 } elsif ($item->[NODE_TYPE] != TYPE_ENTITY) {
720 0 die "SYNERR";
721 ▶ } elsif (ref ($vspec = $item->[NODE_BODY]) ne 'ARRAY'
Condition33%1/3
ref($vspec = $item->[8]) ne "ARRAY" or $vspec->[0] ne "var"
l!l&&r!l&&!r
005
MC/DC0%0/2
ref($vspec = $item->[8]) ne "ARRAY" or $vspec->[0] ne "var"
ref($vspec = $item->[8]) ne "ARRAY" $vspec->[0] ne "var"
Truth table33%1/3
A or B
A= ref($vspec = $item->[8]) ne "ARRAY"B= $vspec->[0] ne "var"
ABresult
1X1
011
000
722 || $vspec->[0] ne 'var') {
723 # || @$vspec != 2
724 0 die "SYNERR";
725 } else {
726 5 my $name = $vspec->[1];
727 5 ▶ my $var = $self->find_var($name)
Branch: 1 branch
BranchTrueFalseTotal
my $var = $self->find_var($name) or die $self->generror("No such variable '%s'", $name) 5 0 5
728 or die $self->generror(q{No such variable '%s'}, $name);
729 5 ▶ unless ($uniq->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($uniq->{$name}) 4 1 5
730 4 push @$args, $self->as_escaped($var);
731 4 $uniq->{$name} = 1 + keys %$uniq;
732 }
733 5 ▶ my $argno = $ref_numeric ? $uniq->{$name} . "\$" : '';
Branch: 1 branch
BranchTrueFalseTotal
$ref_numeric ? : 3 2 5
734 # XXX: type==value is alias of scalar.
735 5 ▶ if ($ref_numeric and $var->type->[0] eq 'scalar') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_numeric and $var->type->[0] eq 'scalar') { } 1 4 5
Condition100%3/3
$ref_numeric and $var->type->[0] eq "scalar"
!ll&&!rl&&r
221
MC/DC100%2/2
$ref_numeric and $var->type->[0] eq "scalar"
$ref_numeric $var->type->[0] eq "scalar"
Truth table100%3/3
A and B
A= $ref_numericB= $var->type->[0] eq "scalar"
ABresult
0X0
100
111
736 1 $msgid .= "%${argno}d"; # XXX: format selection... but how? from entity?
737 1 ▶ if ($$ref_numeric) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$ref_numeric) 0 1 1
738 0 die "SYNERR";
739 }
740 1 $$ref_numeric = $self->as_lvalue($var);
741 } else {
742 4 $msgid .= "%${argno}s";
743 }
744 }
745 }
746 4 $msgid =~ s/\r//g;
747 # XXX: Unfortunately, this is not good for multiline message.
748 4 ▶ wantarray ? ($msgid, lexpand($args)) : $msgid;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 2 4
749 }
750  
751 0 ▶ sub from_elematt {
Subroutine from_elematt: not called CC=1 SCAR=6.9
Pod undocumented
752 0 (my MY $self, my $node) = @_;
753 # <:yatt:elematt>....</:yatt:elematt> は NOP へ。
754 0 return \ "";
755 }
756 610 ▶ sub from_entity {
Subroutine from_entity: called CC=1 SCAR=0.0
Pod undocumented
757 610 (my MY $self, my $node) = @_;
758 610 (undef, my @pipe) = nx($node);
759 # XXX: expand のように全体に作用するものも有るから、これも現在の式を渡す方式にすべき。
760 # 受け手が有るかどうかで式の生成方式も変わる?なら token リスト削りが良いか。
761 610 $self->gen_entpath($self->{_needs_escaping}, @pipe);
762 }
763  
764 # XXX: lxnest を caller が呼ぶ必要が有る...が、それって良いことなのか...
765 1218 ▶ sub gen_entpath {
Subroutine gen_entpath: called CC=12 SCAR=25.2
Pod undocumented
766 1218 (my MY $self, my ($escape_now)) = splice @_, 0, 2;
767 1218 ▶ return '' unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1218 1218
768 1218 local $self->{_needs_escaping} = 0;
769 1218 ▶ if (@_ == 1 and ($_[0][0] eq 'call'
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and $_[0][0] eq "call" || $_[0][0] eq "var" && $self->{"prefer_call_for_entity"} and my $macro = $self->can("entmacro_$_[0][1]")) 111 1107 1218
Condition83%10/12
@_ == 1 and $_[0][0] eq "call" || $_[0][0] eq "var" && $self->{"prefer_call_for_entity"} and my $macro = $self->can("entmacro_$_[0][1]")
!ll&&!rl&&r
827280111
@_ == 1 and $_[0][0] eq "call" || $_[0][0] eq "var" && $self->{"prefer_call_for_entity"}
!ll&&!rl&&r
43784391
$_[0][0] eq "call" or $_[0][0] eq "var" and $self->{"prefer_call_for_entity"}
l!l&&r!l&&!r
3910784
$_[0][0] eq "var" and $self->{"prefer_call_for_entity"}
!ll&&!rl&&r
4653190
MC/DC60%3/5
@_ == 1 and $_[0][0] eq "call" || $_[0][0] eq "var" && $self->{"prefer_call_for_entity"} and my $macro = $self->can("entmacro_$_[0][1]")
@_ == 1 $_[0][0] eq "call" $_[0][0] eq "var" $self->{"prefer_call_for_entity"} my $macro = $self->can("entmacro_$_[0][1]")
Truth table71%5/7
A and B or C and D and E
A= @_ == 1B= $_[0][0] eq "call"C= $_[0][0] eq "var"D= $self->{"prefer_call_for_entity"}E= my $macro = $self->can("entmacro_$_[0][1]")
ABCDEresult
0XXXX0
100XX0
1010X0
11XX00
101100
11XX11
101111
770 or $_[0][0] eq 'var' and $self->{prefer_call_for_entity})
771 and my $macro = $self->can("entmacro_$_[0][1]")) {
772 111 return $macro->($self, $_[0]);
773 }
774 # XXX: path の先頭と以後は分けないと! as_head, as_rest?
775 my @result = map {
776 1107 my ($type, @rest) = @$_;
777 1158 ▶ unless (my $sub = $self->can("as_expr_$type")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can("as_expr_$type")) { } 1158 0 1158
778 0 die $self->generror("unknown entity item %s", terse_dump($type));
779 } else {
780 1158 $sub->($self, \$escape_now, @rest);
781 }
782 } @_;
783 1098 ▶ return '' unless @result;
Branch: 1 branch
BranchTrueFalseTotal
unless @result 0 1098 1098
784 1098 ▶ my $result = @result > 1 ? join("->", @result) : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
@result > 1 ? : 43 1055 1098
785 # XXX: これだと逆に、 html 型が困る。
786 1098 ▶ if (not $escape_now or ref $result) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $escape_now or ref $result) { } 682 416 1098
Condition100%3/3
not $escape_now or ref $result
l!l&&r!l&&!r
67111416
MC/DC100%2/2
not $escape_now or ref $result
not $escape_now ref $result
Truth table100%3/3
not(A) or B
A= not $escape_nowB= ref $result
ABresult
1X1
011
000
787 682 $result;
788 } else {
789 416 sprintf(q{YATT::Lite::Util::escape(%s)}, $result);
790 }
791 }
792 # XXX: partial logic dup with ensure_entity_is_declared
793 9 ▶ sub find_entity {
Subroutine find_entity: called CC=2 SCAR=7.0
Pod undocumented
794 9 (my MY $self, my ($name)) = @_;
795 9 my Template $tmpl = $self->{_curtmpl};
796 $tmpl->{_Item}{Entity->item_key_for($name)}
797 9 ▶ // $tmpl->{entns}->can(Entity->method_name_for($name));
Condition66%2/3
$tmpl->{"_Item"}{"YATT::Lite::Core::Entity"->item_key_for($name)} // $tmpl->{"entns"}->can("YATT::Lite::Core::Entity"->method_name_for($name))
l!l&&r!l&&!r
018
MC/DC50%1/2
$tmpl->{"_Item"}{"YATT::Lite::Core::Entity"->item_key_for($name)} // $tmpl->{"entns"}->can("YATT::Lite::Core::Entity"->method_name_for($name))
$tmpl->{"_Item"}{"YATT::Lite::Core::Entity"->item_key_for($name)} $tmpl->{"entns"}->can("YATT::Lite::Core::Entity"->method_name_for($name))
Truth table66%2/3
A // B
A= $tmpl->{"_Item"}{"YATT::Lite::Core::Entity"->item_key_for($name)}B= $tmpl->{"entns"}->can("YATT::Lite::Core::Entity"->method_name_for($name))
ABresult
1X1
011
000
798 }
799 275 ▶ sub ensure_entity_is_declared {
Subroutine ensure_entity_is_declared: called CC=3 SCAR=11.0
Pod undocumented
800 275 (my MY $self, my ($name)) = @_;
801 275 my Template $tmpl = $self->{_curtmpl};
802 275 ▶ if ($tmpl->{_Item}{Entity->item_key_for($name)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpl->{"_Item"}{"YATT::Lite::Core::Entity"->item_key_for($name)}) 12 263 275
803 # Found embedded entity definition.
804 12 return;
805 }
806 263 ▶ unless ($tmpl->{entns}->can(Entity->method_name_for($name))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmpl->{"entns"}->can("YATT::Lite::Core::Entity"->method_name_for($name))) 1 262 263
807 die $self->generror(q!No such entity in namespace "%s": %s!
808 1 , $tmpl->{entns}, $name);
809 }
810 }
811 429 ▶ sub gen_entlist {
Subroutine gen_entlist: called CC=2 SCAR=6.9
Pod undocumented
812 429 (my MY $self, my ($escape_now)) = splice @_, 0, 2;
813 my @list = map {
814 429 $self->gen_entpath($escape_now, lxnest($_))
815 } @_;
816 429 ▶ wantarray ? @list : join ", ", @list;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 107 322 429
817 }
818 354 ▶ sub as_expr_var {
Subroutine as_expr_var: called CC=4 SCAR=13.9
Pod undocumented
819 354 (my MY $self, my ($esc_later, $name)) = @_;
820 354 ▶ if (my $var = $self->find_var($name)) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $var = $self->find_var($name)) { } 345 9 354
elsif ($self->find_entity($name)) { } 1 8 9
821 345 ▶ if (my $sub = $self->can("as_expr_var_" . $var->type->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can('as_expr_var_' . $var->type->[0])) { } 28 317 345
822 28 $sub->($self, $esc_later, $var, $name);
823 } else {
824 317 $self->as_lvalue($var);
825 }
826 } elsif ($self->find_entity($name)) {
827 1 $self->gen_entcall($name);
828 } else {
829 8 die $self->generror(q{No such variable '%s'}, $name);
830 }
831 }
832 23 ▶ sub as_expr_var_html {
Subroutine as_expr_var_html: called CC=1 SCAR=0.0
Pod undocumented
833 23 (my MY $self, my ($esc_later, $var, $name)) = @_;
834 23 $$esc_later = 0;
835 23 $self->as_lvalue_html($var);
836 }
837 5 ▶ sub as_expr_var_attr {
Subroutine as_expr_var_attr: called CC=2 SCAR=7.4
Pod undocumented
838 5 (my MY $self, my ($esc_later, $var, $name)) = @_;
839 # $$esc_later = 0;
840 5 (undef, my $attname) = @{$var->type};
841 5 ▶ sprintf(q{YATT::Lite::Util::named_attr('%s', $%s)}
Condition33%1/3
$attname // $name
l!l&&r!l&&!r
050
MC/DC0%0/2
$attname // $name
$attname $name
Truth table33%1/3
A // B
A= $attnameB= $name
ABresult
1X1
011
000
842 , $attname // $name, $name);
843 }
844 287 ▶ sub as_expr_call {
Subroutine as_expr_call: called CC=2 SCAR=6.9
Pod undocumented
845 287 (my MY $self, my ($esc_later, $name)) = splice @_, 0, 3;
846 # XXX: 受け側が print か、それとも一般の式か。 print なら \ すべき。
847 # entns があるか、find_code_var か。さもなければエラーよね。
848 287 ▶ if (my $var = $self->find_callable_var($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $var = $self->find_callable_var($name)) 12 275 287
849 # code 引数の中の引数のデフォルト値の中に、改行が有ったら??
850 # XXX: body の引数宣言が無い場合に <yatt:body/> は、ちゃんと呼び出せるか?
851 12 return $self->as_expr_call_var($var, $name, @_);
852 }
853  
854 275 $self->ensure_entity_is_declared($name);
855  
856 274 $self->gen_entcall($name, @_);
857 }
858 275 ▶ sub gen_entcall {
Subroutine gen_entcall: called CC=1 SCAR=0.0
Pod undocumented
859 275 (my MY $self, my ($name, @rest)) = @_;
860 275 my $call = sprintf '$this->entity_%s(%s)', $name
861 , scalar $self->gen_entlist(undef, @rest);
862 275 $call;
863 }
864 12 ▶ sub as_expr_call_var {
Subroutine as_expr_call_var: called CC=2 SCAR=6.9
Pod undocumented
865 12 (my MY $self, my ($var, $name, @args)) = @_;
866 12 ▶ if (my $sub = $self->can("as_expr_call_var_" . $var->type->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can('as_expr_call_var_' . $var->type->[0])) { } 1 11 12
867 1 $sub->($self, $var, $name, @args);
868 } else {
869 11 \ sprintf q{$%1$s && $%1$s->(%2$s)}, $name
870 , scalar $self->gen_entlist(undef, @args);
871 }
872 }
873 1 ▶ sub as_expr_call_var_attr {
Subroutine as_expr_call_var_attr: called CC=2 SCAR=7.4
Pod undocumented
874 1 (my MY $self, my ($var, $name, @args)) = @_;
875 1 (undef, my $attname) = @{$var->type};
876 1 ▶ sprintf q|YATT::Lite::Util::named_attr('%s', %s)|
Condition33%1/3
$attname // $name
l!l&&r!l&&!r
100
MC/DC0%0/2
$attname // $name
$attname $name
Truth table33%1/3
A // B
A= $attnameB= $name
ABresult
1X1
011
000
877 , $attname // $name
878 , join ", ", "\$".$name, $self->gen_entlist(undef, @args);
879 }
880 12 ▶ sub as_expr_invoke {
Subroutine as_expr_invoke: called CC=1 SCAR=0.0
Pod undocumented
881 12 (my MY $self, my ($esc_later, $name)) = splice @_, 0, 3;
882 12 sprintf '%s(%s)', $name
883 , scalar $self->gen_entlist(undef, @_);
884 }
885  
886 24 ▶ sub as_expr_expr {
Subroutine as_expr_expr: called CC=1 SCAR=0.0
Pod undocumented
887 24 (my MY $self, my ($esc_later, $expr)) = @_;
888 24 $expr;
889 }
890 22 ▶ sub as_expr_array {
Subroutine as_expr_array: called CC=1 SCAR=0.0
Pod undocumented
891 22 (my MY $self, my ($esc_later)) = splice @_, 0, 2;
892 22 '['.$self->gen_entlist(undef, @_).']';
893 }
894 2 ▶ sub as_expr_hash {
Subroutine as_expr_hash: called CC=1 SCAR=0.0
Pod undocumented
895 2 (my MY $self, my ($esc_later)) = splice @_, 0, 2;
896 2 '{'.$self->gen_entlist(undef, @_).'}';
897 }
898 22 ▶ sub as_expr_aref {
Subroutine as_expr_aref: called CC=1 SCAR=0.0
Pod undocumented
899 22 (my MY $self, my ($esc_later, $node)) = @_;
900 22 '['.$self->gen_entpath(undef, lxnest($node)).']';
901 }
902 15 ▶ sub as_expr_href {
Subroutine as_expr_href: called CC=1 SCAR=0.0
Pod undocumented
903 15 (my MY $self, my ($esc_later, $node)) = @_;
904 15 '{'.$self->gen_entpath(undef, lxnest($node)).'}';
905 }
906 2 ▶ sub as_expr_prop {
Subroutine as_expr_prop: called CC=3 SCAR=13.3
Pod undocumented
907 2 (my MY $self, my ($esc_later, $name)) = @_;
908 2 ▶ if ($self->{prefer_call_for_entity}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'prefer_call_for_entity'}) { } 0 2 2
elsif ($name =~ /^\w+$/) { } 2 0 2
909 0 $name
910 } elsif ($name =~ /^\w+$/) {
911 2 "{$name}"
912 } else {
913 0 '{'.qtext($name).'}';
914 }
915 }
916 418 ▶ sub as_expr_text {
Subroutine as_expr_text: called CC=1 SCAR=0.0
Pod undocumented
917 418 (my MY $self, my ($esc_later, $expr)) = @_;
918 418 qqvalue($expr);
919 }
920 #========================================
921 }
922  
923 46 ▶sub make_arg_spec {
Subroutine make_arg_spec: called CC=2 SCAR=6.9
Pod undocumented
924 138 my ($pack, $dict, $order) = splice @_, 0, 3;
925 138 foreach my $name (@_) {
926 322 $dict->{$name} = @$order;
927 322 push @$order, $name;
928 }
929 }
930  
931 44 ▶sub feed_arg_spec {
Subroutine feed_arg_spec: called CC=6 SCAR=18.0
Pod undocumented
932 44 (my MY $trans, my ($args, $arg_dict, $arg_order)) = splice @_, 0, 4;
933 44 my ($found, $nth);
934 44 foreach my $arg (lexpand($args)) {
935 42 my ($name, @ext) = argName($arg); # XXX: <yatt:my var:type=value /> は?
936 42 ▶ unless (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 12 30 42
937 12 ▶ $name = $arg_order->[$nth++]
Branch: 1 branch
BranchTrueFalseTotal
$name = $$arg_order[$nth++] or die $trans->generror("Too many args") 12 0 12
938 or die $trans->generror("Too many args");
939 }
940 42 ▶ defined (my $argno = $arg_dict->{$name})
Branch: 1 branch
BranchTrueFalseTotal
defined(my $argno = $arg_dict->{$name}) or die $trans->generror("Unknown arg '%s'", $name) 42 0 42
941 or die $trans->generror("Unknown arg '%s'", $name);
942  
943 42 ▶ if (defined (my $prevNode = $_[$argno])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prevNode = $_[$argno])) 1 41 42
944 die $trans->generror("You may forgot '=' between %s and %s"
945 , $prevNode->[NODE_PATH]
946 1 , $trans->{_curtmpl}->node_outer_source($arg));
947 }
948  
949 41 $_[$argno] = $arg;
950 41 $found++;
951 }
952 43 $found;
953 }
954  
955 {
956 46 MY->make_arg_spec(\ my %args, \ my @args, qw(if unless));
957 13 ▶ sub macro_if {
Subroutine macro_if: called CC=9 SCAR=22.6
Pod undocumented
958 13 (my MY $self, my $node) = @_;
959 13 my ($path, $body, $primary, $head, $foot) = nx($node);
960 13 my @arms = do {
961 13 ▶ $self->feed_arg_spec($primary, \%args, \@args
Branch: 1 branch
BranchTrueFalseTotal
$self->feed_arg_spec($primary, \%args, \@args, my($if, $unless)) or die $self->generror("Not enough arguments!") 13 0 13
962 , my ($if, $unless))
963 or die $self->generror("Not enough arguments!");
964 13 my ($kw, $cond) = do {
965 13 ▶ if ($if) { (if => $if) }
Branch: 2 branches
BranchTrueFalseTotal
if ($if) { } 13 0 13
elsif ($unless) { } 0 0 0
966 0 elsif ($unless) { (unless => $unless) }
967 0 else { die "??" }
968 };
969 13 ["$kw (%s) ", $cond->[NODE_VALUE], lexpand($body->[NODE_VALUE])];
970 };
971  
972 # いかん、 cond を生成するなら、body も生成しておかないと、行番号が困る。
973  
974 13 foreach my $arg (lexpand($foot)) {
975 11 (undef, my $kw) = @{$arg->[NODE_PATH]};
976 11 ▶ unless ($kw eq 'else') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($kw eq "else") 1 10 11
977 1 die $self->generror("Unknown option for <%s>: %s"
978 , join(":", @$path), $kw);
979 }
980 10 $self->feed_arg_spec($arg->[NODE_ATTLIST], \%args, \@args
981 , my ($if, $unless));
982 9 my ($fmt, $guard) = do {
983 9 ▶ if ($if) {
Branch: 2 branches
BranchTrueFalseTotal
if ($if) { } 4 5 9
elsif ($unless) { } 0 5 5
984 4 (q{elsif (%s) }, $if->[NODE_VALUE]);
985 } elsif ($unless) {
986 0 (q{elsif (not %s) }, $unless->[NODE_VALUE]);
987 } else {
988 5 (q{else }, undef);
989 }
990 };
991 9 push @arms, [$fmt, $guard, lexpand($arg->[NODE_VALUE])]
992 }
993 my @expr = map {
994 11 my ($fmt, $guard, @body) = @$_;
995 20 local $self->{_scope} = $self->mkscope({}, $self->{_scope});
996 20 local $self->{_curtoks} = [@body];
997 20 ▶ (defined $guard
Branch: 1 branch
BranchTrueFalseTotal
defined $guard ? : 15 5 20
998 ? sprintf($fmt, join "", $self->as_list(lexpand($guard))) : $fmt)
999 .'{'.$self->cut_next_nl.$self->as_print('}');
1000 } @arms;
1001 11 \ join "", @expr, $self->cut_next_nl;
1002 }
1003 }
1004  
1005 46 ▶sub is_spread {
Subroutine is_spread: called CC=5 SCAR=16.6
Pod undocumented
1006 ref $_[0] eq 'ARRAY'
1007 6 ▶ && @{$_[0]} == 4
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "ARRAY" and @{$_[0];} == 4 and $_[0][0] eq "" and $_[0][1] eq "" and $_[0][2] eq "" 2 4 6
Condition66%6/9
ref $_[0] eq "ARRAY" and @{$_[0];} == 4 and $_[0][0] eq "" and $_[0][1] eq ""
!ll&&!rl&&r
402
ref $_[0] eq "ARRAY" and @{$_[0];} == 4 and $_[0][0] eq ""
!ll&&!rl&&r
402
ref $_[0] eq "ARRAY" and @{$_[0];} == 4
!ll&&!rl&&r
402
MC/DC25%1/4
ref $_[0] eq "ARRAY" and @{$_[0];} == 4 and $_[0][0] eq "" and $_[0][1] eq ""
ref $_[0] eq "ARRAY" @{$_[0];} == 4 $_[0][0] eq "" $_[0][1] eq ""
Truth table40%2/5
A and B and C and D
A= ref $_[0] eq "ARRAY"B= @{$_[0];} == 4C= $_[0][0] eq ""D= $_[0][1] eq ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1008 && $_[0][0] eq ''
1009 && $_[0][1] eq ''
1010 && $_[0][2] eq ''
1011 }
1012 2 ▶sub take_spread_name {
Subroutine take_spread_name: called CC=1 SCAR=0.0
Pod undocumented
1013 2 $_[0]->[3];
1014 }
1015  
1016 {
1017 38 ▶ sub make_arg_adder {
Subroutine make_arg_adder: called CC=1 SCAR=0.1
Pod undocumented
1018 38 (my MY $self, my $node) = @_;
1019 45 ▶ my $simple_adder = sub {
Subroutine __ANON__: called CC=7 SCAR=19.6
1020 45 my ($default_type, $arg, $valNode, $skip) = @_;
1021 45 my ($name, $typename) = argName($arg, $skip);
1022 45 ▶ if (my $oldvar = $self->find_var($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $oldvar = $self->find_var($name)) 1 44 45
1023 1 ▶ die $self->generror("Conflicting variable '%s'"
Condition50%1/2
$oldvar->lineno // "(unknown)"
l!l
10
MC/DC0%0/1
$oldvar->lineno // "(unknown)"
$oldvar->lineno
Truth table50%1/2
A
A= $oldvar->lineno
Aresult
11
00
1024 ." (previously defined at line %s)"
1025 , $name, $oldvar->lineno // '(unknown)');
1026 }
1027 44 ▶ $typename ||= $default_type;
Condition66%2/3
$typename ||= $default_type
l!l&&r!l&&!r
14300
MC/DC0%0/2
$typename ||= $default_type
$typename $default_type
Truth table66%2/3
A ||= B
A= $typenameB= $default_type
ABresult
1X1
011
000
1028 44 ▶ if (my $sub = $self->can("_macro_my_$typename")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can("_macro_my_$typename")) { } 3 41 44
1029 3 $sub->($self, $node, $name, $valNode);
1030 } else {
1031 41 ▶ my $var = $self->{_scope}[0]{$name}
Branch: 1 branch
BranchTrueFalseTotal
my $var = $self->{"_scope"}[0]{$name} = $self->mkvar_at(undef, $typename, $name) or die $self->generror("Unknown type '%s' for variable '%s'", $typename, $name) 41 0 41
1032 = $self->mkvar_at(undef, $typename, $name)
1033 or die $self->generror("Unknown type '%s' for variable '%s'"
1034 , $typename, $name);
1035 # typename == source の時が問題だ。
1036 41 my $expr = 'my '.$self->as_lvalue($var);
1037 41 my $value = argValue($valNode);
1038 41 ▶ $expr .= defined $value ? (' = '.$self->as_cast_to($var, $value)) : ';';
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 38 3 41
1039 }
1040 38 };
1041 47 ▶ my $adder = sub {
Subroutine __ANON__: called CC=11 SCAR=25.2
1042 47 my ($default_type, $arg, $valNode, $skip) = @_;
1043 47 ▶ if (array_of_array($arg->[NODE_PATH])) {
Branch: 1 branch
BranchTrueFalseTotal
if (array_of_array($arg->[7])) { } 2 45 47
1044 2 my (@pre, @main);
1045 2 foreach my $nameSpec (@{$arg->[NODE_PATH]}) {
1046 6 my $is_spread = is_spread($nameSpec->[NODE_PATH]);
1047 6 my ($name, $typename) = do {
1048 6 ▶ if ($is_spread) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_spread) { } 2 4 6
1049 2 (take_spread_name($nameSpec->[NODE_PATH]), 'list')
1050 } else {
1051 4 argName($nameSpec, $skip);
1052 }
1053 };
1054  
1055 6 ▶ if (my $oldvar = $self->find_var($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $oldvar = $self->find_var($name)) 0 6 6
1056 0 ▶ die $self->generror("Conflicting variable '%s'"
Condition0%0/2
$oldvar->lineno // "(unknown)"
l!l
00
MC/DC0%0/1
$oldvar->lineno // "(unknown)"
$oldvar->lineno
Truth table0%0/2
A
A= $oldvar->lineno
Aresult
11
00
1057 ." (previously defined at line %s)"
1058 , $name, $oldvar->lineno // '(unknown)');
1059 }
1060 6 ▶ $typename ||= $default_type;
Condition66%2/3
$typename ||= $default_type
l!l&&r!l&&!r
240
MC/DC0%0/2
$typename ||= $default_type
$typename $default_type
Truth table66%2/3
A ||= B
A= $typenameB= $default_type
ABresult
1X1
011
000
1061 6 ▶ if (my $sub = $self->can("_macro_my_$typename")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can("_macro_my_$typename")) 0 6 6
1062 ...
1063 0 }
1064 6 ▶ my $var = $self->{_scope}[0]{$name}
Branch: 1 branch
BranchTrueFalseTotal
my $var = $self->{"_scope"}[0]{$name} = $self->mkvar_at(undef, $typename, $name) or die $self->generror("Unknown type '%s' for variable '%s'", $typename, $name) 6 0 6
1065 = $self->mkvar_at(undef, $typename, $name)
1066 or die $self->generror("Unknown type '%s' for variable '%s'"
1067 , $typename, $name);
1068  
1069 6 ▶ if (@pre) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pre) 0 6 6
1070 0 die $self->generror("Multiple spread op is prohibited");
1071 }
1072 6 ▶ if ($is_spread) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_spread) { } 2 4 6
1073 2 push @pre, 'my '.$self->as_lvalue($var).' = []';
1074 2 push @main, '@'.$self->as_lvalue($var);
1075 } else {
1076 4 push @main, 'my '.$self->as_lvalue($var);
1077 }
1078 }
1079 2 my $main = sprintf(q|(%s) = (%s)|, join(", ", @main)
1080 , join("", $self->as_list(lexpand(argValue($valNode)))));
1081 2 (@pre, $main);
1082 } else {
1083 45 $simple_adder->(@_)
1084 }
1085 38 };
1086 }
1087  
1088 33 ▶ sub macro_my {
Subroutine macro_my: called CC=8 SCAR=20.8
Pod undocumented
1089 33 (my MY $self, my $node) = @_;
1090 33 my ($path, $body, $maybeWrappedAttlist, $head, $foot) = nx($node);
1091 33 ▶ my $has_body = $body && @$body ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$body && @$body ? : 5 28 33
Condition66%2/3
$body and @$body
!ll&&!rl&&r
2805
MC/DC50%1/2
$body and @$body
$body @$body
Truth table66%2/3
A and B
A= $bodyB= @$body
ABresult
0X0
100
111
1092 33 my $adder = $self->make_arg_adder($node);
1093 33 my $primary = $self->node_unwrap_attlist($maybeWrappedAttlist);
1094 33 my @assign;
1095 33 foreach my $arg (@{$primary}[0 .. $#$primary-$has_body]) {
1096 35 push @assign, $adder->(text => $arg, $arg);
1097 }
1098 32 ▶ if ($has_body) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_body) 5 27 32
1099 5 my $arg = $primary->[-1];
1100 # XXX: ここは統合できるはず。ただし、NESTED の時に name が無いことを確認すべき。
1101 5 ▶ if ($arg->[NODE_TYPE] == TYPE_ATT_NESTED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->[0] == 9) { } 1 4 5
1102 1 foreach my $each (@{$arg->[NODE_BODY]}) {
1103 2 push @assign, $adder->(html => $each, $body);
1104 }
1105 } else {
1106 4 push @assign, $adder->(html => $arg, $body);
1107 }
1108 }
1109 32 foreach my $arg (map {lexpand($_)} $head, $foot) {
1110 2 push @assign, $adder->(text => $arg, $arg, 1); # Skip leading :yatt:
1111 }
1112 32 \ join "; ", @assign;
1113 }
1114 2 ▶ sub _macro_my_code {
Subroutine _macro_my_code: called CC=1 SCAR=0.0
1115 2 (my MY $self, my ($node, $name, $valNode)) = @_;
1116 2 my $var = $self->{_scope}[0]{$name} = $self->mkvar_at(undef, code => $name);
1117 2 local $self->{_curtoks} = [lexpand(argValue($valNode))];
1118 2 'my '.$self->as_lvalue($var).' = '.q|sub {| . $self->as_print('}');
1119 }
1120 1 ▶ sub _macro_my_source {
Subroutine _macro_my_source: called CC=1 SCAR=0.0
1121 1 (my MY $self, my ($node, $name, $valNode)) = @_;
1122 1 my $var = $self->{_scope}[0]{$name} = $self->mkvar_at(undef, text => $name);
1123 'my '.$self->as_lvalue($var).' = '
1124 2 .join(q|."\n".|, map {qtext($_)}
1125 1 split /\n/, $self->{_curtmpl}->node_body_source($node));
1126 }
1127  
1128 5 ▶ sub macro_block {
Subroutine macro_block: called CC=2 SCAR=6.9
Pod undocumented
1129 5 (my MY $self, my $node) = @_;
1130 5 my ($path, $body, $maybeWrappedAttlist, $head, $foot) = nx($node);
1131 5 local $self->{_scope} = $self->mkscope(+{}, $self->{_scope});
1132 5 my $adder = $self->make_arg_adder($node);
1133 5 my $primary = $self->node_unwrap_attlist($maybeWrappedAttlist);
1134 5 my @assign;
1135 5 foreach my $arg (@$primary) {
1136 4 push @assign, $adder->(text => $arg, $arg);
1137 }
1138 # $self->macro_scoped_block_of_tokens(+{}, @{argValue($body)});
1139 5 local $self->{_curtoks} = [@{argValue($body)}];
1140 5 \ ('{'.join("; ", @assign, "").$self->as_print('}'));
1141 }
1142  
1143 0 ▶ sub macro_scoped_block_of_tokens {
Subroutine macro_scoped_block_of_tokens: not called CC=1 SCAR=6.9
Pod undocumented
1144 0 (my MY $self, my ($scope, @tokens)) = @_;
1145 0 local $self->{_scope} = $self->mkscope($scope, $self->{_scope});
1146 0 local $self->{_curtoks} = \@tokens;
1147 0 \ ('{'.$self->as_print('}'));
1148 }
1149 }
1150  
1151 {
1152 46 MY->make_arg_spec(\ my %args, \ my @args, qw(list nth));
1153 15 ▶ sub macro_foreach {
Subroutine macro_foreach: called CC=25 SCAR=33.1
Pod undocumented
1154 15 (my MY $self, my ($node, $opts)) = @_;
1155 15 my ($path, $body, $primary, $head, $foot) = nx($node);
1156 15 ▶ my @primary = lexpand($primary)
Branch: 1 branch
BranchTrueFalseTotal
my(@primary) = lexpand($primary) or die $self->generror("Not enough arguments for <yatt:foreach>!") 15 0 15
1157 or die $self->generror("Not enough arguments for <yatt:foreach>!");
1158  
1159 15 my ($varDecl, $list, $nth) = do {
1160 15 ▶ if (@primary == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@primary == 1) { } 1 14 15
1161 1 my $name = $primary[0][NODE_PATH];
1162 1 ▶ if (defined $name and $name ne 'list') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and $name ne "list") 0 1 1
Condition33%1/3
defined $name and $name ne "list"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $name and $name ne "list"
defined $name $name ne "list"
Truth table33%1/3
A and B
A= defined $nameB= $name ne "list"
ABresult
0X0
100
111
1163 0 die $self->generror("Invalid list argument for <yatt:foreach>!");
1164 }
1165 1 (undef, $primary[0], undef)
1166 } else {
1167 14 my $declArg = shift @primary;
1168 14 $self->feed_arg_spec(\@primary, \%args, \@args
1169 , my ($list, $nth));
1170 14 ($declArg, $list, $nth);
1171 }
1172 };
1173  
1174 15 my ($prologue, $continue, $epilogue) = ('', '', '');
1175  
1176 15 ▶ unless (defined $list) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $list) 0 15 15
1177 0 die $self->generror("no list= is given");
1178 }
1179  
1180 15 my %local;
1181 15 my $loopvar = do {
1182 15 ▶ if (not $varDecl) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $varDecl) { } 1 14 15
1183 # _ は? entity 自体に処理させるか…
1184 1 ''
1185 }
1186 else {
1187 14 my ($varName, $typeName) = do {
1188 14 my ($head, @rest) = lexpand($varDecl->[NODE_PATH]);
1189 14 my $valuePart = $varDecl->[NODE_VALUE];
1190 14 ▶ if ($head eq 'my') {
Branch: 3 branches
BranchTrueFalseTotal
if ($head eq 'my') { } 11 3 14
elsif (not $valuePart) { } 2 1 3
elsif (not $rest[0]) { } 1 0 1
1191 11 ▶ ($valuePart, $rest[0] || '');
Condition100%2/2
$rest[0] || ''
l!l
110
MC/DC100%1/1
$rest[0] || ''
$rest[0]
Truth table100%2/2
A
A= $rest[0]
Aresult
11
00
1192 }
1193 elsif (not $valuePart) {
1194 2 ($head, $rest[0]);
1195 }
1196 elsif (not $rest[0]) {
1197 1 ($head, $valuePart);
1198 }
1199 else {
1200 0 die $self->generror("conflicting typespec: $rest[0] vs $valuePart")
1201 }
1202 };
1203 14 ▶ $local{$varName} = $self->mkvar_at(undef, $typeName || '' => $varName);
Condition100%2/2
$typeName || ''
l!l
311
MC/DC100%1/1
$typeName || ''
$typeName
Truth table100%2/2
A
A= $typeName
Aresult
11
00
1204 14 "my \$" . $varName;
1205 }
1206 };
1207  
1208 15 my ($nth_var, @nth_type) = do {
1209 15 ▶ if ($nth and my $vn = $nth->[NODE_VALUE]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nth and my $vn = $nth->[8]) 4 11 15
Condition66%2/3
$nth and my $vn = $nth->[8]
!ll&&!rl&&r
1104
MC/DC50%1/2
$nth and my $vn = $nth->[8]
$nth my $vn = $nth->[8]
Truth table66%2/3
A and B
A= $nthB= my $vn = $nth->[8]
ABresult
0X0
100
111
1210 4 my ($x, @t) = lexpand($nth->[NODE_PATH]);
1211 4 ▶ if ($vn =~ /^(\w+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vn =~ /^(\w+)$/) { } 4 0 4
1212 4 ($vn, @t);
1213 } else {
1214 0 die $self->generror("Invalid nth var: %s", $nth);
1215 }
1216 }
1217 };
1218 15 ▶ if ($nth_var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nth_var) 4 11 15
1219 4 ▶ $local{$nth_var} = $self->mkvar_at(undef, $nth_type[0] || '' => $nth_var);
Condition50%1/2
$nth_type[0] || ''
l!l
04
MC/DC0%0/1
$nth_type[0] || ''
$nth_type[0]
Truth table50%1/2
A
A= $nth_type[0]
Aresult
11
00
1220  
1221 4 $prologue .= sprintf q{ my $%s = 1;}, $nth_var;
1222 4 $continue .= sprintf q{ $%s++;}, $nth_var;
1223 }
1224  
1225 15 my $fmt = q|{%4$s; foreach %1$s (%2$s) %3$s continue {%5$s} %6$s}|;
1226 15 my $listexpr = do {
1227 15 ▶ unless (my $passThruVarName = passThruVar($list)) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $passThruVarName = passThruVar($list)) { } 14 1 15
if (do { my $found_var = $self->find_var($passThruVarName) }) { } 13 1 14
1228 1 $self->as_list(lexpand($list->[NODE_VALUE]));
1229 } elsif (my $found_var = $self->find_var($passThruVarName)) {
1230 13 ▶ unless ($found_var->is_type('list')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found_var->is_type("list")) 1 12 13
1231 1 die $self->generror(q{%s - %s should be list type.}
1232 , join(":", @$path), $passThruVarName);
1233 }
1234 12 '@'.$self->as_lvalue($found_var);
1235 } else {
1236 1 die die $self->generror("Unknown variable for foreach list: '%s'", $passThruVarName);
1237 }
1238 };
1239  
1240 13 local $self->{_curtoks} = [@{argValue($body)}];
1241  
1242 # <yatt:foreach ..>\n
1243 # ↑This newline should be removed.
1244 13 my $statements = "{";
1245 13 ▶ if (my $nl = $self->cut_next_nl) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $nl = $self->cut_next_nl) 3 10 13
1246 3 $statements .= $nl;
1247 }
1248  
1249 # ___</yatt:foreach>
1250 # ↑ This indent is messy too.
1251 13 ▶ if (@{$self->{_curtoks}} and $self->{_curtoks}[-1] =~ /^[\ \t]+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_curtoks"};} and $self->{"_curtoks"}[-1] =~ /^[\ \t]+\z/) 1 12 13
Condition66%2/3
@{$self->{"_curtoks"};} and $self->{"_curtoks"}[-1] =~ /^[\ \t]+\z/
!ll&&!rl&&r
0121
MC/DC50%1/2
@{$self->{"_curtoks"};} and $self->{"_curtoks"}[-1] =~ /^[\ \t]+\z/
@{$self->{"_curtoks"};} $self->{"_curtoks"}[-1] =~ /^[\ \t]+\z/
Truth table66%2/3
A and B
A= @{$self->{"_curtoks"};}B= $self->{"_curtoks"}[-1] =~ /^[\ \t]+\z/
ABresult
0X0
100
111
1252 1 pop @{$self->{_curtoks}};
1253 }
1254  
1255 # ...\n ← not to remove this newline.
1256 # </yatt:foreach>
1257 13 local $self->{_no_last_newline} = 0;
1258  
1259 13 local $self->{_scope} = $self->mkscope(\%local, $self->{_scope});
1260 13 $statements .= $self->as_print('}');
1261  
1262 13 ▶ if ($opts and $opts->{fragment}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts and $opts->{'fragment'}) { } 0 13 13
Condition33%1/3
$opts and $opts->{"fragment"}
!ll&&!rl&&r
1300
MC/DC0%0/2
$opts and $opts->{"fragment"}
$opts $opts->{"fragment"}
Truth table33%1/3
A and B
A= $optsB= $opts->{"fragment"}
ABresult
0X0
100
111
1263 0 ($fmt, $loopvar, $listexpr, $statements
1264 , $prologue, $continue, $epilogue);
1265 } else {
1266 13 \ sprintf $fmt, $loopvar, $listexpr, $statements
1267 , $prologue, $continue, $epilogue;
1268 }
1269 }
1270 }
1271  
1272 {
1273 46 MY->make_arg_spec(\ my %args, \ my @args, qw(if unless local));
1274 7 ▶ sub macro_return {
Subroutine macro_return: called CC=9 SCAR=22.3
Pod undocumented
1275 7 (my MY $self, my $node) = @_;
1276 7 my ($path, $body, $primary, $head, $foot) = nx($node);
1277  
1278 7 ▶ if ($foot || $head) {
Branch: 1 branch
BranchTrueFalseTotal
if ($foot or $head) 0 7 7
Condition33%1/3
$foot or $head
l!l&&r!l&&!r
007
MC/DC0%0/2
$foot or $head
$foot $head
Truth table33%1/3
A or B
A= $footB= $head
ABresult
1X1
011
000
1279 0 die $self->generror("Unsupported syntax: foot");
1280 }
1281  
1282 7 $self->feed_arg_spec($primary, \%args, \@args
1283 , my ($if, $unless, $local));
1284  
1285 7 my ($fmt, $guard) = do {
1286 7 ▶ if ($if || $unless) {
Branch: 1 branch
BranchTrueFalseTotal
if ($if or $unless) { } 4 3 7
Condition100%3/3
$if or $unless
l!l&&r!l&&!r
223
MC/DC100%2/2
$if or $unless
$if $unless
Truth table100%3/3
A or B
A= $ifB= $unless
ABresult
1X1
011
000
1287 # conditional return
1288 # if ()
1289 4 my ($kw, $cond) = do {
1290 4 ▶ if ($if) { (if => $if) }
Branch: 2 branches
BranchTrueFalseTotal
if ($if) { } 2 2 4
elsif ($unless) { } 2 0 2
1291 2 elsif ($unless) { (unless => $unless) }
1292 0 else { die "??" }
1293 };
1294 4 ("$kw (%s) ", $cond->[NODE_VALUE]);
1295 } else {
1296 3 ();
1297 }
1298 };
1299  
1300 7 my ($begin, $end) = do {
1301 7 ▶ if ($local) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local) { } 1 6 7
1302 1 ('{', ' return}');
1303 } else {
1304 6 ('{YATT::Lite::Util::rewind($CON); ', ' die \"DONE"}');
1305 }
1306 };
1307  
1308 7 my $expr = do {
1309 7 local $self->{_scope} = $self->mkscope({}, $self->{_scope});
1310 7 local $self->{_curtoks} = [lexpand($body->[NODE_VALUE])];
1311 7 ▶ (defined $guard
Branch: 1 branch
BranchTrueFalseTotal
defined $guard ? : 4 3 7
1312 ? sprintf($fmt, join "", $self->as_list(lexpand($guard))) : '')
1313 .$begin.$self->cut_next_nl.$self->as_print($end);
1314 };
1315  
1316 7 \ $expr;
1317 }
1318 }
1319  
1320 # A skeleton for new macro.
1321 # {
1322 # MY->make_arg_spec(\ my %args, \ my @args, qw(if unless));
1323 # sub macro_return {
1324 # (my MY $self, my $node) = @_;
1325 # my ($path, $body, $primary, $head, $foot) = nx($node);
1326 #
1327 # \ ($self->dump_as_comment_line($self->node_as_hash($node)));
1328 # }
1329 # }
1330  
1331 46 ▶sub dump_as_comment_line {
Subroutine dump_as_comment_line: not called CC=1 SCAR=4.1
Pod undocumented
1332 0 (my MY $self, my $node) = @_;
1333 0 my $str = terse_dump($node);
1334 0 $str =~ s/^/# /mg;
1335 0 $str."\n";
1336 }
1337  
1338 # A skelton for new entmacro
1339 # sub entmacro_XXX {
1340 # (my MY $self, my $node) = @_;
1341 # sprintf(q{YATT::Lite::Util::escape(%s)}, terse_dump($node));
1342 # }
1343  
1344 0 ▶sub entmacro_scalar {
Subroutine entmacro_scalar: not called CC=1 SCAR=6.9
Pod undocumented
1345 0 (my MY $self, my $node) = @_;
1346 0 my (@expr) = $self->gen_entlist(undef, entx($node));
1347 0 sprintf q|scalar(%s)|, join "", @expr;
1348 }
1349  
1350 0 ▶sub entmacro_not {
Subroutine entmacro_not: not called CC=1 SCAR=6.9
Pod undocumented
1351 0 (my MY $self, my $node) = @_;
1352 0 my (@expr) = $self->gen_entlist(undef, entx($node));
1353 0 sprintf q|(not(%s))|, join "", @expr;
1354 }
1355  
1356 0 ▶sub entmacro_and {
Subroutine entmacro_and: not called CC=1 SCAR=6.9
Pod undocumented
1357 0 (my MY $self, my $node) = @_;
1358 0 my (@expr) = $self->gen_entlist(undef, entx($node));
1359 0 "(".join(" and ", map {"($_)"} @expr).")";
1360 }
1361  
1362 0 ▶sub entmacro_or {
Subroutine entmacro_or: not called CC=1 SCAR=6.9
Pod undocumented
1363 0 (my MY $self, my $node) = @_;
1364 0 my (@expr) = $self->gen_entlist(undef, entx($node));
1365 0 "(".join(" or ", map {"($_)"} @expr).")";
1366 }
1367  
1368 0 ▶sub entmacro_undef {
Subroutine entmacro_undef: not called CC=1 SCAR=6.9
Pod undocumented
1369 0 (my MY $self, my $node) = @_;
1370 0 my (@expr) = $self->gen_entlist(undef, entx($node));
1371 0 sprintf q|(undef(%s))|, join "", @expr;
1372 }
1373  
1374 1 ▶sub entmacro_with_ignoring_die {
Subroutine entmacro_with_ignoring_die: called CC=1 SCAR=0.0
Pod undocumented
1375 1 (my MY $self, my $node) = @_;
1376 1 my (@expr) = $self->gen_entlist(undef, entx($node));
1377 1 sprintf q|($this->YATT->with_ignoring_die(sub {%s}))|, join "", @expr;
1378 }
1379  
1380 101 ▶sub entmacro_if {
Subroutine entmacro_if: called CC=3 SCAR=11.4
Pod undocumented
1381 101 (my MY $self, my $node) = @_;
1382 101 my ($cond, $then, $else) = $self->gen_entlist(undef, entx($node));
1383 sprintf q|do {(%s) ? (%s) : (%s)}|
1384 101 ▶ , map {ref $_ ? $$_ : $_} $cond, $then, $else || q{''};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 303 303
Condition50%1/2
$else || q['']
l!l
1010
MC/DC0%0/1
$else || q['']
$else
Truth table50%1/2
A
A= $else
Aresult
11
00
1385 }
1386  
1387 0 ▶sub entmacro_ifeq {
Subroutine entmacro_ifeq: not called CC=3 SCAR=24.8
Pod undocumented
1388 0 (my MY $self, my $node) = @_;
1389 0 my ($val, $what, $then, $else) = $self->gen_entlist(undef, entx($node));
1390 sprintf q|do {((%s // '') eq (%s // '')) ? (%s) : (%s)}|
1391 0 ▶ , map {ref $_ ? $$_ : $_} $val, $what, $then, $else || q{''};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
Condition0%0/2
$else || q['']
l!l
00
MC/DC0%0/1
$else || q['']
$else
Truth table0%0/2
A
A= $else
Aresult
11
00
1392 }
1393  
1394 0 ▶sub entmacro_value_checked {
Subroutine entmacro_value_checked: not called CC=4 SCAR=30.0
Pod undocumented
1395 0 (my MY $self, my $node) = @_;
1396 0 my (@list) = $self->gen_entlist(undef, entx($node));
1397 0 ▶ unless (@list >= 2 and @list <= 3) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@list >= 2 and @list <= 3) 0 0 0
Condition0%0/3
@list >= 2 and @list <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
@list >= 2 and @list <= 3
@list >= 2 @list <= 3
Truth table0%0/3
A and B
A= @list >= 2B= @list <= 3
ABresult
0X0
100
111
1398 0 die $self->generror("Invalid number of args: value_checked(VALUE, HASHorARRAY,?is_default?)");
1399 }
1400 sprintf q|YATT::Lite::Util::value_checked(%s)|
1401 0 ▶ , join ", ", map {ref $_ ? $$_ : $_} @list;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
1402 }
1403  
1404 0 ▶sub entmacro_value_selected {
Subroutine entmacro_value_selected: not called CC=4 SCAR=30.0
Pod undocumented
1405 0 (my MY $self, my $node) = @_;
1406 0 my (@list) = $self->gen_entlist(undef, entx($node));
1407 0 ▶ unless (@list >= 2 and @list <= 3) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@list >= 2 and @list <= 3) 0 0 0
Condition0%0/3
@list >= 2 and @list <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
@list >= 2 and @list <= 3
@list >= 2 @list <= 3
Truth table0%0/3
A and B
A= @list >= 2B= @list <= 3
ABresult
0X0
100
111
1408 0 die $self->generror("Invalid number of args: value_selected(VALUE, HASHorARRAY,?is_default?)");
1409 }
1410 sprintf q|YATT::Lite::Util::value_selected(%s)|
1411 0 ▶ , join ", ", map {ref $_ ? $$_ : $_} @list;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
1412 }
1413  
1414 5 ▶sub entmacro_lexpand {
Subroutine entmacro_lexpand: called CC=1 SCAR=0.0
Pod undocumented
1415 5 (my MY $self, my $node) = @_;
1416 5 q|@{|.$self->gen_entpath(undef, map {lxnest($_)} entx($node)).q| // []}|;
1417 }
1418  
1419 4 ▶sub entmacro_render {
Subroutine entmacro_render: called CC=1 SCAR=0.0
Pod undocumented
1420 4 (my MY $self, my $node) = @_;
1421 4 my ($wname, @expr) = $self->gen_entlist(undef, entx($node));
1422 4 \ sprintf q{YATT::Lite::Util::safe_render($this, $CON, %s, %s)}
1423 , $wname, join(", ", @expr);
1424 }
1425  
1426 0 ▶sub entmacro_dispatch_all {
Subroutine entmacro_dispatch_all: not called CC=1 SCAR=6.9
Pod undocumented
1427 0 (my MY $self, my $node) = @_;
1428 0 my ($prefix, $nargs, @list) = $self->gen_entlist(undef, entx($node));
1429 0 \ sprintf q{YATT::Lite::Util::dispatch_all($this, $CON, %s, %s, %s)}
1430 , $prefix, $nargs, join(", ", @list);
1431 }
1432  
1433 0 ▶sub entmacro_dispatch_one {
Subroutine entmacro_dispatch_one: not called CC=1 SCAR=6.9
Pod undocumented
1434 0 (my MY $self, my $node) = @_;
1435 0 my ($prefix, $nargs, @list) = $self->gen_entlist(undef, entx($node));
1436 0 \ sprintf q{YATT::Lite::Util::dispatch_one($this, $CON, %s, %s, %s)}
1437 , $prefix, $nargs, join(", ", @list);
1438 }
1439  
1440 0 ▶sub entmacro___WIDGET__ {
Subroutine entmacro___WIDGET__: not called CC=1 SCAR=6.9
Pod undocumented
1441 0 (my MY $self, my $node) = @_;
1442 0 my Widget $widget = $self->{_curwidget};
1443 0 qtext($widget->{name});
1444 }
1445  
1446 0 ▶sub entmacro_show_expr {
Subroutine entmacro_show_expr: not called CC=1 SCAR=6.9
Pod undocumented
1447 0 (my MY $self, my $node) = @_;
1448 0 require YATT::Lite::LRXML::FormatEntpath;
1449 0 my (@pipe) = entx($node);
1450 0 \ sprintf q{$this->YATT->render_into($CON, %s, [%s, %s])}
1451 , qtext('show_expr')
1452 , qtext(YATT::Lite::LRXML::FormatEntpath::format_entpath(@pipe))
1453 , join(", ", $self->gen_entpath(undef, @pipe));
1454 }
1455  
1456 46 ▶use YATT::Lite::Breakpoint qw(break_load_cgen break_cgen);
Subroutine BEGIN: called CC=1 SCAR=0.0
1457 46 break_load_cgen();
1458  
1459 46 1;
« blib/lib/YATT/Lite/Core.pm ↑ Summary blib/lib/YATT/Lite/Partial/Gettext.pm »