Instrumented/Entry.pm

filter: Statementstmt 11.7% 17 / 145 Branchbran 0.0% 0 / 64 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 20.8% 5 / 24 Podpod 100% 19 / 19 totaltotal 15.6% 41 / 262 CC 38 SCAR 60.6
CC
38
Cov
8%
expand
865.2
child
12.0
if
12.0
CRAP 428.0
↑ Summary Instrumented/Context.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package
5 XHTML::Instrumented::Entry;
6  
7 4 ▶use XHTML::Instrumented::Control;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Params::Validate qw(validate HASHREF);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 our @unused;
11  
12 sub new
13 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
14 0 my $class = shift;
15  
16 0 my %p = Params::Validate::validate( @_, {
17 args => HASHREF,
18 flags => HASHREF,
19 tag => 1,
20 id => 0,
21 name => 0,
22 data => 0,
23 for => 0,
24 # ids => HASHREF,
25 }
26 );
27  
28 0 bless({ data => [], %p }, $class);
29 }
30  
31 sub copy()
32 0 ▶{
Subroutine copy: not called CC=1 SCAR=6.9
Pod documented
33 0 my $self = shift;
34 0 my %p = Params::Validate::validate( @_, {
35 args => 0,
36 control => { optional => 1, isa => 'XHTML::Instrumented::Control' },
37 data => 0,
38 extra => 0,
39 flags => 0,
40 form => 0,
41 id => 0,
42 special => 0,
43 tag => 0,
44 }
45 );
46  
47 bless({
48 date => [],
49 0 %{$self},
50 0 args => {%{$self->{args}}},
51 %p
52 }, ref($self));
53 }
54  
55 sub split_char
56 0 ▶{
Subroutine split_char: not called CC=1 SCAR=6.9
Pod documented
57 0 '\.';
58 }
59  
60 sub child
61 0 ▶{
Subroutine child: not called CC=3 SCAR=24.8
Pod documented
62 0 my $self = shift;
63 0 my %p = Params::Validate::validate(@_,
64 {
65 args => 1,
66 tag => 1,
67 form => 0,
68 }
69 );
70  
71 0 my $args = $p{args};
72 0 my $id;
73 my $for;
74 0 my @flags;
75 0 ▶ if (my $id_full = $args->{id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id_full = $args->{"id"}) 0 0 0
76 0 ($id, @flags) = split($self->split_char, $id_full);
77 }
78 0 ▶ if (my $id_full = $args->{for}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id_full = $args->{"for"}) 0 0 0
79 0 my @fflags;
80 0 ($for, @fflags) = split($self->split_char, $id_full);
81 }
82  
83 my $ret = ref($self)->new(
84 %p,
85 0 flags => { map({ my ($x, @x) = split(':', $_); $x => [@x]} @flags) },
86 id => $id,
87 name => $args->{name},
88 0 ('for' => $for) x!! $for,
89 );
90  
91 0 return $ret;
92 }
93  
94 sub prepend
95 0 ▶{
Subroutine prepend: not called CC=2 SCAR=17.9
Pod documented
96 0 my $self = shift;
97  
98 0 for my $child (@_) {
99 0 unshift(@{$self->{data}}, $child);
100 }
101 }
102  
103 sub id
104 0 ▶{
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
105 0 my $self = shift;
106 0 $self->{id};
107 }
108  
109 sub name
110 0 ▶{
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
111 0 my $self = shift;
112 0 $self->{name};
113 }
114  
115 # elements that have no id or name can be converted to text here
116 # or that can happen latter.
117  
118 sub append
119 0 ▶{
Subroutine append: not called CC=2 SCAR=17.9
Pod documented
120 0 my $self = shift;
121  
122 0 for my $child (@_) {
123 0 push(@{$self->{data}}, $child);
124 }
125  
126 0 return;
127 }
128  
129 # accesor methods
130  
131 sub context
132 0 ▶{
Subroutine context: not called CC=1 SCAR=6.9
Pod documented
133 0 my $self = shift;
134  
135 0 die caller;
136  
137 0 $self->{contextu};
138 }
139  
140 sub tag
141 0 ▶{
Subroutine tag: not called CC=1 SCAR=6.9
Pod documented
142 0 my $self = shift;
143  
144 0 $self->{tag};
145 }
146  
147 sub args
148 0 ▶{
Subroutine args: not called CC=1 SCAR=6.9
Pod documented
149 0 my $self = shift;
150  
151 0 %{$self->{args}};
152 }
153  
154 sub flags
155 0 ▶{
Subroutine flags: not called CC=1 SCAR=6.9
Pod documented
156 0 my $self = shift;
157  
158 0 $self->{flags};
159 }
160  
161 # methods
162  
163 sub are_if
164 0 ▶{
Subroutine are_if: not called CC=2 SCAR=17.9
Pod documented
165 0 my $self = shift;
166  
167 0 ▶ exists $self->{flags}{eq} || exists $self->{flags}{if};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"flags"}{"eq"} or exists $self->{"flags"}{"if"} 0 0 0
168 }
169  
170 sub if
171 0 ▶{
Subroutine if: not called CC=3 SCAR=24.8
Pod documented
172 0 my $self = shift;
173 0 my $ret = 1;
174  
175 0 ▶ if (exists $self->{flags}{eq}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"flags"}{"eq"}) 0 0 0
176 0 $ret = $self->control->eq(@{$self->{flags}{eq}});
177 }
178 0 ▶ if (exists $self->{flags}{if}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"flags"}{"if"}) 0 0 0
179 0 $ret = $self->control->if;
180 }
181  
182 0 return $ret;
183 }
184  
185 sub control
186 0 ▶{
Subroutine control: not called CC=2 SCAR=17.9
Pod documented
187 0 my $self = shift;
188  
189 0 ▶ $self->{control} or die;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"control"} or die 0 0 0
190 }
191  
192 sub children
193 0 ▶{
Subroutine children: not called CC=1 SCAR=6.9
Pod documented
194 0 my $self = shift;
195 0 my @ret;
196 0 my %p = Params::Validate::validate( @_, {
197 context => { isa => 'XHTML::Instrumented::Context' },
198 }
199 );
200  
201 0 return @{$self->{data}};
202 }
203  
204 # we enter here with the complete parsed datastructure.
205  
206 sub is_form
207 0 ▶{
Subroutine is_form: not called CC=1 SCAR=6.9
Pod documented
208 0 my $self = shift;
209  
210 0 $self->{tag} eq 'form';
211 }
212  
213 sub is_label
214 0 ▶{
Subroutine is_label: not called CC=1 SCAR=6.9
Pod documented
215 0 my $self = shift;
216 0 $self->{tag} eq 'label';
217 }
218  
219 sub expand
220 0 ▶{
Subroutine expand: not called CC=30 SCAR=67.6
Pod documented
221 0 my $self = shift;
222  
223 0 my %p = Params::Validate::validate( @_, {
224 context => { isa => 'XHTML::Instrumented::Context' },
225 }
226 );
227 0 my $context = $p{context};
228  
229 0 my @ret;
230 my $control;
231  
232 0 ▶ if ($self->{args}{class}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"args"}{"class"}) 0 0 0
233  
234 }
235  
236 0 my $id;
237  
238 0 ▶ if ($self->name || $self->id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->name or $self->id) { } 0 0 0
Condition0%0/3
$self->name or $self->id
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->name or $self->id
$self->name $self->id
Truth table0%0/3
A or B
A= $self->nameB= $self->id
ABresult
1X1
011
000
239 0 ▶ if ($self->is_form) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_form) { } 0 0 0
240 0 ▶ if (my $name = $self->name) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $self->name) 0 0 0
241 0 $control = $context->get_form($name);
242 0 $id = $name;
243 0 ▶ if ($control) {
Branch: 1 branch
BranchTrueFalseTotal
if ($control) 0 0 0
244 0 $control->{id} = $id;
245 0 $control->{_ids_} = $self->{_ids_};
246 0 $control->{_names_} = $self->{_names_};
247 }
248 }
249 0 $context = $context->copy(form => $control);
250 0 ▶ if ($control) {
Branch: 1 branch
BranchTrueFalseTotal
if ($control) 0 0 0
251 0 ▶ die unless $control->is_form;
Branch: 1 branch
BranchTrueFalseTotal
unless $control->is_form 0 0 0
252 }
253 } else {
254 0 ▶ if (my $id = $self->id) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id = $self->id) 0 0 0
255 0 $control = $context->get_id($id);
256 0 ▶ if ($control->has_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($control->has_name) 0 0 0
257 0 $self->{name} = $control->name;
258 }
259 0 ▶ if (ref $control eq 'XHTML::Instrumented::Control::Dummy') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $control eq "XHTML::Instrumented::Control::Dummy") 0 0 0
260 0 $control = $context->get_name($id, $control);
261 }
262 }
263 0 ▶ if (my $name = $self->name) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $self->name) 0 0 0
264 0 $control = $context->get_name($name, $control);
265 }
266 }
267 0 ▶ $control ||= $context->get_id('__dummy__');
Condition0%0/3
$control ||= $context->get_id("__dummy__")
l!l&&r!l&&!r
000
MC/DC0%0/2
$control ||= $context->get_id("__dummy__")
$control $context->get_id("__dummy__")
Truth table0%0/3
A ||= B
A= $controlB= $context->get_id("__dummy__")
ABresult
1X1
011
000
268 } else {
269 0 $control = $context->get_id('__dummy__');
270 }
271  
272 $control->set_tag(
273 tag => $self->{tag},
274 args => $self->{args},
275 0 );
276 0 ▶ die unless $control;
Branch: 1 branch
BranchTrueFalseTotal
unless $control 0 0 0
277  
278 0 ▶ die "no control ($id)" . $control unless UNIVERSAL::isa($control, 'XHTML::Instrumented::Control');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($control, "XHTML::Instrumented::Control") 0 0 0
279  
280 0 $self->{control} = $control;
281  
282 0 my $if = $self->if;
283 0 ▶ if ($self->{args}{class}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"args"}{"class"}) 0 0 0
284 0 ▶ if (grep({ $_ eq ':even'} split('\s', $self->{args}{class}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq ":even";} split(/\s/, $self->{"args"}{"class"}, 0)) 0 0 0
285 0 ▶ if ($context->{loop}->count % 2 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{"loop"}->count % 2 == 0) 0 0 0
286 0 $if = 0;
287 }
288 }
289 0 ▶ if (grep({ $_ eq ':odd'} split('\s', $self->{args}{class}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq ":odd";} split(/\s/, $self->{"args"}{"class"}, 0)) 0 0 0
290 0 ▶ if ($context->{loop}->count % 2 == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{"loop"}->count % 2 == 1) 0 0 0
291 0 $if = 0;
292 }
293 }
294 }
295
296 0 ▶ if ($self->are_if) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->are_if) 0 0 0
297 0 $self->{control} = $control = XHTML::Instrumented::Control::Dummy->new(id_count => $control->{id_count});
298 }
299  
300 0 ▶ if ($if) {
Branch: 1 branch
BranchTrueFalseTotal
if ($if) { } 0 0 0
301 0 ▶ if ($self->is_label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_label) 0 0 0
302 0 ▶ if (my $for = $self->{for}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $for = $self->{"for"}) 0 0 0
303 0 my $control = $context->get_id($for);
304 0 ▶ if ($control->required) {
Branch: 1 branch
BranchTrueFalseTotal
if ($control->required) 0 0 0
305 0 $self->{args}{style} .= "color: red;";
306 }
307 }
308 }
309  
310 my @asdf = $control->to_text(
311 tag => $self->{tag},
312 children => [ $self->children(context => $context->copy(form => $control->form)) ],
313 args => { $self->args },
314 flags => $self->flags,
315 context => $context,
316 (special => $self->{flags}{sp}) x!! defined $self->{flags}{sp},
317 0 );
318  
319 0 for (@asdf) {
320 4 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
321 0 ▶ warn Dumper $control, \@asdf unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
322 }
323  
324 0 push(@ret, @asdf);
325 } else {
326 0 my $tag = $self->{tag};
327 0 push(@ret, "<!-- $tag -->"); # Fixme need verbose flag
328 }
329  
330 0 ▶ if ($self->{args}{class}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"args"}{"class"}) 0 0 0
331 0 ▶ if (grep({ $_ eq ':data'} split('\s', $self->{args}{class}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq ":data";} split(/\s/, $self->{"args"}{"class"}, 0)) 0 0 0
332 0 $context->inc_loop;
333 }
334 }
335  
336 0 join('', @ret);
337 }
338  
339 4 1;
340 __END__
↑ Summary Instrumented/Context.pm »