blib/lib/YATT/Lite/LRXML.pm

filter: Statementstmt 90.4% 680 / 752 Branchbran 75.4% 243 / 322 Conditioncond 61.7% 108 / 175 MC/DCmcdc 33.3% 36 / 108 Subroutinesub 93.6% 89 / 95 Podpod 1.3% 1 / 73 totaltotal 75.8% 1157 / 1525 CC 235 SCAR 23.9
CC
235
Cov
83%
load_from
30.0
cut_import_spec
30.0
parse_attlist_with_lvalue
25.6
CRAP 10.9
« blib/lib/YATT/Lite/Types.pm ↑ Summary blib/lib/YATT/Lite/Core.pm »
1 #========================================
2 # Parsing and Building. part の型を確定させる所まで請け負うことに。
3 package YATT::Lite::LRXML; sub MY () {__PACKAGE__}
4 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 49 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 49 ▶use 5.010; no if $] >= 5.017011, warnings => "experimental";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # 現在宣言 parse 中の template (path キー)。declare_import の循環検出用。GH-256
9 49 our %DECL_PARSING;
10  
11 49 ▶use base qw(YATT::Lite::VarMaker);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 49 ▶use fields qw/_re_decl
Subroutine BEGIN: called CC=1 SCAR=0.0
13 _re_body
14 _re_entopn
15 _re_att
16 _re_name
17 _re_evar _ch_etext
18 _re_eparen
19 _re_eopen _re_eclose
20  
21 _template
22 _chunklist
23 _startln _endln
24 _startpos _curpos
25 namespace
26 vfs
27 default_part
28 base scheme path encoding debug
29 all
30 special_entities
31 body_argument
32 body_argument_type
33  
34 _subroutes
35 _rootroute
36  
37 match_argsroute_first
38  
39 _original_entpath
40 allow_bare_entity_in_decl
41 49 /;
42  
43 49 ▶use YATT::Lite::Core qw(Part Widget Page Action Data Entity Template ArgMacro Import);
Subroutine BEGIN: called CC=1 SCAR=0.0
44 49 ▶use YATT::Lite::VarTypes;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 49 ▶use YATT::Lite::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 49 ▶use YATT::Lite::Util qw(numLines default untaint_unless_tainted lexpand);
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 49 ▶use YATT::Lite::RegexpNames;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 49 require Scalar::Util;
51 49 require Encode;
52 49 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 #========================================
55 407 ▶sub default_public_part {'page'}
Subroutine default_public_part: called CC=1 SCAR=0.0
Pod undocumented
56 28 ▶sub default_private_part {'widget'}
Subroutine default_private_part: called CC=1 SCAR=0.0
Pod undocumented
57 21 ▶sub default_body_argument { 'body' }
Subroutine default_body_argument: called CC=1 SCAR=0.0
Pod undocumented
58  
59 435 ▶sub default_part_for {
Subroutine default_part_for: called CC=2 SCAR=6.9
Pod undocumented
60 435 (my MY $self, my Template $tmpl) = @_;
61 $tmpl->{public}
62 435 ▶ ? $self->default_public_part
Branch: 1 branch
BranchTrueFalseTotal
$tmpl->{'public'} ? : 407 28 435
63 : $self->default_private_part;
64 }
65  
66 #========================================
67 940 ▶sub after_new {
Subroutine after_new: called CC=16 SCAR=31.4
Pod documented
68 940 my MY $self = shift;
69 940 $self->SUPER::after_new;
70 940 ▶ Scalar::Util::weaken($self->{vfs}) if $self->{vfs};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"vfs"} 919 21 940
71  
72 940 ▶ $self->{body_argument} //= $self->default_body_argument;
Condition66%2/3
$self->{"body_argument"} //= $self->default_body_argument
l!l&&r!l&&!r
919210
MC/DC0%0/2
$self->{"body_argument"} //= $self->default_body_argument
$self->{"body_argument"} $self->default_body_argument
Truth table66%2/3
A //= B
A= $self->{"body_argument"}B= $self->default_body_argument
ABresult
1X1
011
000
73  
74 940 ▶ $self->{namespace} ||= [qw(yatt perl)];
Condition100%2/2
$self->{"namespace"} ||= ["yatt", "perl"]
l!l
12928
MC/DC100%1/1
$self->{"namespace"} ||= ["yatt", "perl"]
$self->{"namespace"}
Truth table100%2/2
A
A= $self->{"namespace"}
Aresult
11
00
75 940 my $nspat = qr!@{[join "|", $self->namespace]}!;
76 940 ▶ $self->{_re_name} ||= $self->re_name;
Condition33%1/3
$self->{"_re_name"} ||= $self->re_name
l!l&&r!l&&!r
09400
MC/DC0%0/2
$self->{"_re_name"} ||= $self->re_name
$self->{"_re_name"} $self->re_name
Truth table33%1/3
A ||= B
A= $self->{"_re_name"}B= $self->re_name
ABresult
1X1
011
000
77 940 ▶ my $decl_prefix = $] >= 5.030 ? q{(?<=\A|\n)} : "";
Branch: 1 branch
BranchTrueFalseTotal
$] >= 5.03 ? : 940 0 940
78 940 ▶ $self->{_re_decl} ||= qr{$decl_prefix<!(?<declname>$nspat(?::\w++)+)\b
Condition33%1/3
$self->{"_re_decl"} ||= qr/$decl_prefix<!(?<declname>$nspat(?::\w++)+)\b |(?:<!--\#(?<comment>$nspat(?::\w++)*))\b/sx
l!l&&r!l&&!r
09400
MC/DC0%0/2
$self->{"_re_decl"} ||= qr/$decl_prefix<!(?<declname>$nspat(?::\w++)+)\b |(?:<!--\#(?<comment>$nspat(?::\w++)*))\b/sx
$self->{"_re_decl"} qr/$decl_prefix<!(?<declname>$nspat(?::\w++)+)\b |(?:<!--\#(?<comment>$nspat(?::\w++)*))\b/sx
Truth table33%1/3
A ||= B
A= $self->{"_re_decl"}B= qr/$decl_prefix<!(?<declname>$nspat(?::\w++)+)\b |(?:<!--\#(?<comment>$nspat(?::\w++)*))\b/sx
ABresult
1X1
011
000
79 |(?:<!--\#(?<comment>$nspat(?::\w++)*))\b}xs;
80 940 my $entOpen = do {
81 # qq なので注意
82 940 my $entbase = qq{(?<entity>$nspat)};
83 940 $entbase .= sprintf(q{(?=%s)}, join "|"
84 , ':'
85 , sprintf(q{(?<lcmsg>%s)}, join "|"
86 , q{(?<msgopn>(?:\#\w+)?\[{2,})}
87 , q{(?<msgsep>\|{2,})}
88 , q{(?<msgclo>\]{2,})}));
89 940 my @entPat = $entbase;
90 # special の場合は entgroup を呼びたいので、 先に open ( を削っておく。
91 push @entPat, sprintf q{(?<special>(?:%s))\(}
92 , join "|", lexpand($self->{special_entities})
93 940 ▶ if $self->{special_entities};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"special_entities"} 78 862 940
94 940 sprintf q{&(?:%s)}, join "|", @entPat;
95 };
96  
97 940 ▶ my $entCloseInAtt = $self->{allow_bare_entity_in_decl} ? "" : ";";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'allow_bare_entity_in_decl'} ? : 1 939 940
98  
99 $self->{_re_att}
100 940 ▶ ||= qr{(?<ws>\s++)
Condition33%1/3
$self->{"_re_att"} ||= qr#(?<ws>\s++) | (?<comment>--+.*?--+) | (?<macro>%(?:[\w\:\.]+(?:[\w:\.\-=\[\]\{\}\(,\)]+)?);) | (?:'(?<sq>[^\']*+)' |"(?<dq>[^\"]*+)" |(?<nest>\[) | (?<nestclo>\]) |$entOpen |(?<bare>[^\s\'\"<>\[\]/=$entCloseInAtt]++) ) (?<equal>\s*=\s*+)?+ #sx
l!l&&r!l&&!r
09400
MC/DC0%0/2
$self->{"_re_att"} ||= qr#(?<ws>\s++) | (?<comment>--+.*?--+) | (?<macro>%(?:[\w\:\.]+(?:[\w:\.\-=\[\]\{\}\(,\)]+)?);) | (?:'(?<sq>[^\']*+)' |"(?<dq>[^\"]*+)" |(?<nest>\[) | (?<nestclo>\]) |$entOpen |(?<bare>[^\s\'\"<>\[\]/=$entCloseInAtt]++) ) (?<equal>\s*=\s*+)?+ #sx
$self->{"_re_att"} qr#(?<ws>\s++) | (?<comment>--+.*?--+) | (?<macro>%(?:[\w\:\.]+(?:[\w:\.\-=\[\]\{\}\(,\)]+)?);) | (?:'(?<sq>[^\']*+)' |"(?<dq>[^\"]*+)" |(?<nest>\[) | (?<nestclo>\]) |$entOpen |(?<bare>[^\s\'\"<>\[\]/=$entCloseInAtt]++) ) (?<equal>\s*=\s*+)?+ #sx
Truth table33%1/3
A ||= B
A= $self->{"_re_att"}B= qr#(?<ws>\s++) | (?<comment>--+.*?--+) | (?<macro>%(?:[\w\:\.]+(?:[\w:\.\-=\[\]\{\}\(,\)]+)?);) | (?:'(?<sq>[^\']*+)' |"(?<dq>[^\"]*+)" |(?<nest>\[) | (?<nestclo>\]) |$entOpen |(?<bare>[^\s\'\"<>\[\]/=$entCloseInAtt]++) ) (?<equal>\s*=\s*+)?+ #sx
ABresult
1X1
011
000
101 | (?<comment>--+.*?--+)
102 | (?<macro>%(?:[\w\:\.]+(?:[\w:\.\-=\[\]\{\}\(,\)]+)?);)
103 |
104 (?:'(?<sq>[^\']*+)'
105 |"(?<dq>[^\"]*+)"
106 |(?<nest>\[) | (?<nestclo>\])
107 |$entOpen
108 |(?<bare>[^\s\'\"<>\[\]/=$entCloseInAtt]++)
109 )
110 (?<equal>\s*=\s*+)?+
111 }xs;
112 940 ▶ $self->{_re_body} ||= qr{$entOpen
Condition33%1/3
$self->{"_re_body"} ||= qr"$entOpen |<(?:(?<clo>/?)(?<opt>:?)(?<elem>$nspat(?::\w++)+) |\?(?<pi>$nspat(?::\w++)*))\b "sx
l!l&&r!l&&!r
09400
MC/DC0%0/2
$self->{"_re_body"} ||= qr"$entOpen |<(?:(?<clo>/?)(?<opt>:?)(?<elem>$nspat(?::\w++)+) |\?(?<pi>$nspat(?::\w++)*))\b "sx
$self->{"_re_body"} qr"$entOpen |<(?:(?<clo>/?)(?<opt>:?)(?<elem>$nspat(?::\w++)+) |\?(?<pi>$nspat(?::\w++)*))\b "sx
Truth table33%1/3
A ||= B
A= $self->{"_re_body"}B= qr"$entOpen |<(?:(?<clo>/?)(?<opt>:?)(?<elem>$nspat(?::\w++)+) |\?(?<pi>$nspat(?::\w++)*))\b "sx
ABresult
1X1
011
000
113 |<(?:(?<clo>/?)(?<opt>:?)(?<elem>$nspat(?::\w++)+)
114 |\?(?<pi>$nspat(?::\w++)*))\b
115 }xs;
116 # For entities.
117 940 $self->{_re_entopn} = qr{$entOpen}xs;
118 940 ▶ $self->{_re_eopen} ||= qr{(?<open> [\(\{\[])}xs;
Condition33%1/3
$self->{"_re_eopen"} ||= qr/(?<open> [\(\{\[])/sx
l!l&&r!l&&!r
09400
MC/DC0%0/2
$self->{"_re_eopen"} ||= qr/(?<open> [\(\{\[])/sx
$self->{"_re_eopen"} qr/(?<open> [\(\{\[])/sx
Truth table33%1/3
A ||= B
A= $self->{"_re_eopen"}B= qr/(?<open> [\(\{\[])/sx
ABresult
1X1
011
000
119 940 ▶ $self->{_re_eclose} ||= qr{(?<close> [\)\}\]])}xs;
Condition33%1/3
$self->{"_re_eclose"} ||= qr/(?<close> [\)\}\]])/sx
l!l&&r!l&&!r
09400
MC/DC0%0/2
$self->{"_re_eclose"} ||= qr/(?<close> [\)\}\]])/sx
$self->{"_re_eclose"} qr/(?<close> [\)\}\]])/sx
Truth table33%1/3
A ||= B
A= $self->{"_re_eclose"}B= qr/(?<close> [\)\}\]])/sx
ABresult
1X1
011
000
120 940 ▶ $self->{_re_evar} ||= qr{: (?<var>\w+)}xs;
Condition33%1/3
$self->{"_re_evar"} ||= qr/: (?<var>\w+)/sx
l!l&&r!l&&!r
09400
MC/DC0%0/2
$self->{"_re_evar"} ||= qr/: (?<var>\w+)/sx
$self->{"_re_evar"} qr/: (?<var>\w+)/sx
Truth table33%1/3
A ||= B
A= $self->{"_re_evar"}B= qr/: (?<var>\w+)/sx
ABresult
1X1
011
000
121 940 ▶ $self->{_ch_etext} ||= qr{(?: [^\ \t\n,;:()\[\]{}])}xs;
Condition33%1/3
$self->{"_ch_etext"} ||= qr/(?: [^\ \t\n,;:()\[\]{}])/sx
l!l&&r!l&&!r
09400
MC/DC0%0/2
$self->{"_ch_etext"} ||= qr/(?: [^\ \t\n,;:()\[\]{}])/sx
$self->{"_ch_etext"} qr/(?: [^\ \t\n,;:()\[\]{}])/sx
Truth table33%1/3
A ||= B
A= $self->{"_ch_etext"}B= qr/(?: [^\ \t\n,;:()\[\]{}])/sx
ABresult
1X1
011
000
122 940 ▶ $self->{_re_eparen} ||= qr{(\( (?<paren> (?: (?> [^()]+) | (?-2) )*) \) )}xs;
Condition33%1/3
$self->{"_re_eparen"} ||= qr/(\( (?<paren> (?: (?> [^()]+) | (?-2) )*) \) )/sx
l!l&&r!l&&!r
09400
MC/DC0%0/2
$self->{"_re_eparen"} ||= qr/(\( (?<paren> (?: (?> [^()]+) | (?-2) )*) \) )/sx
$self->{"_re_eparen"} qr/(\( (?<paren> (?: (?> [^()]+) | (?-2) )*) \) )/sx
Truth table33%1/3
A ||= B
A= $self->{"_re_eparen"}B= qr/(\( (?<paren> (?: (?> [^()]+) | (?-2) )*) \) )/sx
ABresult
1X1
011
000
123 940 $self;
124 }
125  
126 use YATT::Lite::Types
127 49 ▶ ([EntMatch => fields => [qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
128 entity
129 lcmsg
130 msgopn msgsep msgclo
131 special
132 /]
133 , [AttMatch => fields => [qw/ws comment
134 macro
135 sq dq bare
136 nest nestclo
137 equal
138 /]]
139 ]
140 49 );
141  
142 #========================================
143  
144 # Debugging aid.
145 # YATT::Lite::LRXML->load_from(string => '...template...')
146 #
147 0 ▶sub load_from {
Subroutine load_from: not called CC=5 SCAR=34.0
Pod undocumented
148 0 my ($pack, $loadSpec, $tmplSpec, @moreLoadArgs) = @_;
149  
150 0 ▶ my ($loadType, @loadArgs) = ref $loadSpec ? @$loadSpec : $loadSpec;
Branch: 1 branch
BranchTrueFalseTotal
ref $loadSpec ? : 0 0 0
151 0 ▶ unless (defined $loadType) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $loadType) 0 0 0
152 0 croak "Undefined source type";
153 }
154 0 ▶ my $sub = $pack->can("load_${loadType}_into")
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $pack->can("load_${loadType}_into") or croak("Unknown source type: $loadType") 0 0 0
155 or croak "Unknown source type: $loadType";
156  
157 0 ▶ my ($tmplFrom, @tmplArgs) = ref $tmplSpec ? @$tmplSpec : $tmplSpec;
Branch: 1 branch
BranchTrueFalseTotal
ref $tmplSpec ? : 0 0 0
158 0 my Template $tmpl = $pack->Template->new(@tmplArgs);
159  
160 # デフォルトでは body もパースする.
161 # XXX: オプション名 all だと分かりにくい。公式にする前に、改名すべき。
162 0 $sub->($pack, $tmpl, $tmplFrom, all => 1, @loadArgs, @moreLoadArgs);
163 }
164  
165 232 ▶sub load_file_into {
Subroutine load_file_into: called CC=7 SCAR=20.7
Pod undocumented
166 232 my ($pack, $tmpl, $fn) = splice @_, 0, 3;
167 232 ▶ croak "Template argument is missing!
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tmpl and UNIVERSAL::isa($tmpl, $pack->Template) 0 232 232
Condition33%1/3
defined $tmpl and UNIVERSAL::isa($tmpl, $pack->Template)
!ll&&!rl&&r
00232
MC/DC0%0/2
defined $tmpl and UNIVERSAL::isa($tmpl, $pack->Template)
defined $tmpl UNIVERSAL::isa($tmpl, $pack->Template)
Truth table33%1/3
A and B
A= defined $tmplB= UNIVERSAL::isa($tmpl, $pack->Template)
ABresult
0X0
100
111
168 YATT::Lite::Parser->from_file(filename, templateObject)"
169 unless defined $tmpl and UNIVERSAL::isa($tmpl, $pack->Template);
170 232 ▶ unless (defined $fn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fn) 0 232 232
171 0 croak "filename is undef!";
172 }
173 232 ▶ my MY $self = ref $pack ? $pack->configure(@_) : $pack->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
ref $pack ? : 232 0 232
174 232 ▶ open my $fh, '<', $fn or die "Can't open $fn: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $fn or die "Can't open ${fn}: $!" 232 0 232
175 232 ▶ binmode $fh, ":encoding($$self{encoding})" if $$self{encoding};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"encoding"} 230 2 232
176 232 $self->{path} = $fn;
177 232 $self->{scheme} = 'file';
178 232 my $string = do {
179 232 local $/;
180 232 untaint_unless_tainted($fn, scalar <$fh>);
181 };
182 232 $self->load_string_into($tmpl, $string);
183 }
184  
185 487 ▶sub load_string_into {
Subroutine load_string_into: called CC=5 SCAR=16.4
Pod undocumented
186 487 (my $pack, my Template $tmpl) = splice @_, 0, 2;
187 487 $tmpl->reset;
188 487 ▶ my MY $self = ref $pack ? $pack->configure(@_[1 .. $#_])
Branch: 1 branch
BranchTrueFalseTotal
ref $pack ? : 473 14 487
189 : $pack->new(@_[1 .. $#_]);
190 487 ▶ unless (defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 0 487 487
191 0 croak "template string is undef!";
192 }
193 487 $self->parse_decl($tmpl, $_[0]);
194 465 ▶ $self->parse_body($tmpl) if $self->{all};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"all"} 17 448 465
195 464 ▶ wantarray ? ($tmpl, $self) : $tmpl;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 464 464
196 }
197  
198 463 ▶sub parse_body {
Subroutine parse_body: called CC=3 SCAR=11.0
Pod undocumented
199 463 (my MY $self, my Template $tmpl) = @_;
200 463 ▶ return if $tmpl->{_parse_ok};
Branch: 1 branch
BranchTrueFalseTotal
if $tmpl->{"_parse_ok"} 7 456 463
201 456 $self->{_template} = $tmpl;
202 456 $self->parse_widget($_) for $tmpl->list_parts($self->Widget);
203 446 $tmpl->{_parse_ok} = 1;
204 }
205  
206 #
207 # parse_decllist_entities updates all decllists in given template.
208 # This method is for inspector and not used from normal code generation pass.
209 #
210 4 ▶sub parse_decllist_entities {
Subroutine parse_decllist_entities: called CC=7 SCAR=19.6
Pod undocumented
211 4 (my MY $self, my Template $tmpl) = @_;
212 4 foreach my Part $part ($tmpl->list_parts) {
213 # $self->{startln} = $self->{endln} = $part->{bodyln};
214 # ($self->{startpos}, $self->{curpos}) = ($part->{startpos}) x 2;
215 8 ▶ my $decllist = $part->{_decllist} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $decllist = $part->{"_decllist"} or next 6 2 8
216 6 foreach my $node (@$decllist) {
217 9 ▶ $node->[NODE_TYPE] == TYPE_ATT_TEXT
Branch: 1 branch
BranchTrueFalseTotal
$node->[0] == 8 or next 3 6 9
218 or next;
219 3 $self->{_endln} = $node->[NODE_LNO];
220 3 my ($type, $dflag, $default)
221 = $self->parse_type_dflag_default($node->[NODE_BODY]);
222 3 ▶ if (ref $node->[NODE_PATH]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node->[7]) 0 3 3
223 ...
224 0 }
225 3 ▶ $node->[NODE_BODY] = [
Branch: 1 branch
BranchTrueFalseTotal
defined $default ? : 1 2 3
226 $type, $dflag,
227 (defined $default
228 ? lexpand($self->_parse_text_entities_at($node->[NODE_BODY_BEGIN], $default))
229 : ())];
230 }
231 }
232 }
233  
234 19 ▶sub posinfo {
Subroutine posinfo: called CC=1 SCAR=0.0
Pod undocumented
235 19 (my MY $self) = shift;
236 19 ($self->{_startpos}, $self->{_curpos});
237 }
238  
239 1966 ▶sub add_posinfo {
Subroutine add_posinfo: called CC=2 SCAR=6.9
Pod undocumented
240 1966 (my MY $self, my ($len, $sync)) = @_;
241 1966 $self->{_curpos} += $len;
242 1966 ▶ $self->{_startpos} = $self->{_curpos} if $sync;
Branch: 1 branch
BranchTrueFalseTotal
if $sync 1425 541 1966
243 1966 $len;
244 }
245  
246 0 ▶sub update_posinfo {
Subroutine update_posinfo: not called CC=2 SCAR=17.9
Pod undocumented
247 0 my MY $self = shift;
248 0 my ($sync) = splice @_, 1;
249 # $self->{_curpos} = $self->{total} - length $_[0];
250 0 ▶ $self->{_startpos} = $self->{_curpos} if $sync;
Branch: 1 branch
BranchTrueFalseTotal
if $sync 0 0 0
251 }
252  
253 214 ▶sub ensure_default_part {
Subroutine ensure_default_part: called CC=1 SCAR=0.0
Pod undocumented
254 214 (my MY $self, my Template $tmpl) = @_;
255 my Part $part = $self->build(
256 $self->primary_ns
257 , args => $self->default_part_for($tmpl)
258 , '', implicit => 1
259 , startpos => $self->{_startpos}, bodypos => $self->{_startpos}
260 214 );
261 214 $self->add_part($tmpl, $part);
262 214 $part;
263 }
264  
265 487 ▶sub parse_decl {
Subroutine parse_decl: called CC=21 SCAR=30.5
Pod undocumented
266 487 (my MY $self, my Template $tmpl, my $str, my @config) = @_;
267 # local %+; # ← XXX: This causes massive test failure, but why??
268 487 break_parser();
269 # 宣言 parse 中フラグ。declare_import の循環検出に使う。GH-256
270 # (path キーの registry も持つのは、循環相手の Template object が
271 # cached_in の dict 代入前で、object 経由では検出できないケースがあるため)
272 487 local $tmpl->{_decl_parsing} = 1;
273 487 ▶ local $DECL_PARSING{$tmpl->{path} // Scalar::Util::refaddr($tmpl)} = 1;
Condition66%2/3
$tmpl->{"path"} // builtin::refaddr($tmpl)
l!l&&r!l&&!r
2322550
MC/DC0%0/2
$tmpl->{"path"} // builtin::refaddr($tmpl)
$tmpl->{"path"} builtin::refaddr($tmpl)
Truth table66%2/3
A // B
A= $tmpl->{"path"}B= builtin::refaddr($tmpl)
ABresult
1X1
011
000
274 487 $self->{_template} = $tmpl;
275 487 $self->configure(@config);
276 487 $tmpl->{string} = $str;
277 487 $tmpl->{utf8} = Encode::is_utf8($str);
278 # 宣言/コメントの位置記録。再 parse で重複しないようここで初期化する。GH-258
279 487 $tmpl->{_boundarylist} = [];
280 487 $self->{_startln} = $self->{_endln} = 1;
281 487 ($self->{_startpos}, $self->{_curpos}, my $total) = (0, 0, length $str);
282 487 my Part $part;
283 487 ▶ while ($str =~ s{^(.*?)($$self{_re_decl})}{}s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/^(.*?)($self->{"_re_decl"})//s) 582 465 1047
284 582 ▶ if (not $part and (length $1 || $+{comment})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $part and length $1 || $+{"comment"}) 86 496 582
Condition83%5/6
not $part and length $1 || $+{"comment"}
!ll&&!rl&&r
18031686
length $1 or $+{"comment"}
l!l&&r!l&&!r
860316
MC/DC66%2/3
not $part and length $1 || $+{"comment"}
not $part length $1 $+{"comment"}
Truth table75%3/4
not(A) and B or C
A= not $partB= length $1C= $+{"comment"}
ABCresult
0XX0
1000
11X1
1011
285 86 $part = $self->ensure_default_part($tmpl);
286 }
287 582 ▶ $self->add_text($part, $1) if length $1;
Branch: 1 branch
BranchTrueFalseTotal
if length $1 262 320 582
288 582 $self->{_curpos} = $total - length $str;
289 582 ▶ if (my $comment_ns = $+{comment}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comment_ns = $+{"comment"}) 19 563 582
290 19 ▶ unless ($str =~ s{^(.*?)-->(\r?\n)?}{}s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($str =~ s/^(.*?)-->(\r?\n)?//s) 0 19 19
291 0 die $self->synerror_at($self->{_startln}, q{Comment is not closed});
292 }
293 19 ▶ my $nlines = numLines($1) + ($2 ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 18 1 19
294 19 $self->{_curpos} += length $&;
295 #
296 # Yet another illegular.
297 # TYPE_COMMENT:
298 # - NODE_BODY is $nlines
299 # - NODE_ATTLIST is payload.
300 #
301 19 push @{$part->{_toks}}, do {
302 19 my $node = [];
303 19 $node->[NODE_TYPE] = TYPE_COMMENT;
304 19 @{$node}[NODE_BEGIN, NODE_END] = $self->posinfo($str);
305 19 $node->[NODE_LNO] = $self->{_startln};
306 19 $node->[NODE_PATH] = $comment_ns;
307 19 $node->[NODE_BODY] = $nlines;
308 19 $node->[NODE_ATTLIST] = $1;
309 19 $node;
310 };
311 # 不変量: substr(string, startpos, endpos - startpos) はコメント全文。GH-258
312 19 push @{$tmpl->{_boundarylist}}, +{
313 kind => 'comment', declkind => $comment_ns
314 , startpos => $self->{_startpos}, endpos => $self->{_curpos}
315 19 , lineno => $self->{_startln}, nlines => $nlines
316 };
317 19 $self->{_startln} = $self->{_endln} += $nlines;
318 19 next;
319 }
320 563 my $declkind = $+{declname};
321 563 my ($ns, $kind) = split /:/, $declkind, 2;
322 # 宣言境界の先頭 pos/行。この時点の _startpos は宣言先頭を指しており、
323 # part の startpos (build 経由) と同じ値になる。GH-258
324 563 my ($decl_startpos, $decl_startln) = ($self->{_startpos}, $self->{_startln});
325 563 ▶ if (my $sub = $self->can("declare_$kind")) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $sub = $self->can("declare_$kind")) { } 309 254 563
elsif ($self->can("build_$kind")) { } 252 2 254
326 # yatt:args, base, action, argmacro...
327  
328 # add_part を自分で呼びたい、又は add_part 自体を呼びたくないものは
329 # declare_ で処理する.
330  
331 # 最初に、ここまでの宣言で作られた part を finalize
332 # (ただし、宣言抜きで作られた default widget の場合は何もしない)
333 309 ▶ if ($part and not $part->{implicit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part and not $part->{"implicit"}) 26 283 309
Condition100%3/3
$part and not $part->{"implicit"}
!ll&&!rl&&r
275826
MC/DC100%2/2
$part and not $part->{"implicit"}
$part not $part->{"implicit"}
Truth table100%3/3
A and not(B)
A= $partB= not $part->{"implicit"}
ABresult
0X0
100
111
334 26 $self->finalize_part($part);
335 }
336  
337 # 戻り値が undef なら、同じ $part を用いつづける。
338 309 my @args = $self->parse_attlist(\$str, 1);
339 309 my $newpart = $sub->($self, $tmpl, $ns, @args);
340  
341 293 ▶ if ($newpart) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newpart) 249 44 293
342 249 $newpart->{_decllist} = \@args;
343 249 $part = $newpart;
344 }
345 }
346 elsif ($self->can("build_$kind")) {
347 252 ▶ $self->finalize_part($part) if $part;
Branch: 1 branch
BranchTrueFalseTotal
if $part 213 39 252
348 # yatt:widget, entity
349 252 my (@args) = $self->parse_attlist(\$str, 1); # To delay entity parsing.
350 252 my $saved_attlist = [@args];
351  
352 # Cut partname="/route/pattern" from @args
353 252 my ($partName, $mapping) = $self->cut_partname_and_route($declkind, \@args);
354  
355 251 $self->add_part($tmpl, $part = $self->build($ns, $kind, $kind, $partName));
356  
357 # $part decllist may contain not only attributes but also others
358 # like argmacrosand possible future items.
359 249 $part->{_decllist} = $saved_attlist;
360  
361 249 ▶ if ($mapping) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mapping) 37 212 249
362 37 $self->add_route($part, $mapping);
363 }
364 249 $self->add_args($part, @args);
365 }
366 else {
367 2 die $self->synerror_at($self->{_startln}, q{Unknown declarator (<!%s:%s >)}, $ns, $kind);
368 }
369 542 ▶ unless ($str =~ s{^>([\ \t]*\r?\n)?}{}s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($str =~ s/^>([\ \t]*\r?\n)?//s) 1 541 542
370 1 die $self->synerror_at($self->{_startln}, q{Declarator '<!%s:%s' is not closed with '>': %s}
371 , $ns, $kind
372 , _firstline_only($str));
373 }
374 # <!yatt:...> の直後には改行が必要、とする。
375 541 ▶ unless ($1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($1) 0 541 541
376 0 die $self->synerror_at($self->{_startln}, q{<!%s:%s> must end with newline!}, $ns, $kind);
377 }
378 541 $self->add_posinfo(length $&);
379 541 $self->{_endln} += numLines($1);
380 # 不変量: substr(string, startpos, endpos - startpos) は宣言全文
381 # (閉じ '>' + 改行まで)。endpos は続く part の bodypos に等しい。GH-258
382 541 push @{$tmpl->{_boundarylist}}, +{
383 kind => 'decl', declkind => $declkind
384 , startpos => $decl_startpos, endpos => $self->{_curpos}
385 541 , lineno => $decl_startln
386 };
387 541 ▶ if ($part) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part) 498 43 541
388 498 $part->{bodypos} = $self->{_curpos};
389 498 $part->{bodyln} = $self->{_endln}; # part の本体開始行の初期値
390 }
391 } continue {
392 560 $self->{_startpos} = $self->{_curpos};
393 # Keep _startln in sync as well. add_text does this when body text
394 # follows, but for back-to-back declarations nothing else would, and
395 # every following part got the same startln. GH-275
396 560 $self->{_startln} = $self->{_endln};
397 }
398  
399 # Even if no declarations are found, there should be at least one default part.
400 465 ▶ $part //= $self->ensure_default_part($tmpl);
Condition66%2/3
$part //= $self->ensure_default_part($tmpl)
l!l&&r!l&&!r
3371280
MC/DC0%0/2
$part //= $self->ensure_default_part($tmpl)
$part $self->ensure_default_part($tmpl)
Truth table66%2/3
A //= B
A= $partB= $self->ensure_default_part($tmpl)
ABresult
1X1
011
000
401 465 push @{$part->{_toks}}, nonmatched($str);
402 # widget->{endln} は, (視覚上の最後の行)より一つ先の行を指す。(末尾の改行を数える分,多い)
403 465 $part->{endln} = $self->{_endln} += numLines($str);
404  
405 465 $self->finalize_part($part);
406 465 $self->finalize_template($tmpl);
407 }
408  
409 269 ▶sub cut_partname_and_route {
Subroutine cut_partname_and_route: called CC=9 SCAR=23.5
Pod undocumented
410 269 (my MY $self, my ($declkind, $argList)) = @_;
411 269 ▶ my $nameAtt = YATT::Lite::Constants::cut_first_att($argList) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $nameAtt = YATT::Lite::Constants::cut_first_att($argList) or do { my YATT::Lite::Core::Template $tmpl = $self->{"_template"}; die $self->synerror_at($self->{"_startln"}, "No part name in %s\\n%s", $declkind, nonmatched($tmpl->{"string"})) } 269 0 269
412 0 my Template $tmpl = $self->{_template};
413 die $self->synerror_at($self->{_startln}, q{No part name in %s\n%s}
414 , $declkind
415 0 , nonmatched($tmpl->{string}));
416 };
417 269 my ($partName, $mapping);
418 269 ▶ if ($nameAtt->[NODE_TYPE] == TYPE_ATT_NAMEONLY) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nameAtt->[0] == 6) { } 221 48 269
elsif ($nameAtt->[0] == 8) { } 48 0 48
419 221 $partName = $nameAtt->[NODE_PATH];
420 } elsif ($nameAtt->[NODE_TYPE] == TYPE_ATT_TEXT) {
421 48 ▶ if (ref $nameAtt->[NODE_BODY]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $nameAtt->[8]) 1 47 48
422 1 my $t = $YATT::Lite::Constants::TYPE_[$nameAtt->[NODE_BODY][0][NODE_TYPE]];
423 die $self->synerror_at($self->{_startln}
424 1 , q{%s got wrong token for route spec: %s}
425 , $declkind, $t);
426 }
427 47 ▶ if ($nameAtt->[NODE_BODY] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($nameAtt->[8] eq '') { } 6 41 47
428 6 ▶ $partName = $nameAtt->[NODE_PATH] // '';
Condition50%1/2
$nameAtt->[7] // ""
l!l
06
MC/DC0%0/1
$nameAtt->[7] // ""
$nameAtt->[7]
Truth table50%1/2
A
A= $nameAtt->[7]
Aresult
11
00
429 } else {
430 # $partName が foo=bar なら pattern として扱う
431 $mapping = $self->parse_location
432 41 ▶ ($nameAtt->[NODE_BODY], $nameAtt->[NODE_PATH]) or do {
Branch: 1 branch
BranchTrueFalseTotal
$mapping = $self->parse_location($nameAtt->[8], $nameAtt->[7]) or do { die $self->synerror_at($self->{"_startln"}, "Invalid location in %s - \"%s\"", $declkind, $nameAtt->[8]) } 41 0 41
433 die $self->synerror_at($self->{_startln}
434 0 , q{Invalid location in %s - "%s"}
435 , $declkind, $nameAtt->[NODE_BODY])
436 };
437 41 ▶ $partName = $nameAtt->[NODE_PATH]
Condition66%2/3
$nameAtt->[7] // $self->location2name($nameAtt->[8])
l!l&&r!l&&!r
4370
MC/DC0%0/2
$nameAtt->[7] // $self->location2name($nameAtt->[8])
$nameAtt->[7] $self->location2name($nameAtt->[8])
Truth table66%2/3
A // B
A= $nameAtt->[7]B= $self->location2name($nameAtt->[8])
ABresult
1X1
011
000
438 // $self->location2name($nameAtt->[NODE_BODY]);
439 }
440 } else {
441 0 die $self->synerror_at($self->{_startln}, q{Invalid part name in %s}
442 , $declkind);
443 }
444  
445 268 ($partName, $mapping);
446 }
447  
448 465 ▶sub finalize_template {
Subroutine finalize_template: called CC=4 SCAR=15.2
Pod undocumented
449 465 (my MY $self, my Template $tmpl) = @_;
450  
451 465 $self->fixup_template_foreach_part_posinfo($tmpl);
452  
453 465 $tmpl->{nlines} = $self->{_endln};
454  
455 465 ▶ if ($self->{match_argsroute_first}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"match_argsroute_first"}) 0 465 465
456 0 ▶ if ($self->{_rootroute}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_rootroute"}) 0 0 0
457 0 $self->subroutes->append($self->{_rootroute});
458 }
459 }
460 465 ▶ if ($self->{_subroutes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_subroutes"}) 24 441 465
461 24 $tmpl->{subroutes} = $self->{_subroutes};
462 }
463 $tmpl
464 465 }
465  
466 465 ▶sub fixup_template_foreach_part_posinfo {
Subroutine fixup_template_foreach_part_posinfo: called CC=10 SCAR=23.1
Pod undocumented
467 465 (my MY $self, my Template $tmpl) = @_;
468 # $default が partlist に足されてなかったら、先頭に足す... 逆か。
469 # args が、 $default を先頭から削る?
470 # fixup parts.
471 #
472 # 本体区間は「bodypos 以降で最初の宣言境界」まで (無ければ EOF まで)。
473 # _partlist だけを歩くと <!yatt:argmacro> のような partlist に入らない
474 # 宣言を飲み込んでしまう (GH-258)。コメント境界は part 区間の内部要素
475 # なので区間を切らない (raw 本体からの除去は part_body_source が行う)。
476 465 ▶ my @decl_boundaries = grep {$_->{kind} eq 'decl'} @{$tmpl->{_boundarylist} // []};
Condition50%1/2
$tmpl->{"_boundarylist"} // []
l!l
4650
MC/DC0%0/1
$tmpl->{"_boundarylist"} // []
$tmpl->{"_boundarylist"}
Truth table50%1/2
A
A= $tmpl->{"_boundarylist"}
Aresult
11
00
477 465 foreach my Part $part (@{$tmpl->{_partlist}}) {
478 707 ▶ unless (defined $part->{bodypos}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $part->{"bodypos"}) 0 707 707
479 0 die $self->synerror_at($self->{_startln}, q{bodypos is undef});
480 }
481 707 my ($next) = grep {$_->{startpos} >= $part->{bodypos}} @decl_boundaries;
482 $part->{bodylen} = ($next ? $next->{startpos} : length($tmpl->{string}))
483 707 ▶ - $part->{bodypos};
Branch: 1 branch
BranchTrueFalseTotal
$next ? : 227 480 707
484 707 ▶ if ($part->{_toks} and @{$part->{_toks}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part->{"_toks"} and @{$part->{"_toks"};}) 679 28 707
Condition100%3/3
$part->{"_toks"} and @{$part->{"_toks"};}
!ll&&!rl&&r
199679
MC/DC100%2/2
$part->{"_toks"} and @{$part->{"_toks"};}
$part->{"_toks"} @{$part->{"_toks"};}
Truth table100%3/3
A and B
A= $part->{"_toks"}B= @{$part->{"_toks"};}
ABresult
0X0
100
111
485 # widget 末尾の連続改行を、単一の改行トークンへ変換。(行番号は解析済みだから大丈夫)
486 679 ▶ if ($part->{_toks}[-1] =~ s/(?:\r?\n)+\Z//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part->{"_toks"}[-1] =~ s/(?:\r?\n)+\Z//) 602 77 679
487 599 push @{$part->{_toks}}, "\n"
488 602 ▶ unless $tmpl->{ignore_trailing_newlines};
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpl->{"ignore_trailing_newlines"} 599 3 602
489 }
490 }
491 707 ▶ if (my $sub = $part->can('fixup')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $part->can("fixup")) 659 48 707
492 659 $sub->($part, $tmpl, $self);
493 }
494 }
495 }
496  
497 948 ▶sub parse_attlist {
Subroutine parse_attlist: called CC=1 SCAR=0.0
Pod undocumented
498 948 (my MY $self, my ($strref, @opt)) = @_;
499 948 $self->parse_attlist_with_lvalue($self->{_curpos}, undef, $strref, @opt);
500 }
501  
502 1009 ▶sub parse_attlist_with_lvalue {
Subroutine parse_attlist_with_lvalue: called CC=25 SCAR=32.4
Pod undocumented
503 1009 (my MY $self, my ($outer_start, $outer_lvalue, $strref, @opt)) = @_;
504  
505 # To examine node range in perldebugger, do like following:
506 #
507 # x substr($self->{_template}{string}, 18, 26-18)
508 #
509  
510 1009 my ($for_decl) = @opt;
511 1009 my (@result, @lvalue); # Note: @lvalue contains position of lvalue expression.
512 1009 my $curln = $self->{_endln};
513 1009 ▶ while ($$strref =~ s{^$$self{_re_att}}{}xs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$strref =~ s/^$self->{"_re_att"}//sx) 2773 982 3755
514 2773 my $start = $self->{_curpos};
515 2773 $self->{_curpos} += length $&;
516 # startln は不変に保つ. これは add_part が startln を使うため
517 2773 $self->{_endln} += numLines($&);
518  
519 2773 my AttMatch $m = \%+;
520 2773 ▶ next if $m->{ws} || $m->{comment};
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"ws"} or $m->{"comment"} 1161 1612 2773
Condition100%3/3
$m->{"ws"} or $m->{"comment"}
l!l&&r!l&&!r
115651612
MC/DC100%2/2
$m->{"ws"} or $m->{"comment"}
$m->{"ws"} $m->{"comment"}
Truth table100%3/3
A or B
A= $m->{"ws"}B= $m->{"comment"}
ABresult
1X1
011
000
521 1612 ▶ if ($m->{macro}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{"macro"}) 12 1600 1612
522 12 push @result, $self->mkargmacro($start, $m->{macro});
523 12 next;
524 }
525  
526 1600 my @common = ($start, $self->{_curpos}, $curln);
527 312 ▶ my $mklval = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
528 312 ▶ if (@lvalue) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lvalue) { } 235 77 312
529 235 my ($s, $p, $l, $n) = splice(@lvalue);
530 # For endpos, curpos should be fetched after the parsing.
531 235 ($s, $self->{_curpos}, $l, $n);
532 } else {
533 77 (@common, undef);
534 }
535 1600 };
536  
537 # lvalue or rvalue
538 1600 ▶ if (not $m->{equal}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $m->{'equal'}) { } 1217 383 1600
elsif (not @lvalue) { } 383 0 383
539 # rvalue
540 # create node. may have lvalue.
541 1217 ▶ if ($m->{nestclo}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{"nestclo"}) 27 1190 1217
542 # "body = [code p q]" comes here
543 27 ▶ unless ($outer_lvalue) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($outer_lvalue) 0 27 27
544 0 Carp::croak("syntax error");
545 }
546 27 my ($s, $p, $l, $n) = do {
547 27 ▶ if ($outer_lvalue && @$outer_lvalue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outer_lvalue and @$outer_lvalue) { } 25 2 27
Condition66%2/3
$outer_lvalue and @$outer_lvalue
!ll&&!rl&&r
0225
MC/DC50%1/2
$outer_lvalue and @$outer_lvalue
$outer_lvalue @$outer_lvalue
Truth table66%2/3
A and B
A= $outer_lvalueB= @$outer_lvalue
ABresult
0X0
100
111
548 25 splice(@$outer_lvalue);
549 } else {
550 2 (@common, undef)
551 }
552 };
553 27 my $node = [];
554 27 $node->[NODE_TYPE] = TYPE_ATT_NESTED;
555 27 $node->[NODE_BEGIN] = $outer_start;
556 27 $node->[NODE_END] = $self->{_curpos};
557 27 $node->[NODE_LNO] = $l;
558 27 $node->[NODE_PATH] = $n;
559 27 $node->[NODE_BODY] = \@result;
560 27 return $node;
561 }
562  
563 1190 ▶ if ($m->{nest}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{'nest'}) { } 61 1129 1190
564 # [ 〜 ]
565 61 push @result,
566 $self->parse_attlist_with_lvalue($start, \@lvalue, $strref, @opt);
567 } else {
568 1129 push @result, my $node = [];
569 {
570 1129 ▶ if ($m->{bare} and is_ident($m->{bare})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($m->{'bare'} and is_ident($m->{'bare'})) { } 817 312 1129
elsif ($+{'entity'} or $+{'special'}) { } 4 308 312
Condition100%3/3
$m->{"bare"} and is_ident($m->{"bare"})
!ll&&!rl&&r
28626817
MC/DC100%2/2
$m->{"bare"} and is_ident($m->{"bare"})
$m->{"bare"} is_ident($m->{"bare"})
Truth table100%3/3
A and B
A= $m->{"bare"}B= is_ident($m->{"bare"})
ABresult
0X0
100
111
571 817 ▶ if (@lvalue) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lvalue) { } 123 694 817
572 123 $node->[NODE_TYPE] = TYPE_ATT_BARENAME;
573 123 @{$node}[NODE_BEGIN, NODE_END, NODE_LNO, NODE_PATH] = splice(@lvalue);
574 # NODE_END from the lvalue stops right after '='. Cover the
575 # value too, like the other attribute types do. GH-277
576 123 $node->[NODE_END] = $self->{_curpos};
577 123 $node->[NODE_BODY] = $m->{bare};
578 } else {
579 694 $node->[NODE_TYPE] = TYPE_ATT_NAMEONLY;
580 694 @{$node}[NODE_BEGIN, NODE_END, NODE_LNO] = @common;
581 694 $node->[NODE_PATH] = split_ns($m->{bare});
582 }
583 ▶ } elsif ($+{entity} or $+{special}) {
Condition66%2/3
$+{"entity"} or $+{"special"}
l!l&&r!l&&!r
40308
MC/DC50%1/2
$+{"entity"} or $+{"special"}
$+{"entity"} $+{"special"}
Truth table66%2/3
A or B
A= $+{"entity"}B= $+{"special"}
ABresult
1X1
011
000
584 # XXX: 間に space が入ってたら?
585 4 ▶ if ($m->{lcmsg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{"lcmsg"}) 0 4 4
586 die $self->synerror_at($self->{_startln}
587 0 , q{l10n msg is not allowed here});
588 }
589 4 $node->[NODE_TYPE] = TYPE_ATT_TEXT;
590 4 @{$node}[NODE_BEGIN, NODE_END, NODE_LNO, NODE_PATH] = $mklval->();
591  
592 # Below is a workaround for unclosed `<!yatt:args` with `&yatt:var;`
593 # There would be a better way to handle this...
594 4 $_ = $$strref;
595  
596 4 $node->[NODE_BODY] = [$self->mkentity(@common)];
597 4 $node->[NODE_END] = $self->{_curpos};
598 } else {
599 308 my ($quote, $value) = oneof($m, qw(bare sq dq));
600 308 $node->[NODE_TYPE] = TYPE_ATT_TEXT;
601 308 @{$node}[NODE_BEGIN, NODE_END, NODE_LNO, NODE_PATH] = $mklval->();
602 308 ▶ $node->[NODE_BODY_BEGIN] = $start + ($quote ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$quote ? : 280 28 308
603 308 ▶ splice @$node, NODE_BODY, 0, (
Branch: 1 branch
BranchTrueFalseTotal
$for_decl ? : 146 162 308
604 $for_decl ? $value : $self->_parse_text_entities_at(
605 $node->[NODE_BODY_BEGIN], $value
606 )
607 );
608 }
609 };
610 1129 $node->[NODE_BODY_END] = $self->{_curpos};
611 }
612 }
613 # lvalue expression.
614 elsif (
615 # m->{equal} and
616 not @lvalue
617 ) {
618 # got lvalue =, continue to rvalue
619 383 ▶ if ($m->{bare} and is_ident($m->{bare})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($m->{'bare'} and is_ident($m->{'bare'})) { } 349 34 383
elsif ($m->{'nestclo'}) { } 34 0 34
Condition66%2/3
$m->{"bare"} and is_ident($m->{"bare"})
!ll&&!rl&&r
340349
MC/DC50%1/2
$m->{"bare"} and is_ident($m->{"bare"})
$m->{"bare"} is_ident($m->{"bare"})
Truth table66%2/3
A and B
A= $m->{"bare"}B= is_ident($m->{"bare"})
ABresult
0X0
100
111
620 349 @lvalue = (@common, split_ns($m->{bare}));
621 }
622 elsif ($m->{nestclo}) {
623 34 my ($s, $p, $l) = @common;
624 34 @lvalue = ($outer_start, undef, $l, [splice @result]);
625 }
626 else {
627 0 Carp::croak("unknown");
628 }
629 }
630 else {
631 # error
632 die $self->synerror_at(
633 $self->{_startln}
634 0 , q{assignment (=) after assignment (=) is not allowed}
635 );
636 }
637 } continue {
638 2746 $curln = $self->{_endln};
639 2746 ▶ $self->_verify_token($self->{_curpos}, $$strref) if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 2746 2746
640 }
641 982 ▶ wantarray ? @result : \@result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 982 0 982
642 }
643  
644 12 ▶sub mkargmacro {
Subroutine mkargmacro: called CC=4 SCAR=14.8
Pod undocumented
645 12 (my MY $self, my ($start, $string)) = @_;
646 12 local $_ = $string;
647  
648 12 my $node = [];
649 12 $node->[NODE_TYPE] = TYPE_ATT_MACRO;
650 12 @{$node}[NODE_BEGIN, NODE_END, NODE_LNO] = ($start, $self->{_curpos}, $self->{_startln});
651  
652 # namespace-less なケースも扱いたいので % を : に置換
653 12 s/^%/:/;
654  
655 # _parse_entpath だと curpos を移動させてしまうため
656 12 my (@path) = $self->_parse_pipeline;
657  
658 12 $node->[NODE_PATH] = do {
659 12 ▶ if (@path >= 2 and $path[0][0] eq 'var') {
Branch: 1 branch
BranchTrueFalseTotal
if (@path >= 2 and $path[0][0] eq 'var') { } 0 12 12
Condition33%1/3
@path >= 2 and $path[0][0] eq "var"
!ll&&!rl&&r
1200
MC/DC0%0/2
@path >= 2 and $path[0][0] eq "var"
@path >= 2 $path[0][0] eq "var"
Truth table33%1/3
A and B
A= @path >= 2B= $path[0][0] eq "var"
ABresult
0X0
100
111
660 0 my $head = shift @path;
661 0 $head->[1];
662 } else {
663 12 undef;
664 }
665 };
666  
667 12 splice @$node, NODE_BODY, 0, @path;
668  
669 12 ▶ if ($_ ne ';') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ ne ";") 0 12 12
670 die $self->synerror_at($self->{_startln}
671 0 , q{Invalid decl entity: %s (%s remains)}, $string, $_);
672 }
673  
674 12 $node;
675 }
676  
677 658 ▶sub mkentity {
Subroutine mkentity: called CC=3 SCAR=11.0
Pod undocumented
678 658 (my MY $self) = shift;
679 # assert @_ == 3;
680 658 my $node = [];
681 658 $node->[NODE_TYPE] = TYPE_ENTITY;
682 658 @{$node}[NODE_BEGIN, NODE_END, NODE_LNO] = @_;
683 658 ▶ if (my $ns = $+{entity}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $ns = $+{'entity'}) { } 656 2 658
elsif (my $special = $+{'special'}) { } 2 0 2
684 656 $node->[NODE_PATH] = $ns;
685 656 splice @$node, NODE_BODY, 0, $self->_parse_entpath;
686 } elsif (my $special = $+{special}) {
687 2 $node->[NODE_BODY] = [call => $special
688 , $self->_parse_entpath(_parse_entgroup => ')')];
689 } else {
690 0 die "mkentity called without entity or special";
691 }
692 657 $node->[NODE_END] = $self->{_curpos};
693 657 $node;
694 }
695  
696 1043 ▶sub split_ns {
Subroutine split_ns: called CC=3 SCAR=11.0
Pod undocumented
697 1043 ▶ defined (my $value = shift)
Branch: 1 branch
BranchTrueFalseTotal
defined(my $value = shift()) or return undef 1043 0 1043
698 or return undef; # make sure one scalar.
699 1043 local %+;
700 1043 my @names = split /:/, $value;
701 1043 ▶ @names > 1 ? \@names : $value;
Branch: 1 branch
BranchTrueFalseTotal
@names > 1 ? : 30 1013 1043
702 }
703  
704 # widget の body の構文については、 Template が規定してよい。
705 646 ▶sub parse_widget {
Subroutine parse_widget: called CC=4 SCAR=13.9
Pod undocumented
706 646 (my MY $self, my Widget $widget) = @_;
707 646 $self->{_startln} = $self->{_endln} = $widget->{bodyln};
708 # XXX: 戻り値でも良い気はする。とはいえ、デバッグは楽か。
709 646 ▶ local $self->{_chunklist} = my $chunks = [@{$widget->{_toks} //= []}];
Condition100%2/2
$widget->{"_toks"} //= []
l!l
6451
MC/DC100%1/1
$widget->{"_toks"} //= []
$widget->{"_toks"}
Truth table100%2/2
A
A= $widget->{"_toks"}
Aresult
11
00
710 646 ▶ local $_ = @$chunks && !ref $chunks->[0] ? shift @$chunks : '';
Branch: 1 branch
BranchTrueFalseTotal
@$chunks && !ref($chunks->[0]) ? : 638 8 646
Condition100%3/3
@$chunks and not ref $chunks->[0]
!ll&&!rl&&r
71638
MC/DC100%2/2
@$chunks and not ref $chunks->[0]
@$chunks not ref $chunks->[0]
Truth table100%3/3
A and not(B)
A= @$chunksB= not ref $chunks->[0]
ABresult
0X0
100
111
711 646 $self->{_startpos} = $self->{_curpos} = $widget->{bodypos};
712 646 $self->_parse_body($widget, $widget->{_tree} = []);
713 636 push @{$widget->{_tree}}, nonmatched($_); # XXX: nest 時以外
714 636 $widget;
715 }
716  
717 1214 ▶sub _get_chunk {
Subroutine _get_chunk: called CC=7 SCAR=19.5
718 1214 (my MY $self, my $sink) = @_;
719 1214 my $chunks = $self->{_chunklist};
720 1214 ▶ if (length $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_) 856 358 1214
721 856 ▶ push @$sink, $_ if $sink;
Branch: 1 branch
BranchTrueFalseTotal
if $sink 856 0 856
722 856 $self->{_startln} = $self->{_endln} += numLines($_);
723 856 $self->{_curpos} = $self->{_startpos} += length $_;
724 856 $_ = '';
725 }
726 # comment の読み飛ばし
727 1214 ▶ while (@$chunks and ref $chunks->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$chunks and ref $chunks->[0]) 16 1214 1230
Condition100%3/3
@$chunks and ref $chunks->[0]
!ll&&!rl&&r
63757716
MC/DC100%2/2
@$chunks and ref $chunks->[0]
@$chunks ref $chunks->[0]
Truth table100%3/3
A and B
A= @$chunksB= ref $chunks->[0]
ABresult
0X0
100
111
728 16 my $next = shift @$chunks;
729 16 ▶ push @$sink, $next if $sink;
Branch: 1 branch
BranchTrueFalseTotal
if $sink 16 0 16
730 16 $self->{_startln} = $self->{_endln} += $next->[NODE_BODY];
731 16 $self->{_curpos} = $self->{_startpos} = $next->[NODE_END];
732 }
733 1214 ▶ return unless @$chunks;
Branch: 1 branch
BranchTrueFalseTotal
unless @$chunks 637 577 1214
734 577 $_ = shift @$chunks;
735 577 1
736 }
737  
738 1346 ▶sub nonspace {
Subroutine nonspace: called CC=1 SCAR=0.0
Pod undocumented
739 1346 local (%+, $&, $1, $2);
740 1346 $_[0] =~ /\S/;
741 }
742  
743 752 ▶sub splitline {
Subroutine splitline: called CC=1 SCAR=0.0
Pod undocumented
744 752 local (%+, $&, $1, $2);
745 752 split /(?<=\n)/, $_[0];
746 }
747  
748 0 ▶sub _verify_token {
Subroutine _verify_token: not called CC=4 SCAR=30.0
749 0 (my MY $self, my $pos) = splice @_, 0, 2;
750 0 ▶ unless (defined $pos) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pos) 0 0 0
751 0 die $self->synerror_at($self->{_startln}, q{Token pos is undef!: now='%s'}, $_[0]);
752 }
753 0 my $tok = $self->{_template}->source_substr($pos, length $_[0]);
754 0 ▶ unless (defined $tok) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tok) 0 0 0
755 0 die $self->synerror_at($self->{_startln}, q{Token substr is empty!: now='%s'}, $_[0]);
756 }
757 0 ▶ unless ($tok eq $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tok eq $_[0]) 0 0 0
758 0 die $self->synerror_at($self->{_startln}, q{Token mismatch!: substr='%s', now='%s'}
759 , $tok, $_[0]);
760 }
761 }
762  
763 11 ▶sub drop_leading_ws {
Subroutine drop_leading_ws: called CC=3 SCAR=11.0
Pod undocumented
764 11 my $list = shift;
765 11 local (%+, $1, $2, $&);
766 11 ▶ pop @$list while @$list and $list->[-1] =~ /^\s*$/s;
Branch: 1 branch
BranchTrueFalseTotal
@$list and $list->[-1] =~ /^\s*$/s and do { pop @$list } 16 11 27
Condition66%2/3
@$list and $list->[-1] =~ /^\s*$/s
!ll&&!rl&&r
11016
MC/DC50%1/2
@$list and $list->[-1] =~ /^\s*$/s
@$list $list->[-1] =~ /^\s*$/s
Truth table66%2/3
A and B
A= @$listB= $list->[-1] =~ /^\s*$/s
ABresult
0X0
100
111
767 }
768  
769 #========================================
770 # build($ns, $kind, $partName, @attlist)
771 732 ▶sub build {
Subroutine build: called CC=1 SCAR=0.0
Pod undocumented
772 732 (my MY $self, my ($ns, $decl, $kind, $partName, @rest)) = @_;
773 732 local %+;
774 $self->can("build_$kind")->
775 ($self, name => $partName, decl => $decl, kind => $kind
776 , namespace => $ns
777 , folder => $self->{_template}
778 732 , startpos => $self->{_startpos}, @rest);
779 }
780  
781 213 ▶sub build_widget { shift->Widget->new(@_) }
Subroutine build_widget: called CC=1 SCAR=0.0
Pod undocumented
782 457 ▶sub build_page { shift->Page->new(@_) }
Subroutine build_page: called CC=1 SCAR=0.0
Pod undocumented
783 15 ▶sub build_action { shift->Action->new(@_) }
Subroutine build_action: called CC=1 SCAR=0.0
Pod undocumented
784 0 ▶sub build_data { shift->Data->new(@_) }
Subroutine build_data: not called CC=1 SCAR=6.9
Pod undocumented
785  
786 16 ▶sub build_entity { shift->Entity->new(@_) }
Subroutine build_entity: called CC=1 SCAR=0.0
Pod undocumented
787  
788 11 ▶sub build_argmacro { shift->ArgMacro->new(@_) }
Subroutine build_argmacro: called CC=1 SCAR=0.0
Pod undocumented
789  
790 20 ▶sub build_import { shift->Import->new(@_) }
Subroutine build_import: called CC=1 SCAR=0.0
Pod undocumented
791  
792 #========================================
793 # declare
794 20 ▶sub declare_base {
Subroutine declare_base: called CC=2 SCAR=6.9
Pod undocumented
795 20 (my MY $self, my Template $tmpl, my ($ns, @args)) = @_;
796  
797 # Accept empty '<!yatt:base>' declaration as nop for parser testing aid.
798 20 ▶ $self->{vfs}->declare_base($self, $tmpl, $ns, @args)
Branch: 1 branch
BranchTrueFalseTotal
if @args 18 2 20
799 if @args;
800  
801 19 undef;
802 }
803  
804 # <!yatt:import [name...]="file" [name...]="file2" ...> (GH-256)
805 # name := srcName | local=srcName | srcName:kind | local=srcName:kind
806 # kind := widget | page | action | entity | argmacro
807 # (無注釈はソース内で一意な場合のみ自動判定)
808 # kind の妥当性は vfs 側の _find_kind_part__$kind の有無で判定する
809 # (find_kind_part_from dispatch。kind 追加時に LRXML の変更は不要)
810  
811 29 ▶sub declare_import {
Subroutine declare_import: called CC=4 SCAR=14.1
Pod undocumented
812 29 (my MY $self, my Template $tmpl, my ($ns, @args)) = @_;
813  
814 29 ▶ unless (@args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 0 29 29
815 0 die $self->synerror_at($self->{_startln}, q{No import arg});
816 }
817  
818 29 foreach my $att (@args) {
819 29 my ($specs, $fn) = $self->cut_import_spec($att);
820 29 my Template $src = $self->{vfs}->import_resolve_source($self, $tmpl, $fn);
821 27 foreach my $spec (@$specs) {
822 29 $self->import_1($tmpl, $ns, $src, @$spec);
823 }
824 }
825  
826 21 undef;
827 }
828  
829 # ブラケット群 [name...]="file" を ([[local, srcName, kind], ...], $fn) に分解する。
830 29 ▶sub cut_import_spec {
Subroutine cut_import_spec: called CC=18 SCAR=34.0
Pod undocumented
831 29 (my MY $self, my $att) = @_;
832  
833 29 my $names = $att->[NODE_PATH];
834 29 ▶ unless ($att->[NODE_TYPE] == TYPE_ATT_TEXT
Branch: 1 branch
BranchTrueFalseTotal
unless ($att->[0] == 8 and ref $names eq "ARRAY" and not grep({not ref $_;} @$names)) 0 29 29
Condition33%2/6
$att->[0] == 8 and ref $names eq "ARRAY" and not grep({not ref $_;} @$names)
!ll&&!rl&&r
0029
$att->[0] == 8 and ref $names eq "ARRAY"
!ll&&!rl&&r
0029
MC/DC0%0/3
$att->[0] == 8 and ref $names eq "ARRAY" and not grep({not ref $_;} @$names)
$att->[0] == 8 ref $names eq "ARRAY" not grep({not ref $_;} @$names)
Truth table25%1/4
A and B and not(C)
A= $att->[0] == 8B= ref $names eq "ARRAY"C= not grep({not ref $_;} @$names)
ABCresult
0XX0
10X0
1100
1111
835 and ref $names eq 'ARRAY'
836 31 and not grep {not ref $_} @$names) {
837 die $self->synerror_at($self->{_startln}
838 0 , q{import decl must use bracket form like [name...]="file"});
839 }
840  
841 29 my $fn = $att->[NODE_BODY];
842  
843 29 my @specs;
844 29 foreach my $node (@$names) {
845 31 my ($local, $srcSpec);
846 31 my $type = $node->[NODE_TYPE];
847 31 ▶ if ($type == TYPE_ATT_NAMEONLY) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 6) { } 24 7 31
elsif ($type == 7 or $type == 8) { } 7 0 7
848 # srcName または srcName:kind (split_ns 済み)
849 24 $srcSpec = $node->[NODE_PATH];
850 ▶ } elsif ($type == TYPE_ATT_BARENAME or $type == TYPE_ATT_TEXT) {
Condition33%1/3
$type == 7 or $type == 8
l!l&&r!l&&!r
700
MC/DC0%0/2
$type == 7 or $type == 8
$type == 7 $type == 8
Truth table33%1/3
A or B
A= $type == 7B= $type == 8
ABresult
1X1
011
000
851 # local=srcName または local="srcName:kind"
852 7 $local = $node->[NODE_PATH];
853 7 $srcSpec = $node->[NODE_BODY];
854 } else {
855 0 die $self->synerror_at($self->{_startln}, q{Invalid import name spec});
856 }
857  
858 31 ▶ if (ref $local) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $local) 0 31 31
859 die $self->synerror_at($self->{_startln}
860 0 , q{Invalid local name for import: %s}
861 , join(":", @$local));
862 }
863  
864 31 my ($srcName, $kind) = do {
865 31 ▶ if (ref $srcSpec eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $srcSpec eq 'ARRAY') { } 5 26 31
elsif (defined $srcSpec and $srcSpec =~ /^([^:]+):([^:]+)$/) { } 5 21 26
866 5 ▶ unless (@$srcSpec == 2) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$srcSpec == 2) 0 5 5
867 die $self->synerror_at($self->{_startln}
868 0 , q{Invalid import name spec: %s}
869 , join(":", @$srcSpec));
870 }
871 5 @$srcSpec;
872 ▶ } elsif (defined $srcSpec and $srcSpec =~ /^([^:]+):([^:]+)$/) {
Condition66%2/3
defined $srcSpec and $srcSpec =~ /^([^:]+):([^:]+)$/
!ll&&!rl&&r
0215
MC/DC50%1/2
defined $srcSpec and $srcSpec =~ /^([^:]+):([^:]+)$/
defined $srcSpec $srcSpec =~ /^([^:]+):([^:]+)$/
Truth table66%2/3
A and B
A= defined $srcSpecB= $srcSpec =~ /^([^:]+):([^:]+)$/
ABresult
0X0
100
111
873 5 ($1, $2);
874 } else {
875 21 ($srcSpec, undef);
876 }
877 };
878  
879 31 ▶ unless (defined $srcName and $srcName ne '') {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $srcName and $srcName ne "") 0 31 31
Condition33%1/3
defined $srcName and $srcName ne ""
!ll&&!rl&&r
0031
MC/DC0%0/2
defined $srcName and $srcName ne ""
defined $srcName $srcName ne ""
Truth table33%1/3
A and B
A= defined $srcNameB= $srcName ne ""
ABresult
0X0
100
111
880 0 die $self->synerror_at($self->{_startln}, q{Invalid import name spec});
881 }
882 31 ▶ if (defined $kind and not $self->{vfs}->can("_find_kind_part__$kind")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kind and not $self->{"vfs"}->can("_find_kind_part__$kind")) 0 31 31
Condition66%2/3
defined $kind and not $self->{"vfs"}->can("_find_kind_part__$kind")
!ll&&!rl&&r
21100
MC/DC0%0/2
defined $kind and not $self->{"vfs"}->can("_find_kind_part__$kind")
defined $kind not $self->{"vfs"}->can("_find_kind_part__$kind")
Truth table66%2/3
A and not(B)
A= defined $kindB= not $self->{"vfs"}->can("_find_kind_part__$kind")
ABresult
0X0
100
111
883 die $self->synerror_at($self->{_startln}
884 0 , q{Unknown import kind '%s' for '%s'}
885 , $kind, $srcName);
886 }
887  
888 31 ▶ push @specs, [$local // $srcName, $srcName, $kind];
Condition66%2/3
$local // $srcName
l!l&&r!l&&!r
7240
MC/DC0%0/2
$local // $srcName
$local $srcName
Truth table66%2/3
A // B
A= $localB= $srcName
ABresult
1X1
011
000
889 }
890  
891 29 (\@specs, $fn);
892 }
893  
894 29 ▶sub import_1 {
Subroutine import_1: called CC=4 SCAR=14.5
Pod undocumented
895 29 (my MY $self, my Template $tmpl, my $ns, my Template $src
896 , my ($local, $srcName, $kind)) = @_;
897  
898 (my $ikind, my $found)
899 29 = $self->{vfs}->import_find_source_part($self, $src, $srcName, $kind);
900  
901 23 ▶ if ($ikind eq 'argmacro') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ikind eq 'argmacro') { } 3 20 23
902 3 ▶ if ($tmpl->{_argmacro_dict}{$local}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpl->{"_argmacro_dict"}{$local}) 0 3 3
903 die $self->synerror_at($self->{_startln}
904 , q{Duplicate argmacro %s in %s}
905 0 ▶ , $local, $tmpl->{path} // $tmpl->{name});
Condition0%0/3
$tmpl->{"path"} // $tmpl->{"name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tmpl->{"path"} // $tmpl->{"name"}
$tmpl->{"path"} $tmpl->{"name"}
Truth table0%0/3
A // B
A= $tmpl->{"path"}B= $tmpl->{"name"}
ABresult
1X1
011
000
906 }
907 # weak ref でも ArgMacro 自身の _on_declare 自己循環が生存を保証する
908 # (declare_argmacro と同じ)。
909 3 Scalar::Util::weaken($tmpl->{_argmacro_dict}{$local} = $found);
910 } else {
911 20 my Import $import = $self->build($ns, import => import => $local);
912 20 $import->{imported_kind} = $ikind;
913 20 $import->{src_name} = $srcName;
914 20 Scalar::Util::weaken($import->{src_folder} = $src);
915 # 本体を持たない part なので、位置情報だけ整えておく
916 # (fixup_template_foreach_part_posinfo が bodypos を要求する)
917 20 $import->{bodypos} = $self->{_curpos};
918 20 $import->{bodylen} = 0;
919 20 $self->add_part($tmpl, $import);
920 }
921 }
922  
923 228 ▶sub declare_args {
Subroutine declare_args: called CC=3 SCAR=11.0
Pod undocumented
924 228 (my MY $self, my Template $tmpl, my ($ns, @args)) = @_;
925 228 my $kind = 'args';
926 228 my $declkind = join(":", $ns, $kind);
927 my Widget $newpart = $self->cut_implicit_default_part($tmpl, $declkind)
928 || $self->build($ns, $kind => $self->default_part_for($tmpl), ''
929 228 ▶ , startln => $self->{_startln});
Condition66%2/3
$self->cut_implicit_default_part($tmpl, $declkind) || $self->build($ns, $kind, $self->default_part_for($tmpl), '', 'startln', $self->{'_startln'})
l!l&&r!l&&!r
52210
MC/DC0%0/2
$self->cut_implicit_default_part($tmpl, $declkind) || $self->build($ns, $kind, $self->default_part_for($tmpl), '', 'startln', $self->{'_startln'})
$self->cut_implicit_default_part($tmpl, $declkind) $self->build($ns, $kind, $self->default_part_for($tmpl), '', 'startln', $self->{'_startln'})
Truth table66%2/3
A || B
A= $self->cut_implicit_default_part($tmpl, $declkind)B= $self->build($ns, $kind, $self->default_part_for($tmpl), '', 'startln', $self->{'_startln'})
ABresult
1X1
011
000
930  
931 226 ▶ if (not grep {/\S/} @{$newpart->{_toks}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {/\S/;} @{$$newpart{"_toks"};}) 224 2 226
932 $newpart->configure(
933 # startpos => $self->{_curpos},
934 startln => $self->{_startln},
935 224 );
936 224 $newpart->{_toks} = [];
937 }
938  
939 226 $self->cut_root_route_and_install_url_params($newpart, \@args);
940  
941 # $newpart->{startpos} = $self->{_startpos};
942 # $newpart->{bodypos} = $self->{_curpos} + 1;
943 225 $self->add_part($tmpl, $newpart, 1); # partlist と Item に足し直す. no_conflict_check
944  
945 225 $self->add_args($newpart, @args);
946  
947 223 $newpart;
948 }
949  
950 234 ▶sub cut_implicit_default_part {
Subroutine cut_implicit_default_part: called CC=8 SCAR=20.8
Pod undocumented
951 234 (my MY $self, my Template $tmpl, my ($declkind)) = @_;
952 234 (my Part $oldpart, my @other) = $self->list_default_parts($tmpl);
953 234 ▶ unless (not $oldpart or $oldpart->{implicit}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (not $oldpart or $oldpart->{"implicit"}) 3 231 234
Condition100%3/3
not $oldpart or $oldpart->{"implicit"}
l!l&&r!l&&!r
22383
MC/DC100%2/2
not $oldpart or $oldpart->{"implicit"}
not $oldpart $oldpart->{"implicit"}
Truth table100%3/3
not(A) or B
A= not $oldpartB= $oldpart->{"implicit"}
ABresult
1X1
011
000
954 die $self->synerror_at($self->{_startln}
955 , q{<!%s> at line %d conflicts with <!%s>}
956 , $oldpart->syntax_keyword, $oldpart->{startln}
957 3 , $declkind);
958 }
959 231 ▶ if ($oldpart
Branch: 1 branch
BranchTrueFalseTotal
if ($oldpart and $tmpl->{'_partlist'} and @{$tmpl->{'_partlist'};} == 1 and $tmpl->{'_partlist'}[0] == $oldpart) { } 6 225 231
Condition77%7/9
$oldpart and $tmpl->{"_partlist"} and @{$tmpl->{"_partlist"};} == 1 and $tmpl->{"_partlist"}[0] == $oldpart
!ll&&!rl&&r
22506
$oldpart and $tmpl->{"_partlist"} and @{$tmpl->{"_partlist"};} == 1
!ll&&!rl&&r
22326
$oldpart and $tmpl->{"_partlist"}
!ll&&!rl&&r
22308
MC/DC50%2/4
$oldpart and $tmpl->{"_partlist"} and @{$tmpl->{"_partlist"};} == 1 and $tmpl->{"_partlist"}[0] == $oldpart
$oldpart $tmpl->{"_partlist"} @{$tmpl->{"_partlist"};} == 1 $tmpl->{"_partlist"}[0] == $oldpart
Truth table60%3/5
A and B and C and D
A= $oldpartB= $tmpl->{"_partlist"}C= @{$tmpl->{"_partlist"};} == 1D= $tmpl->{"_partlist"}[0] == $oldpart
ABCDresult
0XXX0
10XX0
110X0
11100
11111
960 8 and $tmpl->{_partlist} and @{$tmpl->{_partlist}} == 1
961 and $tmpl->{_partlist}[0] == $oldpart) {
962 # 先頭だったら再利用。
963 6 shift @{$tmpl->{_partlist}}; # == $oldpart
964 } else {
965 225 ▶ $oldpart->{suppressed} = 1 if $oldpart; # 途中なら、古いものを隠して、新たに作り直し。
Branch: 1 branch
BranchTrueFalseTotal
if $oldpart 2 223 225
966  
967 225 return undef;
968 }
969 }
970  
971 226 ▶sub cut_root_route_and_install_url_params {
Subroutine cut_root_route_and_install_url_params: called CC=8 SCAR=21.2
Pod undocumented
972 226 (my MY $self, my Part $part, my ($argList)) = @_;
973  
974 226 ▶ return unless @$argList and $argList->[0]
Branch: 1 branch
BranchTrueFalseTotal
unless @$argList and $argList->[0] and $argList->[0][0] == 8 and not defined $argList->[0][7] 222 4 226
Condition88%8/9
@$argList and $argList->[0] and $argList->[0][0] == 8 and not defined $argList->[0][7]
!ll&&!rl&&r
21394
@$argList and $argList->[0] and $argList->[0][0] == 8
!ll&&!rl&&r
4616713
@$argList and $argList->[0]
!ll&&!rl&&r
460180
MC/DC75%3/4
@$argList and $argList->[0] and $argList->[0][0] == 8 and not defined $argList->[0][7]
@$argList $argList->[0] $argList->[0][0] == 8 not defined $argList->[0][7]
Truth table80%4/5
A and B and C and not(D)
A= @$argListB= $argList->[0]C= $argList->[0][0] == 8D= not defined $argList->[0][7]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
975 and $argList->[0][NODE_TYPE] == TYPE_ATT_TEXT
976 and not defined $argList->[0]->[NODE_PATH];
977  
978 4 my $patNode = shift @$argList;
979 4 ▶ if (ref $patNode->[NODE_BODY]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $patNode->[8]) 1 3 4
980 1 my $t = $YATT::Lite::Constants::TYPE_[$patNode->[NODE_BODY][0][NODE_TYPE]];
981 die $self->synerror_at($self->{_startln}
982 1 , q{%s got wrong token for route spec: %s}
983 , $part->syntax_keyword, $t);
984  
985 }
986 my $mapping = $self->parse_location($patNode->[NODE_BODY], '', $part)
987 3 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
my $mapping = $self->parse_location($patNode->[8], "", $part) or do { die $self->synerror_at($self->{"_startln"}, "Invalid route spec in %s - \"%s\"", $part->syntax_keyword, $patNode->[8]) } 3 0 3
988 die $self->synerror_at($self->{_startln}
989 0 , q{Invalid route spec in %s - "%s"}
990 , $part->syntax_keyword, $patNode->[NODE_BODY]);
991 };
992 3 ▶ if ($self->{match_argsroute_first}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'match_argsroute_first'}) { } 0 3 3
993 0 $self->{_rootroute} = $mapping;
994 } else {
995 3 $self->{_subroutes}->append($mapping);
996 }
997 3 $self->add_url_params($part, lexpand($mapping->cget('params')));
998  
999 }
1000  
1001 17 ▶sub declare_action {
Subroutine declare_action: called CC=5 SCAR=16.1
Pod undocumented
1002 17 (my MY $self, my Template $tmpl, my ($ns, @args)) = @_;
1003 17 my $kind = 'action';
1004 17 my $declkind = join(":", $ns, $kind);
1005  
1006 17 my ($partName, $mapping) = $self->cut_partname_and_route($declkind, \@args);
1007  
1008 17 ▶ if ($partName eq '' and not $mapping) {
Branch: 1 branch
BranchTrueFalseTotal
if ($partName eq "" and not $mapping) 6 11 17
Condition66%2/3
$partName eq "" and not $mapping
!ll&&!rl&&r
1106
MC/DC50%1/2
$partName eq "" and not $mapping
$partName eq "" not $mapping
Truth table66%2/3
A and not(B)
A= $partName eq ""B= not $mapping
ABresult
0X0
100
111
1009 # implicit な page は suppress
1010 # explicit な page は構文エラー(再利用は出来ない)
1011 6 my $declname = "$declkind ''";
1012 6 ▶ if (my Part $implicit = $self->cut_implicit_default_part($tmpl, $declname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my YATT::Lite::Core::Part $implicit = $self->cut_implicit_default_part($tmpl, $declname)) 1 4 5
1013 die $self->synerror_at($self->{_startln}
1014 1 , q{<!%s> conflicts with name-less default widget}
1015 , "$declkind ''");
1016 }
1017 }
1018  
1019 15 my Part $newpart = $self->build($ns, $kind => $kind, $partName, startln => $self->{_startln});
1020  
1021 15 $self->add_part($tmpl, $newpart, 1); # partlist と Item に足し直す. no_conflict_check
1022  
1023 15 ▶ if ($mapping) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mapping) 4 11 15
1024 4 $self->add_route($newpart, $mapping);
1025 }
1026  
1027 15 $self->add_args($newpart, @args);
1028  
1029 15 $newpart;
1030 }
1031  
1032 234 ▶sub list_default_parts {
Subroutine list_default_parts: called CC=3 SCAR=11.0
Pod undocumented
1033 234 (my MY $self, my Template $tmpl) = @_;
1034 234 ▶ return unless $tmpl->{_partlist};
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpl->{"_partlist"} 217 17 234
1035 grep {
1036 19 my Part $part = $_;
1037 19 ▶ $part->{name} eq '' and not $part->{suppressed};
Condition66%2/3
$part->{'name'} eq '' && !$part->{'suppressed'}
!ll&&!rl&&r
8011
MC/DC50%1/2
$part->{'name'} eq '' && !$part->{'suppressed'}
$part->{'name'} eq '' !$part->{'suppressed'}
Truth table66%2/3
A && not(B)
A= $part->{'name'} eq ''B= !$part->{'suppressed'}
ABresult
0X0
100
111
1038 17 } @{$tmpl->{_partlist}};
1039 }
1040  
1041 # <!yatt:config cf=value...>
1042 4 ▶sub declare_config {
Subroutine declare_config: called CC=2 SCAR=6.9
Pod undocumented
1043 4 (my MY $self, my Template $tmpl, my ($ns, @args)) = @_;
1044 # XXX: 一方が undef だったら?
1045 4 ▶ $tmpl->configure(map {($_->[NODE_PATH], $_->[NODE_BODY] // 1)} @args);
Condition100%2/2
$_->[8] // 1
l!l
31
MC/DC100%1/1
$_->[8] // 1
$_->[8]
Truth table100%2/2
A
A= $_->[8]
Aresult
11
00
1046 4 undef;
1047 }
1048  
1049 0 ▶sub declare_constants {
Subroutine declare_constants: not called CC=1 SCAR=6.9
Pod undocumented
1050 0 (my MY $self, my Template $tmpl, my ($ns, @args)) = @_;
1051 0 $tmpl->{constants} = \@args;
1052 0 undef;
1053 }
1054  
1055 # <!yatt:argmacro macroName=[...output_args...] ...args>
1056 11 ▶sub declare_argmacro {
Subroutine declare_argmacro: called CC=4 SCAR=15.6
Pod undocumented
1057 11 (my MY $self, my Template $tmpl, my ($ns, @args)) = @_;
1058 11 my $kind = 'argmacro';
1059 11 my $declkind = join(":", $ns, $kind);
1060  
1061 11 ▶ my $nameAtt = YATT::Lite::Constants::cut_first_att(\@args) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $nameAtt = YATT::Lite::Constants::cut_first_att(\@args) or do { die $self->synerror_at($self->{"_startln"}, "No part name in %s\\n%s", $declkind, nonmatched($tmpl->{"string"})) } 11 0 11
1062 die $self->synerror_at($self->{_startln}, q{No part name in %s\n%s}
1063 , $declkind
1064 0 , nonmatched($tmpl->{string}));
1065 };
1066  
1067 11 my $partName = $nameAtt->[NODE_PATH];
1068  
1069 11 my $output_args = do {
1070 11 ▶ if ($nameAtt->[NODE_TYPE] == TYPE_ATT_NESTED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nameAtt->[0] == 9) { } 11 0 11
1071 11 $nameAtt->[NODE_BODY]
1072 } else {
1073 0 my $node = [];
1074 0 $node->[NODE_TYPE] = TYPE_ATT_NAMEONLY;
1075 0 $node->[NODE_PATH] = $partName;
1076 0 [$node];
1077 }
1078 };
1079  
1080 11 ▶ if ($tmpl->{_argmacro_dict}{$partName}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpl->{"_argmacro_dict"}{$partName}) 0 11 11
1081 0 die $self->synerror_at($self->{_startln}, q{Duplicate argmacro %s in %s}
1082 , $partName
1083 , $declkind);
1084 }
1085  
1086 my Part $newpart = $self->build(
1087 $ns, $kind => $kind, $partName, startln => $self->{_startln},
1088 11 output_args => $output_args,
1089 );
1090  
1091 11 Scalar::Util::weaken($tmpl->{_argmacro_dict}{$partName} = $newpart);
1092  
1093 11 $self->add_args($newpart, @args);
1094  
1095 11 $newpart;
1096 }
1097  
1098 704 ▶sub finalize_part {
Subroutine finalize_part: called CC=2 SCAR=6.9
Pod undocumented
1099 704 (my MY $self, my Part $part) = @_;
1100 my $finalizer = $self->can("finalize__" . $part->{kind})
1101 704 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
my $finalizer = $self->can('finalize__' . $part->{"kind"}) or return 11 693 704
1102 11 $finalizer->($self, $part)
1103 }
1104  
1105 11 ▶sub finalize__argmacro {
Subroutine finalize__argmacro: called CC=1 SCAR=0.0
Pod undocumented
1106 11 (my MY $self, my ArgMacro $argmacro) = @_;
1107 11 require YATT::Lite::CGen::ArgMacro;
1108 my $builder = YATT::Lite::CGen::ArgMacro->new(
1109 vfs => $self->{vfs}
1110 11 );
1111  
1112 $argmacro->{_on_declare} = $builder->with_template(
1113 $self->{_template},
1114 11 generate_on_declare => ($argmacro),
1115 );
1116  
1117 11 $argmacro;
1118 }
1119  
1120 #========================================
1121  
1122 37 ▶sub location2name {
Subroutine location2name: called CC=1 SCAR=0.0
Pod undocumented
1123 37 (my MY $self, my $location) = @_;
1124 37 $location =~ s{([^A-Za-z0-9])}{'_'.sprintf("%02x", unpack("C", $1))}eg;
1125 37 $location;
1126 }
1127  
1128 44 ▶sub parse_location {
Subroutine parse_location: called CC=2 SCAR=7.1
Pod undocumented
1129 44 (my MY $self, my ($location, $name, $item)) = @_;
1130 44 ▶ return unless $location =~ m{^/};
Branch: 1 branch
BranchTrueFalseTotal
unless $location =~ m[^/] 0 44 44
1131 44 $self->subroutes->create([$name, $location], $item);
1132 }
1133  
1134 44 ▶sub subroutes {
Subroutine subroutes: called CC=2 SCAR=7.1
Pod undocumented
1135 44 (my MY $self) = @_;
1136 44 ▶ $self->{_subroutes} //= $self->SubRoutes->new;
Condition66%2/3
$self->{"_subroutes"} //= $self->SubRoutes->new
l!l&&r!l&&!r
20240
MC/DC0%0/2
$self->{"_subroutes"} //= $self->SubRoutes->new
$self->{"_subroutes"} $self->SubRoutes->new
Truth table66%2/3
A //= B
A= $self->{"_subroutes"}B= $self->SubRoutes->new
ABresult
1X1
011
000
1137 }
1138  
1139 24 ▶sub SubRoutes {
Subroutine SubRoutes: called CC=1 SCAR=0.0
Pod undocumented
1140 24 require YATT::Lite::WebMVC0::SubRoutes;
1141 24 'YATT::Lite::WebMVC0::SubRoutes'
1142 }
1143  
1144 #========================================
1145 214 ▶sub primary_ns {
Subroutine primary_ns: called CC=2 SCAR=7.6
Pod undocumented
1146 214 my MY $self = shift;
1147 214 ▶ unless ($self->{namespace}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'namespace'}) { } 214 0 214
1148 0 'yatt';
1149 } else {
1150 214 first($self->{namespace});
1151 }
1152 }
1153 940 ▶sub namespace {
Subroutine namespace: called CC=4 SCAR=15.6
Pod undocumented
1154 940 my MY $self = shift;
1155 940 ▶ return unless defined $self->{namespace};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"namespace"} 0 940 940
1156 ref $self->{namespace} && wantarray
1157 940 ? @{$self->{namespace}}
1158 940 ▶ : $self->{namespace};
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'namespace'} && wantarray ? : 940 0 940
Condition33%1/3
ref $self->{"namespace"} and wantarray
!ll&&!rl&&r
00940
MC/DC0%0/2
ref $self->{"namespace"} and wantarray
ref $self->{"namespace"} wantarray
Truth table33%1/3
A and B
A= ref $self->{"namespace"}B= wantarray
ABresult
0X0
100
111
1159 }
1160  
1161 #========================================
1162 725 ▶sub add_part {
Subroutine add_part: called CC=5 SCAR=16.1
Pod undocumented
1163 725 (my MY $self, my Template $tmpl, my Part $part, my $no_conflict_check) = @_;
1164 725 my $itemKey = $part->item_key;
1165 725 ▶ if (not $no_conflict_check and defined $tmpl->{_Item}{$itemKey}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $no_conflict_check and defined $tmpl->{"_Item"}{$itemKey}) 2 723 725
Condition100%3/3
not $no_conflict_check and defined $tmpl->{"_Item"}{$itemKey}
!ll&&!rl&&r
2404832
MC/DC100%2/2
not $no_conflict_check and defined $tmpl->{"_Item"}{$itemKey}
not $no_conflict_check defined $tmpl->{"_Item"}{$itemKey}
Truth table100%3/3
not(A) and B
A= not $no_conflict_checkB= defined $tmpl->{"_Item"}{$itemKey}
ABresult
0X0
100
111
1166 2 die $self->synerror_at($self->{_startln}, q{Conflicting part name! '%s'}, $part->{name});
1167 }
1168 723 ▶ if ($tmpl->{_partlist} and my Part $prev = $tmpl->{_partlist}[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpl->{"_partlist"} and my YATT::Lite::Core::Part $prev = $tmpl->{"_partlist"}[-1]) 245 478 723
Condition100%3/3
$tmpl->{"_partlist"} and my YATT::Lite::Core::Part $prev = $tmpl->{"_partlist"}[-1]
!ll&&!rl&&r
4735245
MC/DC100%2/2
$tmpl->{"_partlist"} and my YATT::Lite::Core::Part $prev = $tmpl->{"_partlist"}[-1]
$tmpl->{"_partlist"} my YATT::Lite::Core::Part $prev = $tmpl->{"_partlist"}[-1]
Truth table100%3/3
A and B
A= $tmpl->{"_partlist"}B= my YATT::Lite::Core::Part $prev = $tmpl->{"_partlist"}[-1]
ABresult
0X0
100
111
1169 245 $prev->{endln} = $self->{_endln};
1170 }
1171 723 $part->{startln} = $self->{_startln};
1172 723 $part->{bodyln} = $self->{_endln};
1173 723 push @{$tmpl->{_partlist}}, $tmpl->{_Item}{$itemKey} = $part;
1174 }
1175  
1176 41 ▶sub add_route {
Subroutine add_route: called CC=1 SCAR=0.0
Pod undocumented
1177 41 (my MY $self, my Part $part, my $mapping) = @_;
1178 41 $mapping->configure(item => $part);
1179 41 $self->{_subroutes}->append($mapping);
1180 41 $self->add_url_params($part, lexpand($mapping->cget('params')));
1181 }
1182  
1183 262 ▶sub add_text {
Subroutine add_text: called CC=1 SCAR=0.0
Pod undocumented
1184 262 (my MY $self, my Part $part, my $text) = @_;
1185 262 push @{$part->{_toks}}, $text;
1186 262 $self->add_posinfo(length($text), 1);
1187 262 $self->{_startln} = $self->{_endln} += numLines($text);
1188 }
1189  
1190 1038 ▶sub add_lineinfo {
Subroutine add_lineinfo: called CC=1 SCAR=0.0
Pod undocumented
1191 1038 (my MY $self, my $sink) = @_;
1192 # push @$sink, [TYPE_LINEINFO, $self->{_endln}];
1193 }
1194  
1195 491 ▶sub parse_arg_spec_for_part {
Subroutine parse_arg_spec_for_part: called CC=3 SCAR=11.1
Pod undocumented
1196 491 (my MY $self, my Part $part, my $attNode) = @_;
1197 my ($node_type, $lno, $argName, $desc)
1198 491 = @{$attNode}[NODE_TYPE, NODE_LNO, NODE_PATH, NODE_BODY];
1199 491 my ($type, $dflag, $default);
1200 491 ▶ if ($node_type == TYPE_ATT_NESTED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node_type == 9) { } 14 477 491
1201 14 my $headDesc = $desc->[0];
1202 14 ▶ $type = $headDesc->[NODE_PATH] || $headDesc->[NODE_BODY];
Condition33%1/3
$headDesc->[7] || $headDesc->[8]
l!l&&r!l&&!r
1400
MC/DC0%0/2
$headDesc->[7] || $headDesc->[8]
$headDesc->[7] $headDesc->[8]
Truth table33%1/3
A || B
A= $headDesc->[7]B= $headDesc->[8]
ABresult
1X1
011
000
1203 # primary of [primary key=val key=val] # delegate:foo の時は BODY に入る?
1204 } else {
1205 477 ($type, $dflag, $default) = $self->parse_type_dflag_default($desc);
1206 };
1207 491 ($type, $argName, nextArgNo($part)
1208 , $lno, $node_type, $dflag
1209 , $default);
1210 }
1211  
1212 534 ▶sub add_args {
Subroutine add_args: called CC=12 SCAR=25.7
Pod undocumented
1213 534 (my MY $self, my Part $part) = splice @_, 0, 2;
1214 534 foreach my $argSpec (@_) {
1215  
1216 # XXX: comment もあるし、 %yatt:argmacro; もある。
1217 502 ▶ if ($argSpec->[NODE_TYPE] == TYPE_ATT_MACRO) {
Branch: 1 branch
BranchTrueFalseTotal
if ($argSpec->[0] == 10) 12 490 502
1218 12 $self->add_argmacro($part, $argSpec);
1219 12 next;
1220 }
1221  
1222 490 my ($type, $argName, $nextArgNo, $lno, $node_type, $dflag, $default)
1223 = my @argSpec = $self->parse_arg_spec_for_part($part, $argSpec);
1224 490 ▶ unless (defined $argName) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $argName) 1 489 490
1225 # argmacro と勘違いして &yatt:argmacro; と書いた時に気づきやすいように
1226 1 ▶ if ($argSpec->[NODE_TYPE] == TYPE_ATT_TEXT
Branch: 1 branch
BranchTrueFalseTotal
if ($argSpec->[0] == 8 and @{$argSpec->[8];} == 1 and +(my $entity = $argSpec->[8][0])->[0] == 3) { } 1 0 1
Condition33%2/6
$argSpec->[0] == 8 and @{$argSpec->[8];} == 1 and +(my $entity = $argSpec->[8][0])->[0] == 3
!ll&&!rl&&r
001
$argSpec->[0] == 8 and @{$argSpec->[8];} == 1
!ll&&!rl&&r
001
MC/DC0%0/3
$argSpec->[0] == 8 and @{$argSpec->[8];} == 1 and +(my $entity = $argSpec->[8][0])->[0] == 3
$argSpec->[0] == 8 @{$argSpec->[8];} == 1 +(my $entity = $argSpec->[8][0])->[0] == 3
Truth table25%1/4
A and B and C
A= $argSpec->[0] == 8B= @{$argSpec->[8];} == 1C= +(my $entity = $argSpec->[8][0])->[0] == 3
ABCresult
0XX0
10X0
1100
1111
1227 1 and @{$argSpec->[NODE_BODY]} == 1
1228 and (my $entity = $argSpec->[NODE_BODY][0])->[NODE_TYPE]
1229 == TYPE_ENTITY) {
1230 die $self->synerror_at(
1231 $self->{_startln},
1232 'Use of entity(%s) is not allowed here. (Did you mean %%%s;?)',
1233 1 $self->{_template}->node_source($argSpec),
1234 $entity->[NODE_BODY][1],
1235 );
1236 } else {
1237 die $self->synerror_at(
1238 $self->{_startln}, 'Invalid argument spec: %s',
1239 0 $self->{_template}->node_source($argSpec),
1240 );
1241 }
1242 }
1243  
1244 489 ▶ if (my $var = $part->{_arg_dict}{$argName}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $var = $part->{'_arg_dict'}{$argName}) { } 1 488 489
1245 1 ▶ if ($var->from_route) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var->from_route) { } 1 0 1
1246 # Override $type, $dflag, $default of this var.
1247 1 $self->set_var_type($var, $type); # type is always overridden.
1248 1 $self->set_dflag_default_to($var, $dflag, $default);
1249 } else {
1250 die $self->synerror_at($self->{_startln}
1251 , 'Argument %s redefined in %s %s'
1252 0 , $argName, $part->{kind}, $part->{name});
1253 }
1254 } else {
1255 488 my $var = $self->mkvar_at($self->{_startln}, @argSpec);
1256 487 $self->set_dflag_default_to($var, $dflag, $default);
1257  
1258 487 my $type = $var->type->[0];
1259 487 ▶ if ($node_type == TYPE_ATT_NESTED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node_type == 9) { } 14 473 487
1260 # XXX: [delegate:type ...], [code ...] の ... が来る
1261 # 仮想的な widget にする? のが一番楽そうではあるか。そうすれば add_args 出来る。
1262 # $self->add_arg_of_delegate/code/...へ。
1263 14 ▶ my $sub = $self->can("add_arg_of_type_$type") or do {
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $self->can("add_arg_of_type_$type") or do { die $self->synerror_at($self->{"_startln"}, "Unknown arg type in arg '%s': %s", $argName, $type) } 14 0 14
1264 0 die $self->synerror_at($self->{_startln}, "Unknown arg type in arg '%s': %s", $argName, $type)
1265 };
1266 14 $sub->($self, $part, $var, $argSpec->[NODE_BODY]);
1267 } else {
1268 473 ▶ if (my $sub = $self->can("add_arg_of_type_$type")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can("add_arg_of_type_$type")) { } 12 461 473
1269 12 $sub->($self, $part, $var, []);
1270 } else {
1271 461 push @{$part->{_arg_order}}, $argName;
1272 461 $part->{_arg_dict}{$argName} = $var;
1273 }
1274 }
1275 }
1276 }
1277 532 $self;
1278 }
1279  
1280 # %macroName(renameTo=renameFrom);
1281 12 ▶sub add_argmacro {
Subroutine add_argmacro: called CC=1 SCAR=0.0
Pod undocumented
1282 12 (my MY $self, my Part $part, my $node) = @_;
1283 # widget 宣言の中で argmacro を呼び出す
1284  
1285 12 my ArgMacro $argmacro = $self->find_argmacro($node);
1286  
1287 12 require YATT::Lite::CGen::ArgMacro;
1288 my $builder = YATT::Lite::CGen::ArgMacro->new(
1289 vfs => $self->{vfs}
1290 12 );
1291 $builder->with_template(
1292 $self->{_template},
1293 12 $argmacro->{_on_declare} => ($self, $part, $node)
1294 );
1295  
1296 12 return;
1297 }
1298  
1299 12 ▶sub find_argmacro {
Subroutine find_argmacro: called CC=5 SCAR=16.3
Pod undocumented
1300 12 (my MY $self, my $node) = @_;
1301  
1302 12 my $ns = $node->[NODE_PATH];
1303 12 my ($call, $macroName, $renameSpec) = @{$node->[NODE_BODY]};
1304  
1305 # XXX: %yatt:foo; namespace の扱い
1306  
1307 12 my Template $tmpl = $self->{_template};
1308 12 my ArgMacro $argmacro = $tmpl->{_argmacro_dict}{$macroName};
1309 12 ▶ return $argmacro if $argmacro;
Branch: 1 branch
BranchTrueFalseTotal
if $argmacro 11 1 12
1310  
1311 # XXX: ディレクトリからの追加を許すか否か、その場合の意味論…
1312 1 foreach my Part $part ($tmpl->list_base) {
1313 1 ▶ next unless $part->isa(Template);
Branch: 1 branch
BranchTrueFalseTotal
unless $part->isa("YATT::Lite::Core::Template") 0 1 1
1314 1 my Template $base = $part;
1315 1 ▶ if ($argmacro = $base->{_argmacro_dict}{$macroName}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($argmacro = $base->{"_argmacro_dict"}{$macroName}) 1 0 1
1316 1 return $argmacro
1317 }
1318 }
1319  
1320 0 die $self->synerror_at($node->[NODE_LNO]
1321 , "Unknown argmacro '%s'"
1322 , $macroName)
1323 }
1324  
1325 44 ▶sub add_url_params {
Subroutine add_url_params: called CC=2 SCAR=6.9
Pod undocumented
1326 44 (my MY $self, my Part $part, my @params) = @_;
1327 44 foreach my $param (@params) {
1328 8 my ($argName, $type_or_pat) = @$param;
1329 8 my $type = 'value'; # XXX: type_or_pat
1330 8 my $var = $self->mkvar_at($self->{_startln}, $type, $argName
1331 , nextArgNo($part));
1332 8 $var->from_route(1);
1333 8 push @{$part->{_arg_order}}, $argName;
1334 8 $part->{_arg_dict}{$argName} = $var;
1335 }
1336 }
1337  
1338 # code 型は仮想的な Widget を作る。
1339 22 ▶sub add_arg_of_type_code {
Subroutine add_arg_of_type_code: called CC=1 SCAR=0.0
Pod undocumented
1340 22 (my MY $self, my Part $part, my ($var, $attlist)) = @_;
1341 22 $var->widget(my Widget $virtual = $self->Widget->new(name => $var->varname));
1342 22 $self->add_args($virtual, @$attlist);
1343 22 my $argName = $var->varname;
1344 22 push @{$part->{_arg_order}}, $argName;
1345 22 $part->{_arg_dict}{$argName} = $var;
1346 }
1347  
1348 4 ▶sub add_arg_of_type_delegate {
Subroutine add_arg_of_type_delegate: called CC=15 SCAR=28.6
Pod undocumented
1349 4 (my MY $self, my Widget $widget, my ($var, $attlist)) = @_;
1350 # XXX: 引数でない変数も足さないと...
1351 4 my $name = $var->varname;
1352 # XXX: 既に有ったらエラーにしないと。
1353 4 $widget->{_var_dict}{$name} = $var;
1354 4 my ($type, @subtype) = @{$var->type};
1355 4 ▶ my @wpath = @subtype ? @subtype : $name;
Branch: 1 branch
BranchTrueFalseTotal
@subtype ? : 1 3 4
1356 my Widget $delegate = $self->{vfs}->find_part_from
1357 4 ▶ ($widget->{folder}, @wpath) or do {
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::Core::Widget $delegate = $self->{"vfs"}->find_part_from($widget->{"folder"}, @wpath) or do { $self->synerror_at($self->{"_startln"}, "Can't find delegate widget for argument %s=[%s]", $name, join(":", $type, @subtype)) } 4 0 4
1358 0 $self->synerror_at($self->{_startln}, "Can't find delegate widget for argument %s=[%s]", $name, join(":", $type, @subtype));
1359 };
1360 4 $var->weakened_set_widget($delegate);
1361 4 ▶ unless (Scalar::Util::isweak($var->[YATT::Lite::VarTypes::t_delegate::VSLOT_WIDGET])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::is_weak($var->[10])) 0 4 4
1362 0 die "Can't weaken!";
1363 }
1364 4 $var->delegate_vars(\ my %delegate_vars);
1365  
1366 4 my ($attDict, $excludeDict) = do {
1367 4 my (%attDict, %exclDict);
1368 4 foreach my $argSpec (@$attlist) {
1369 5 ▶ if (my $attName = $argSpec->[NODE_PATH]) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $attName = $argSpec->[7]) { } 4 1 5
elsif ($argSpec->[0] == 8 and ($attName) = $argSpec->[8] =~ /^-(\w+)$/) { } 1 0 1
1370 4 ▶ defined $attDict{$attName}
Branch: 1 branch
BranchTrueFalseTotal
defined $attDict{$attName} and die $self->synerror_at($argSpec->[3], "Duplicate argname '%s' in delegate var %s", $attName, $name) 0 4 4
1371 and die $self->synerror_at
1372 ($argSpec->[NODE_LNO]
1373 , "Duplicate argname '%s' in delegate var %s"
1374 , $attName, $name);
1375 4 $attDict{$attName} = $argSpec;
1376 ▶ } elsif ($argSpec->[NODE_TYPE] == TYPE_ATT_TEXT
Condition33%1/3
$argSpec->[0] == 8 and ($attName) = $argSpec->[8] =~ /^-(\w+)$/
!ll&&!rl&&r
001
MC/DC0%0/2
$argSpec->[0] == 8 and ($attName) = $argSpec->[8] =~ /^-(\w+)$/
$argSpec->[0] == 8 ($attName) = $argSpec->[8] =~ /^-(\w+)$/
Truth table33%1/3
A and B
A= $argSpec->[0] == 8B= ($attName) = $argSpec->[8] =~ /^-(\w+)$/
ABresult
0X0
100
111
1377 and ($attName) = $argSpec->[NODE_BODY] =~ /^-(\w+)$/) {
1378 1 ▶ if (not $delegate->{_arg_dict}{$attName}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($delegate->{"_arg_dict"}{$attName}) 0 1 1
1379 0 die $self->synerror_at
1380 ($argSpec->[NODE_LNO]
1381 , "No such argument '%s' in delegate to '%s'"
1382 , $attName, $name);
1383 }
1384 1 $exclDict{$attName} = $argSpec;
1385 } else {
1386 0 die $self->synerror_at
1387 ($argSpec->[NODE_LNO]
1388 , "Invalid decl spec for delegate var %s", $name);
1389 }
1390 }
1391 4 (\%attDict, \%exclDict);
1392 };
1393  
1394 4 foreach my $argName (@{$delegate->{_arg_order}}) {
1395 # 既に宣言されている名前は、足さない。
1396 9 ▶ next if $widget->{_arg_dict}{$argName};
Branch: 1 branch
BranchTrueFalseTotal
if $widget->{"_arg_dict"}{$argName} 0 9 9
1397  
1398 # Ignore [delegate -excluded_var]
1399 9 ▶ next if $excludeDict->{$argName};
Branch: 1 branch
BranchTrueFalseTotal
if $excludeDict->{$argName} 1 8 9
1400  
1401 8 $delegate_vars{$argName} = my $orig = $delegate->{_arg_dict}{$argName};
1402  
1403 8 my $actual = do {
1404 8 ▶ if (my $att = $attDict->{$argName}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $att = $attDict->{$argName}) { } 1 7 8
1405 1 my @new = $self->parse_arg_spec_for_part($widget, $att);
1406 1 ▶ $new[0] ||= $orig->[0];
Condition33%1/3
$new[0] ||= $orig->[0]
l!l&&r!l&&!r
010
MC/DC0%0/2
$new[0] ||= $orig->[0]
$new[0] $orig->[0]
Truth table33%1/3
A ||= B
A= $new[0]B= $orig->[0]
ABresult
1X1
011
000
1407 1 $self->mkvar_at($self->{_startln}, @new);
1408 } else {
1409 # clone して argno と lineno を変える。
1410 $self->mkvar_at($widget->{startln}, @$orig)
1411 7 ->argno(nextArgNo($widget))->lineno($widget->{startln});
1412 }
1413 };
1414 8 $widget->{_arg_dict}{$argName} = $actual;
1415 # XXX: lineno を widget の startln にするのは手抜き。本来は直前の arg のものを使うべき。
1416 8 push @{$widget->{_arg_order}}, $argName;
1417 }
1418 }
1419 506 ▶sub nextArgNo {
Subroutine nextArgNo: called CC=2 SCAR=6.9
Pod undocumented
1420 506 (my Part $part) = @_;
1421 506 ▶ $part->{_arg_order} ? scalar @{$part->{_arg_order}} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$part->{'_arg_order'} ? : 188 318 506
1422 }
1423  
1424 #========================================
1425 32 ▶sub synerror_at {
Subroutine synerror_at: called CC=1 SCAR=0.0
Pod undocumented
1426 32 (my MY $self, my $ln) = splice @_, 0, 2;
1427 32 my %opts = ($self->_tmpl_file_line($ln), depth => 2);
1428 32 $self->_error(\%opts, @_);
1429 }
1430  
1431 33 ▶sub _error {
Subroutine _error: called CC=2 SCAR=6.9
1432 33 (my MY $self, my ($opts, $fmt)) = splice @_, 0, 3;
1433 33 ▶ if (my $vfs = $self->{vfs}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $vfs = $self->{'vfs'}) { } 19 14 33
1434 19 $vfs->error($opts, $fmt, @_);
1435 } else {
1436 14 sprintf($fmt, @_);
1437 }
1438 }
1439  
1440 33 ▶sub _tmpl_file_line {
Subroutine _tmpl_file_line: called CC=3 SCAR=11.0
1441 33 (my MY $self, my $ln) = @_;
1442 33 ▶ ($$self{path} ? (tmpl_file => $$self{path}) : ()
Branch: 2 branches
BranchTrueFalseTotal
$self->{'path'} ? : 10 23 33
defined $ln ? : 23 10 33
1443 , defined $ln ? (tmpl_line => $ln) : ());
1444 }
1445  
1446 #========================================
1447 1192 ▶sub is_ident {
Subroutine is_ident: called CC=2 SCAR=7.1
Pod undocumented
1448 1192 ▶ return undef unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 1192 1192
1449 1192 local %+;
1450 1192 $_[0] =~ m{^[[:alpha:]_\:](?:\w+|:)*$}; # To exclude leading digit.
1451 }
1452  
1453 308 ▶sub oneof {
Subroutine oneof: called CC=3 SCAR=11.0
Pod undocumented
1454 308 my $hash = shift;
1455 308 my $i = 0;
1456 308 foreach my $key (@_) {
1457 854 ▶ if (defined(my $value = $hash->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = $hash->{$key})) 308 546 854
1458 308 return $i => $value;
1459 }
1460 } continue {
1461 546 $i++;
1462 }
1463 0 die "really??";
1464 }
1465  
1466 214 ▶sub first { ref $_[0] ? $_[0][0] : $_[0] }
Subroutine first: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 214 0 214
1467  
1468 1101 ▶sub nonmatched {
Subroutine nonmatched: called CC=3 SCAR=11.1
Pod undocumented
1469 1101 ▶ return unless defined $_[0] and length $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and length $_[0] 645 456 1101
Condition66%2/3
defined $_[0] and length $_[0]
!ll&&!rl&&r
0645456
MC/DC50%1/2
defined $_[0] and length $_[0]
defined $_[0] length $_[0]
Truth table66%2/3
A and B
A= defined $_[0]B= length $_[0]
ABresult
0X0
100
111
1470 456 $_[0];
1471 }
1472  
1473 8 ▶sub shortened_original_entpath {
Subroutine shortened_original_entpath: called CC=1 SCAR=0.0
Pod undocumented
1474 8 (my MY $self) = @_;
1475 8 my $str = $self->{_original_entpath};
1476 8 $str =~ s/\n.*\z//s;
1477 8 $str;
1478 }
1479  
1480 1 ▶sub _firstline_only {
Subroutine _firstline_only: called CC=1 SCAR=0.0
1481 1 my ($str) = @_;
1482 1 $str =~ s/\n.*\z/.../s;
1483 1 $str;
1484 }
1485  
1486 #========================================
1487  
1488 sub _parse_body;
1489  
1490 sub _parse_text_entities_at;
1491 sub _parse_text_entities;
1492 sub _parse_entpath;
1493 sub _parse_pipeline;
1494 sub _parse_entgroup;
1495 sub _parse_entterm;
1496 sub _parse_group_string;
1497 sub _parse_hash;
1498  
1499 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
1500  
1501 14 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=6 SCAR=19.5
1502 14 ▶ unless (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_[0]) 0 14 14
1503 0 confess "BUG! \$self isn't object!";
1504 }
1505 14 my $sub = our $AUTOLOAD;
1506 14 (my $meth = $sub) =~ s/.*:://;
1507 14 ▶ my $sym = $YATT::Lite::LRXML::{$meth}
Branch: 1 branch
BranchTrueFalseTotal
my $sym = $YATT::Lite::LRXML::{$meth} or croak("No such method: $meth") 14 0 14
1508 or croak "No such method: $meth";
1509 14 ▶ if ($meth =~ /ent|pipeline/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($meth =~ /ent|pipeline/) { } 5 9 14
elsif ($meth =~ /body/) { } 9 0 9
1510 require YATT::Lite::LRXML::ParseEntpath
1511 5 }
1512 elsif ($meth =~ /body/) {
1513 require YATT::Lite::LRXML::ParseBody
1514 9 }
1515 else {
1516 0 my MY $self = $_[0];
1517 0 die $self->synerror_at($self->{_startln}, "Unknown method: %s", $meth);
1518 }
1519 14 my $code = *{$sym}{CODE}
1520 14 ▶ or croak "Can't find definition of: $meth";
Branch: 1 branch
BranchTrueFalseTotal
my $code = *{$sym;}{"CODE"} or croak("Can't find definition of: $meth") 14 0 14
1521 14 goto &$code;
1522 }
1523  
1524 #
1525 49 ▶use YATT::Lite::Breakpoint qw(break_load_parser break_parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
1526 49 break_load_parser();
1527  
1528 49 1;
« blib/lib/YATT/Lite/Types.pm ↑ Summary blib/lib/YATT/Lite/Core.pm »