blib/lib/WebDyne/HTML/Tiny.pm

filter: Statementstmt 50.4% 256 / 507 Branchbran 33.7% 62 / 184 Conditioncond 19.2% 25 / 130 MC/DCmcdc 11.5% 9 / 78 Subroutinesub 64.5% 31 / 48 Podpod 5.5% 1 / 18 totaltotal 39.7% 384 / 965 CC 155 SCAR 52.7
CC
155
Cov
42%
popup_menu
702.0
_radio_checkbox_group
600.0
checkbox
132.0
CRAP 193.7
« blib/lib/WebDyne/Template.pm ↑ Summary blib/lib/WebDyne/Util.pm »
1 #
2 # This file is part of WebDyne.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package WebDyne::HTML::Tiny;
14  
15  
16 # Pragma
17 #
18 34 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 34 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # Constants, inheritance
24 #
25 34 our $AUTOLOAD;
26 34 our @ISA=qw(HTML::Tiny);
27  
28  
29 # External Modules
30 #
31 34 ▶use HTML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 #use CGI::Simple;
33 34 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 34 ▶use HTML::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36  
37 # WebDyne Modules
38 #
39 34 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 34 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 34 ▶use WebDyne::CGI::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43  
44 # Constants
45 #
46 use constant {
47  
48 34 URL_ENCODED => 'application/x-www-form-urlencoded',
49 MULTIPART => 'multipart/form-data'
50  
51 34 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53  
54 # Package state
55 #
56 34 my %Package;
57  
58  
59 # Version information
60 #
61 34 $VERSION='3.027';
62  
63  
64 # Debug load
65 #
66 34 0 && debug("Loading %s version $VERSION", __PACKAGE__);
67  
68  
69 # Trick to allow use of illegal subroutine name to suppport treebuilder comment format
70 #
71 34 *{'WebDyne::HTML::Tiny::~comment'}=\&_comment;
72 34 *{'WebDyne::HTML::Tiny::entity_encode'}=sub {
73 544 ▶ my ($self, $value)=@_;
Subroutine __ANON__: called CC=1 SCAR=0.0
74 544 return $value unless WEBDYNE_CGI_AUTOESCAPE;
75 544 return HTML::Tiny::entity_encode($self, $value);
76 34 };
77  
78  
79 # All done. Positive return
80 #
81 34 ▶return ${&_init()} || err('error running init code');
Condition33%1/3
${&_init();} || err('error running init code')
l!l&&r!l&&!r
3400
MC/DC0%0/2
${&_init();} || err('error running init code')
${&_init();} err('error running init code')
Truth table33%1/3
A || B
A= ${&_init();}B= err('error running init code')
ABresult
1X1
011
000
82  
83  
84 #==================================================================================================
85  
86  
87 sub new {
88  
89  
90 # Start new instance
91 #
92 58 ▶ my ($class, @param)=@_;
Subroutine new: called CC=4 SCAR=14.7
Pod documented
93 58 my %param;
94 58 ▶ if (ref($param[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param[0] eq 'HASH') { } 0 58 58
95 0 %param=%{$param[0]};
96 }
97 else {
98 58 %param=@param;
99 }
100 58 0 && debug("$class new, %s", Dumper(\%param));
101
102
103 # Shortcuts (start_html, start_form etc.) enabled by default.
104 #
105 &shortcut_enable() unless
106 58 ▶ $param{'noshortcut'}; # no sense before ? was || $Package{'_shortcut_enable'};
Branch: 1 branch
BranchTrueFalseTotal
unless $param{"noshortcut"} 58 0 58
107
108
109 # Get HTML::Tiny ref
110 #
111 58 ▶ my $self=$class->SUPER::new( mode=>(delete($param{'mode'}) || $WEBDYNE_HTML_TINY_MODE));
Condition66%2/3
delete $param{'mode'} || $WebDyne::HTML::Tiny::WEBDYNE_HTML_TINY_MODE
l!l&&r!l&&!r
5620
MC/DC0%0/2
delete $param{'mode'} || $WebDyne::HTML::Tiny::WEBDYNE_HTML_TINY_MODE
delete $param{'mode'} $WebDyne::HTML::Tiny::WEBDYNE_HTML_TINY_MODE
Truth table66%2/3
A || B
A= delete $param{'mode'}B= $WebDyne::HTML::Tiny::WEBDYNE_HTML_TINY_MODE
ABresult
1X1
011
000
112
113
114 # Save away other supplied params into self ref
115 #
116 58 $self->{'_r'}=$param{'r'};
117
118  
119 # Done
120 #
121 58 return $self;
122  
123 }
124  
125  
126 sub Vars {
127  
128 # Get CGI::Simple Vars to ensure we can find values needed to persist choices across form submissions
129 #
130 0 ▶ my $self=shift();
Subroutine Vars: not called CC=2 SCAR=17.9
Pod undocumented
131 0 0 && debug("$self Vars");
132 0 ▶ return ($self->{'_Vars'} ||= $self->CGI()->Vars());
Condition0%0/3
$self->{"_Vars"} ||= $self->CGI->Vars
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_Vars"} ||= $self->CGI->Vars
$self->{"_Vars"} $self->CGI->Vars
Truth table0%0/3
A ||= B
A= $self->{"_Vars"}B= $self->CGI->Vars
ABresult
1X1
011
000
133  
134 }
135  
136  
137 sub CGI {
138  
139
140 # Get CGI::Simple object ref
141 #
142 9 ▶ my $self=shift();
Subroutine CGI: called CC=2 SCAR=7.0
Pod undocumented
143 9 0 && debug("$self CGI");
144 9 ▶ return ($self->{'_CGI'} ||= WebDyne::CGI::Simple->new($self->{'_r'}));
Condition66%2/3
$self->{"_CGI"} ||= "WebDyne::CGI::Simple"->new($self->{"_r"})
l!l&&r!l&&!r
720
MC/DC0%0/2
$self->{"_CGI"} ||= "WebDyne::CGI::Simple"->new($self->{"_r"})
$self->{"_CGI"} "WebDyne::CGI::Simple"->new($self->{"_r"})
Truth table66%2/3
A ||= B
A= $self->{"_CGI"}B= "WebDyne::CGI::Simple"->new($self->{"_r"})
ABresult
1X1
011
000
145
146 }
147  
148  
149 sub _init {
150  
151  
152 # Initialise various subs
153 #
154 34 ▶ *HTML::Tiny::start=\&HTML::Tiny::open || *HTML::Tiny::start; # || *HTML::Tiny::Start stops warning
Subroutine _init: called CC=7 SCAR=25.1
Condition33%1/3
\&HTML::Tiny::open || *HTML::Tiny::start
l!l&&r!l&&!r
3400
MC/DC0%0/2
\&HTML::Tiny::open || *HTML::Tiny::start
\&HTML::Tiny::open *HTML::Tiny::start
Truth table33%1/3
A || B
A= \&HTML::Tiny::openB= *HTML::Tiny::start
ABresult
1X1
011
000
155 34 ▶ *HTML::Tiny::end=\&HTML::Tiny::close || *HTML::Tiny::end; # || as above
Condition33%1/3
\&HTML::Tiny::close || *HTML::Tiny::end
l!l&&r!l&&!r
3400
MC/DC0%0/2
\&HTML::Tiny::close || *HTML::Tiny::end
\&HTML::Tiny::close *HTML::Tiny::end
Truth table33%1/3
A || B
A= \&HTML::Tiny::closeB= *HTML::Tiny::end
ABresult
1X1
011
000
156  
157  
158 # Translate CGI.pm shortcut field to HTML::Tiny equiv
159 #
160 34 my %type=(
161 textfield => 'text',
162 password_field => 'password',
163 filefield => 'file',
164 defaults => 'submit',
165 image_button => 'image',
166 button => 'button'
167 );
168
169  
170 # Which tags do we need to persist value ?
171 #
172 34 my %persist=(
173 textfield => 1,
174 password_field => 1,
175 filefield => 1
176 );
177  
178  
179 # Re-impliment CGI input shortcut tags
180 #
181 34 foreach my $tag (qw(textfield password_field filefield button submit reset defaults image_button hidden button)) {
182
183 272 *{$tag}=sub {
184 9 ▶ my ($self, $attr_hr, @param)=@_;
Subroutine __ANON__: called CC=10 SCAR=35.6
185 9 0 && debug("$self $tag, attr_hr: %s", Dumper($attr_hr));
186 9 ▶ if (defined($attr_hr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr_hr) { } 9 0 9
187 # Copy attr so don't pollute ref
188 9 my %attr=%{$attr_hr};
189 9 my $label=delete $attr{'label'};
190 #my $param_hr=$self->Vars();
191 9 my $param_hr=$self->CGI->Vars();
192 9 ▶ if ($persist{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($persist{$tag}) 0 9 9
193 0 ▶ if ($attr{'name'} && (my $value=$param_hr->{$attr{'name'}}) && !$attr{'force'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr{"name"} and my $value = $$param_hr{$attr{"name"}} and not $attr{"force"}) 0 0 0
Condition0%0/6
$attr{"name"} and my $value = $$param_hr{$attr{"name"}} and not $attr{"force"}
!ll&&!rl&&r
000
$attr{"name"} and my $value = $$param_hr{$attr{"name"}}
!ll&&!rl&&r
000
MC/DC0%0/3
$attr{"name"} and my $value = $$param_hr{$attr{"name"}} and not $attr{"force"}
$attr{"name"} my $value = $$param_hr{$attr{"name"}} not $attr{"force"}
Truth table0%0/4
A and B and not(C)
A= $attr{"name"}B= my $value = $$param_hr{$attr{"name"}}C= not $attr{"force"}
ABCresult
0XX0
10X0
1100
1111
194 0 $attr{'value'}=$value;
195 }
196 }
197
198 # Wrap in label if needed
199 #
200 9 ▶ if ($label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label) { } 0 9 9
201 0 ▶ return $self->label(join('', grep {$_} @param, $label) . $self->input({type => $type{$tag} || $tag, %attr}));
Condition0%0/3
$type{$tag} || $tag
l!l&&r!l&&!r
000
MC/DC0%0/2
$type{$tag} || $tag
$type{$tag} $tag
Truth table0%0/3
A || B
A= $type{$tag}B= $tag
ABresult
1X1
011
000
202 }
203 else {
204 9 ▶ return $self->input({type => $type{$tag} || $tag, %attr}, @param);
Condition33%1/3
$type{$tag} || $tag
l!l&&r!l&&!r
090
MC/DC0%0/2
$type{$tag} || $tag
$type{$tag} $tag
Truth table33%1/3
A || B
A= $type{$tag}B= $tag
ABresult
1X1
011
000
205 }
206 }
207 else {
208 0 ▶ return $self->input({type => $type{$tag} || $tag}, @param)
Condition0%0/3
$type{$tag} || $tag
l!l&&r!l&&!r
000
MC/DC0%0/2
$type{$tag} || $tag
$type{$tag} $tag
Truth table0%0/3
A || B
A= $type{$tag}B= $tag
ABresult
1X1
011
000
209 }
210  
211 340 ▶ } unless UNIVERSAL::can(__PACKAGE__, $tag);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can(__PACKAGE__, $tag) 272 68 340
212 }
213  
214  
215 # Isindex deprecated but reimplement anyway
216 #
217 34 foreach my $tag (qw(isindex)) {
218  
219 34 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
220 34 ▶ *{$tag}=sub {shift()->closed($tag, @_)}
Subroutine __ANON__: not called CC=1 SCAR=1.2
221 34 ▶ unless UNIVERSAL::can(__PACKAGE__, $tag);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can(__PACKAGE__, $tag) 34 0 34
222  
223 }
224  
225  
226 # Done return OK
227 #
228 34 return \1;
229  
230 }
231  
232  
233 sub shortcut {
234  
235 # Set or return passthough flag which flags us to ignore all start_* methods
236 #
237 0 ▶ my $self=shift();
Subroutine shortcut: not called CC=3 SCAR=24.8
Pod undocumented
238 0 0 && debug("self: $self, shortcut: %s", Dumper(\@_));
239 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
240 0 ▶ return shift() ? $self->shortcut_enable() : $self->shortcut_disable()
Branch: 1 branch
BranchTrueFalseTotal
shift() ? : 0 0 0
241 }
242 else {
243 0 return $self->{'_shortcut'}
244 }
245  
246 }
247  
248  
249 sub shortcut_disable {
250  
251 34 ▶ no warnings qw(redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
252 66 ▶ 0 && debug('shortcut_disable: %s', Dumper(\@_));
Subroutine shortcut_disable: called CC=4 SCAR=14.1
Pod undocumented
253 66 foreach my $sub (grep {/^(?:_start|_end)/} keys %{__PACKAGE__ . '::'}) {
254 396 (my $sub_start=$sub)=~s/^_//;
255  
256 #print "disable $sub_start=>$sub";
257 396 ▶ if (my ($action, $tag)=($sub_start=~/^(start|end)_([^:]+)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sub_start =~ /^(start|end)_([^:]+)$/) 396 0 396
258  
259 #print "action: $action, tag: $tag\n";
260 396 ▶ *{$sub_start}=sub {shift()->$action($tag, @_)};
Subroutine __ANON__: called CC=1 SCAR=0.0
261 }
262 }
263 66 delete $Package{'_shortcut_enable'};
264
265 # || *start_html to remove warnings
266 66 ▶ *start_html=sub {shift()->_start_html_bare(@_)} || *start_html
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
sub { (shift())->_start_html_bare(@_); } || *start_html
l!l&&r!l&&!r
6600
MC/DC0%0/2
sub { (shift())->_start_html_bare(@_); } || *start_html
sub { (shift())->_start_html_bare(@_); } *start_html
Truth table33%1/3
A || B
A= sub { (shift())->_start_html_bare(@_); } B= *start_html
ABresult
1X1
011
000
267  
268 }
269  
270  
271 sub shortcut_enable {
272  
273 34 ▶ no warnings qw(redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
274 124 ▶ 0 && debug('shortcut_enable: %s', Dumper(\@_));
Subroutine shortcut_enable: called CC=2 SCAR=6.9
Pod undocumented
275 124 foreach my $sub (grep {/^(?:_start|_end])/} keys %{__PACKAGE__ . '::'}) {
276 620 (my $sub_start=$sub)=~s/^_//;
277  
278 #if ( *{__PACKAGE__ . "::${sub_start}"}{'CODE'} eq \&{$sub} ) {
279 # debug("code for $sub_start exists, skipping");
280 # last;
281 #}
282 #else {
283 # debug("code for $sub_start needed, creating");
284 #}
285  
286 620 0 && debug("enable $sub_start=>$sub, %s", *{__PACKAGE__ . "::${sub_start}"}{'CODE'});
287 620 *{$sub_start}=\&{$sub};
288 }
289 124 $Package{'_shortcut_enable'}++;
290  
291 #*start_html=\&_start_html_bare;
292  
293 }
294  
295  
296 # Start_html shorcut and include DTD
297 #
298 sub _start_html {
299  
300  
301 # Get self ref and any attributes passed
302 #
303 65 ▶ my ($self, $attr_hr, @param)=@_;
Subroutine _start_html: called CC=40 SCAR=44.3
304 65 0 && debug("$self _start_html, attr: %s, param: %s", Dumper($attr_hr, \@param));
305 #return $self->SUPER::start_html($attr_hr, @param) if $self->{'_passthrough'};
306  
307  
308 # Command-line tools can suppress both the global head insert and the
309 # configured start_html head parameters.
310 #
311 65 my $r=$self->{'_r'};
312 65 ▶ my $no_head_insert=(ref($r) && $r->{'no_head_insert'});
Condition100%3/3
ref $r && $r->{'no_head_insert'}
!ll&&!rl&&r
14447
MC/DC100%2/2
ref $r && $r->{'no_head_insert'}
ref $r $r->{'no_head_insert'}
Truth table100%3/3
A && B
A= ref $rB= $r->{'no_head_insert'}
ABresult
0X0
100
111
313 65 ▶ my $webdyne_start_html_param_hr=$no_head_insert
Branch: 1 branch
BranchTrueFalseTotal
$no_head_insert ? : 7 58 65
314 ? {}
315 : $WEBDYNE_START_HTML_PARAM;
316  
317  
318 # Attributes we are going to use
319 #
320 65 0 && debug('WEBDYNE_START_HTML_PARAM: %s', Dumper($WEBDYNE_START_HTML_PARAM));
321 my %attr=(
322 65 %{$WEBDYNE_HTML_PARAM},
323 65 %{$webdyne_start_html_param_hr},
324 65 %{$attr_hr}
325 );
326 65 0 && debug('attr: %s', Dumper(\%attr));
327  
328  
329 # If no attributes passed used defaults from constants file
330 #
331 #keys %{$attr_hr} || ($attr_hr=$WEBDYNE_HTML_PARAM);
332  
333  
334 # Pull out meta attributes leaving rest presumably native html tag attribs
335 #
336 32 my %attr_page=map {$_ => delete $attr{$_}} grep { exists($attr{$_}) } (qw(
337 title
338 meta
339 style
340 style_prepend
341 style_append
342 base
343 target
344 author
345 script
346 script_prepend
347 script_append
348 include
349 include_script
350 include_style
351 static
352 cache
353 handler
354 h1
355 h2
356 h3
357 h4
358 h5
359 h6
360 hr
361 sse
362 ws
363 require
364 import
365 65 ), keys %{$WEBDYNE_START_HTML_SHORTCUT_HR});
366 65 0 && debug('start_html %s', Dumper(\%attr_page));
367  
368  
369 # Start with the DTD
370 #
371 65 my @html=$WEBDYNE_DTD;
372  
373  
374 # Static, cache ? If so mark as such in HTML::Tiny object to be
375 # reviewed at end of parse by Treebuilder. Not ideal, good enough
376 #
377 65 foreach my $attr (qw(static cache handler sse ws require import)) {
378 455 ▶ if (my $value=$attr_page{$attr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $attr_page{$attr}) 1 454 455
379 1 0 && debug("found attr: $attr, setting to value: $value");
380 1 $self->{"_${attr}"}=$value;
381 1 ▶ $self->{'_static'} ||=1 if ($attr eq 'cache');
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "cache" 0 1 1
Condition0%0/2
$self->{"_static"} ||= 1
l!l
00
MC/DC0%0/1
$self->{"_static"} ||= 1
$self->{"_static"}
Truth table0%0/2
A
A= $self->{"_static"}
Aresult
11
00
382 }
383 }
384
385
386 # Shortcuts ? Add to relevant attributes
387 #
388 65 foreach my $shortcut (grep {$attr_page{$_}} keys %{$WEBDYNE_START_HTML_SHORTCUT_HR}) {
389 6 my $shortcut_hr=$WEBDYNE_START_HTML_SHORTCUT_HR->{$shortcut};
390 6 my $version=$attr_page{$shortcut};
391 6 0 && debug("found shortcut tag: $shortcut, content: %s", Dumper($shortcut_hr));
392 6 ▶ while (my($type, $href_ar)=each %{$shortcut_hr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$shortcut_hr;}) 6 6 12
393 6 ▶ my @href=ref($href_ar) eq 'ARRAY' ? @{$href_ar} : ($href_ar);
Branch: 1 branch
BranchTrueFalseTotal
ref $href_ar eq 'ARRAY' ? : 0 6 6
394 6 ▶ if ($version=~/^\@/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /^\@/) 3 3 6
395 3 s/\@latest/$version/g for @href;
396 }
397 6 $href_ar=\@href;
398 6 0 && debug("processing type: $type, href: %s", Dumper($href_ar));
399 6 ▶ if (my $type_attr_value_ar=$attr_page{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type_attr_value_ar = $attr_page{$type}) { } 0 6 6
400 0 ▶ unless (ref($type_attr_value_ar) eq 'ARRAY') { $type_attr_value_ar=[$type_attr_value_ar] }
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $type_attr_value_ar eq "ARRAY") 0 0 0
401 0 0 && debug("found existing start_html attr type: $type, content: %s", Dumper($type_attr_value_ar));
402 0 push @{$type_attr_value_ar}, @{$href_ar};
403 0 $attr_page{$type}=$type_attr_value_ar;
404 0 0 && debug("updated start_html attr type: $type to: %s", Dumper($type_attr_value_ar));
405 }
406 else {
407 6 0 && debug("no start_hrml attr type: $type found, creating with content: %s", Dumper($href_ar));
408 6 $attr_page{$type}=$href_ar
409 }
410 }
411 }
412  
413  
414 # Allow stylesheets to be added around configured/default styles without
415 # replacing them. Explicit style remains the base value if supplied.
416 #
417 65 ▶ if ($attr_page{'style_prepend'} || $attr_page{'style_append'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"style_prepend"} or $attr_page{"style_append"}) 3 62 65
Condition100%3/3
$attr_page{"style_prepend"} or $attr_page{"style_append"}
l!l&&r!l&&!r
2162
MC/DC100%2/2
$attr_page{"style_prepend"} or $attr_page{"style_append"}
$attr_page{"style_prepend"} $attr_page{"style_append"}
Truth table100%3/3
A or B
A= $attr_page{"style_prepend"}B= $attr_page{"style_append"}
ABresult
1X1
011
000
418 7 ▶ my @style=map { ref($_) eq 'ARRAY' ? @{$_} : $_ } grep {$_} (
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 2 5 7
419 $attr_page{'style_prepend'},
420 $attr_page{'style'},
421 3 $attr_page{'style_append'}
422 );
423 3 ▶ $attr_page{'style'}=\@style if @style;
Branch: 1 branch
BranchTrueFalseTotal
if @style 3 0 3
424 }
425  
426  
427 # Allow scripts to be added around configured/default scripts without
428 # replacing them. Explicit script remains the base value if supplied.
429 #
430 65 ▶ if ($attr_page{'script_prepend'} || $attr_page{'script_append'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"script_prepend"} or $attr_page{"script_append"}) 3 62 65
Condition100%3/3
$attr_page{"script_prepend"} or $attr_page{"script_append"}
l!l&&r!l&&!r
2162
MC/DC100%2/2
$attr_page{"script_prepend"} or $attr_page{"script_append"}
$attr_page{"script_prepend"} $attr_page{"script_append"}
Truth table100%3/3
A or B
A= $attr_page{"script_prepend"}B= $attr_page{"script_append"}
ABresult
1X1
011
000
431 7 ▶ my @script=map { ref($_) eq 'ARRAY' ? @{$_} : $_ } grep {$_} (
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 2 5 7
432 $attr_page{'script_prepend'},
433 $attr_page{'script'},
434 3 $attr_page{'script_append'}
435 );
436 3 ▶ $attr_page{'script'}=\@script if @script;
Branch: 1 branch
BranchTrueFalseTotal
if @script 3 0 3
437 }
438  
439  
440 # Add meta section
441 #
442 65 my @meta;
443 65 ▶ if (my $hr=$attr_page{'meta'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hr = $attr_page{'meta'}) { } 1 64 65
444 1 0 && debug('have meta hr: %s', Dumper($hr));
445 1 @meta=$self->meta({content => $attr_page{'meta'}});
446 1 0 && debug('processed to: %s', Dumper(\@meta));
447 }
448 else {
449 64 0 && debug('no meta run');
450 }
451
452
453 # Logic error below, replaced by above
454 #
455 #my @meta=$self->meta({ content=>$attr_page{'meta'} })
456 # if $attr_page{'meta'};
457 ##debug('meta: %s', Dumper(\@meta));
458 ##while (my ($name, $content)=each %{$attr_page{'meta'}}) {
459 ## push @meta, $self->meta({name => $name, content => $content});
460 ##}
461 # Used to do this
462 #while (my ($name, $content)=each %{$WEBDYNE_META}) {
463 #push @meta, $self->meta({$name => $content});
464  
465 #}
466 # Now this
467 ##push @meta, $self->meta({ content => $WEBDYNE_META }) unless
468  
469  
470 # Base and/or target
471 #
472 65 my @base;
473 65 ▶ if ($attr_page{'base'} || $attr_page{'target'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"base"} or $attr_page{"target"}) 0 65 65
Condition33%1/3
$attr_page{"base"} or $attr_page{"target"}
l!l&&r!l&&!r
0065
MC/DC0%0/2
$attr_page{"base"} or $attr_page{"target"}
$attr_page{"base"} $attr_page{"target"}
Truth table33%1/3
A or B
A= $attr_page{"base"}B= $attr_page{"target"}
ABresult
1X1
011
000
474 0 my %attr_base;
475 0 ▶ $attr_base{'href'} = $attr_page{'base'} if $attr_page{'base'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_page{"base"} 0 0 0
476 0 ▶ $attr_base{'target'} = $attr_page{'target'} if $attr_page{'target'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_page{"target"} 0 0 0
477 0 push @base, $self->base(\%attr_base);
478 }
479
480  
481 # Add any stylesheets
482 #
483 65 my @link;
484 65 ▶ if (my $style=$attr_page{'style'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $style = $attr_page{"style"}) 11 54 65
485
486 # Generate HTML for link tag stylheet
487 #
488 11 push @link, $self->_start_html_tag('link', 'href', $style,
489 { rel=>'stylesheet'});
490  
491 }
492 65 ▶ if (my $include_style=$attr_page{'include_style'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $include_style = $attr_page{"include_style"}) 0 65 65
493  
494 # Generate HTML to make an include section for any styles user wants, wrap in <style> tag
495 #
496 0 push @link, $self->_start_html_tag('include', 'file', $include_style,
497 { wrap =>'style'});
498
499
500 # Used to do this way but only could do single file
501 #
502 #my $html_or=HTML::Element->new('include', wrap=>'style', file => $include_style);
503 #push @link, $html_or->as_HTML();
504 }
505  
506 65 ▶ if (my $author=$attr_page{'author'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $author = $attr_page{"author"}) 0 65 65
507 0 $author=$self->url_encode($author);
508 0 my $html_or=HTML::Element->new('link', rel=> 'author', href => sprintf('mailto:%s', $author));
509 0 push @link, $html_or->as_HTML();
510 }
511
512  
513 # Scripts
514 #
515 65 my @script;
516 65 ▶ if (my $script=$attr_page{'script'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $script = $attr_page{"script"}) 11 54 65
517
518 # Script same as style above
519 #
520 11 push @script, $self->_start_html_tag('script', 'src', $script);
521 }
522 65 ▶ if (my $include_script=$attr_page{'include_script'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $include_script = $attr_page{"include_script"}) 0 65 65
523
524 # Include script same as style above
525 #
526 0 push @script, $self->_start_html_tag('include', 'file', $include_script,
527 { wrap =>'script'});
528  
529 }
530
531
532 # Include any other files
533 #
534 65 my @include;
535 65 ▶ if (my $fn=$attr_page{'include'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fn = $attr_page{'include'}) { } 0 65 65
536
537
538 # Same as other tags above, generate <include> HTML
539 #
540 0 push @include, $self->_start_html_tag('include', 'file', $fn);
541
542
543 # Used to do this way
544 #
545 #my $html_or=HTML::Element->new('include', file => $fn);
546 #push @include, $html_or->as_HTML();
547
548  
549 # Older way was experimental
550 #
551 #$include=${
552 # $webdyne_or->include({ file=>$fn, head=>1 }) ||
553 # return err();
554 #};
555 #debug("include: $include");
556  
557 }
558 else {
559
560 # No included file (which should include default metadata) so add default
561 #
562 65 0 && debug('no include file, adding default metadata');
563 65 push @meta, $self->meta({ content => $WEBDYNE_META });
564
565 }
566  
567
568
569 # Build title
570 #
571 65 my ($title, $title_html);
572 65 ▶ unless (@include && (grep {/<title>.*?<\/title>/i} @include)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@include and grep {m[<title>.*?</title>]i;} @include) 65 0 65
Condition33%1/3
@include and grep {m[<title>.*?</title>]i;} @include
!ll&&!rl&&r
6500
MC/DC0%0/2
@include and grep {m[<title>.*?</title>]i;} @include
@include grep {m[<title>.*?</title>]i;} @include
Truth table33%1/3
A and B
A= @includeB= grep {m[<title>.*?</title>]i;} @include
ABresult
0X0
100
111
573 65 ▶ if (defined($attr_page{'title'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $attr_page{'title'}) { } 0 65 65
elsif (exists $attr_page{'title'}) { } 0 65 65
574 # Title is defined (presumably some string)
575 #
576 0 0 && debug('title attr defined, using: %s', $attr_page{'title'});
577 0 $title_html=$self->title($title=$attr_page{'title'});
578 }
579 elsif (exists($attr_page{'title'})) {
580 # Exists but undefined, leave title undef also
581 #
582 0 0 && debug('title attr exists but undefined, leaving undefined');
583 0 $title=undef;
584 }
585 else {
586 # No title attr at all, use default
587 #
588 65 0 && debug('title attr not present, using default title');
589 65 $title_html=$self->title($title=$WEBDYNE_HTML_DEFAULT_TITLE);
590 }
591 }
592 65 0 && debug('title: %s', $title || '*undef*');
593
594
595 # Add title as introductory heading if wanted
596 #
597 65 my $heading_html='';
598 65 ▶ if (my ($heading_tag)=grep {$attr_page{$_}} qw(h1 h2 h3 h4 h5 h6)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($heading_tag) = grep({$attr_page{$_};} "h1", "h2", "h3", "h4", "h5", "h6")) 0 65 65
599 0 ▶ $heading_html=$self->$heading_tag($title) if $title;
Branch: 1 branch
BranchTrueFalseTotal
if $title 0 0 0
600 0 ▶ if ($attr_page{'hr'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"hr"}) 0 0 0
601 0 $heading_html.=$self->hr();
602 }
603 }
604
605  
606 # Build head, adding a title section, empty if none specified
607 #
608 my $head=$self->SUPER::head(
609 join(
610 $/,
611 65 grep {$_} (
612 $title_html,
613 @meta,
614 @base,
615 @link,
616 @script,
617 @include
618 )
619 ));
620  
621  
622 # Put all together and return
623 #
624 #push @html, $self->open('html', $attr_hr), $head . $self->open('body');
625 65 push @html, $self->open('html', \%attr), $head . $self->open('body') . $heading_html;
626 65 0 && debug('html: %s', Dumper(\@html));
627 65 return join($/, @html);
628  
629 }
630  
631  
632 sub _start_html_tag {
633  
634 22 ▶ my ($self, $tag, $attr, $param_ar, $attr_hr)=@_;
Subroutine _start_html_tag: called CC=4 SCAR=13.9
635 22 my @html;
636 22 ▶ unless (ref($param_ar) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $param_ar eq "ARRAY") 2 20 22
637 2 $param_ar=[$param_ar];
638 }
639 22 ▶ if ($WEBDYNE_START_HTML_PARAM_STATIC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WebDyne::HTML::Tiny::WEBDYNE_START_HTML_PARAM_STATIC) 22 0 22
640 22 $attr_hr->{'static'}=1;
641 }
642 22 foreach my $param (@{$param_ar}) {
643 42 my $html_or=HTML::Element->new($tag, $attr=>$param, %{$attr_hr} );
644 42 push @html, $html_or->as_HTML();
645 }
646 22 return join('', @html);
647
648 }
649
650  
651 sub _end_html0 { # No longer needed
652  
653 # Stub for WebDyne UNIVERSAL::can to find
654 #
655 #shift()->SUPER::end_html(@_);
656 0 ▶ my ($self, $attr_hr)=@_;
Subroutine _end_html0: not called CC=1 SCAR=6.9
657 0 0 && debug("$self _start_html, attr: %s, param: %s", Dumper($attr_hr, \@_));
658  
659 #return $self->SUPER::end_html($attr_hr) if $self->{'_passthrough'};
660 0 my @html;
661 0 push @html, $self->close('body'), $self->close('html');
662 0 return join($/, @html);
663  
664 #return shift()->close('html', @_);
665  
666 }
667  
668  
669 sub html {
670  
671 13 ▶ my $self=shift();
Subroutine html: called CC=2 SCAR=6.9
Pod undocumented
672 13 0 && debug("$self html() param: %s", Dumper(\@_));
673 # Move default attributes into <html> tag unless user has explicitely supplied
674 13 ▶ unshift (@_, $WEBDYNE_HTML_PARAM) unless (ref $_[0] eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 1 12 13
675 13 return $WEBDYNE_DTD . $self->SUPER::html(@_);
676  
677 }
678  
679  
680 sub head {
681  
682 32 ▶ my ($self, $html, @param)=@_;
Subroutine head: called CC=4 SCAR=13.9
Pod undocumented
683 #debug("$self head, html:$html, attr:%s", Dumper(\@_));
684 32 0 && debug("$self head, param:%s", Dumper($_[2]));
685 32 my $r=$self->{'_r'};
686 32 ▶ my $no_head_insert=(ref($r) && $r->{'no_head_insert'});
Condition66%2/3
ref $r && $r->{'no_head_insert'}
!ll&&!rl&&r
0248
MC/DC50%1/2
ref $r && $r->{'no_head_insert'}
ref $r $r->{'no_head_insert'}
Truth table66%2/3
A && B
A= ref $rB= $r->{'no_head_insert'}
ABresult
0X0
100
111
687 32 ▶ $html.=$WEBDYNE_HEAD_INSERT if ($WEBDYNE_HEAD_INSERT && !$no_head_insert);
Branch: 1 branch
BranchTrueFalseTotal
if $WebDyne::HTML::Tiny::WEBDYNE_HEAD_INSERT and not $no_head_insert 13 19 32
Condition100%3/3
$WebDyne::HTML::Tiny::WEBDYNE_HEAD_INSERT and not $no_head_insert
!ll&&!rl&&r
11813
MC/DC100%2/2
$WebDyne::HTML::Tiny::WEBDYNE_HEAD_INSERT and not $no_head_insert
$WebDyne::HTML::Tiny::WEBDYNE_HEAD_INSERT not $no_head_insert
Truth table100%3/3
A and not(B)
A= $WebDyne::HTML::Tiny::WEBDYNE_HEAD_INSERTB= not $no_head_insert
ABresult
0X0
100
111
688 32 return $self->SUPER::head(grep {$_} ($html, @param));
689
690 }
691  
692  
693 sub _start_html_bare {
694  
695 # Special. Called by optimise_two in WebDybe compile instead of start_html above
696 #
697 18 ▶ my $self=shift();
Subroutine _start_html_bare: called CC=1 SCAR=0.0
698 18 0 && debug("$self _start_html_bare param:%s", Dumper(\@_));
699 18 return $WEBDYNE_DTD . $self->SUPER::open('html', @_);
700 #return $WEBDYNE_DTD
701  
702 }
703  
704  
705 # Start_form shortcut
706 #
707 sub _start_form {
708  
709 0 ▶ my ($self, $attr_hr, @param)=@_;
Subroutine _start_form: not called CC=2 SCAR=17.9
710 0 0 && debug("$self _start_form, attr_hr:%s param:%s", Dumper($attr_hr, \@param));
711 0 my %default=(
712 method => 'post',
713 # Redundant
714 # enctype => +URL_ENCODED
715 );
716 0 ▶ map {$attr_hr->{$_} ||= $default{$_}}
Condition0%0/3
$attr_hr->{$_} ||= $default{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr_hr->{$_} ||= $default{$_}
$attr_hr->{$_} $default{$_}
Truth table0%0/3
A ||= B
A= $attr_hr->{$_}B= $default{$_}
ABresult
1X1
011
000
717 keys %default;
718 0 return $self->start('form', $attr_hr, @param);
719  
720 }
721  
722  
723 # Start multi-part form shortcut
724 #
725 sub _start_multipart_form {
726 0 ▶ 0 && debug("$_[0] _start_multipart_form");
Subroutine _start_multipart_form: not called CC=2 SCAR=17.9
727 0 ▶ return shift()->start_form({enctype => +MULTIPART, %{$_[0] ? shift() : {}}}, @_);
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
728 }
729  
730  
731 sub end_multipart_form {
732 0 ▶ 0 && debug("$_[0] _end_multipart_form");
Subroutine end_multipart_form: not called CC=1 SCAR=6.9
Pod undocumented
733 0 return shift()->end_form(@_);
734 }
735  
736  
737 # Support CGI comment syntax. See aliasing to ~comment in top section
738 #
739 sub _comment {
740  
741 1 ▶ my ($self, $attr_hr)=@_;
Subroutine _comment: called CC=1 SCAR=0.0
742 1 0 && debug("$self comment, attr:%s", Dumper($attr_hr));
743 #return sprintf("\n<!-- %s -->\n", $attr_hr->{'text'});
744 1 my $html=sprintf('<!-- %s -->', $attr_hr->{'text'});
745 1 if (WEBDYNE_HTML_NEWLINE) {
746 $html="\n${html}\n";
747 }
748 1 return $html;
749  
750 }
751  
752  
753 # Meta tag
754 #
755 sub meta {
756  
757 154 ▶ my ($self, $attr_hr)=@_;
Subroutine meta: called CC=6 SCAR=17.9
Pod undocumented
758 154 0 && debug("$self in meta, attr %s", Dumper($attr_hr));
759 154 my @html;
760 154 ▶ if (ref(my $meta_hr=$attr_hr->{'content'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref(my $meta_hr = $attr_hr->{'content'}) eq 'HASH') { } 66 88 154
761 66 0 && debug('meta is HASH');
762
763 # Want to be determenistic so sort keys unless tied
764 #
765 66 my @name=keys(%{$meta_hr});
766 66 ▶ unless(my $or=tied(%{$meta_hr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $or = tied %{$meta_hr;}) { } 16 50 66
767 # Not tied hash to sort keys
768 #
769 50 0 && debug('meta hash not tied, sorting');
770 50 @name=sort { $a cmp $b } @name;
771 }
772 else {
773 16 0 && debug("meta_hr is tied to $or");
774 }
775
776 #while (my ($name, $content)=each %{$attr_hr->{'content'}}) {
777 66 foreach my $name (@name) {
778 176 my $content=$meta_hr->{$name};
779 176 ▶ if ((my ($key, $value)=split(/=/, $name)) == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ((() = split(/=/, $name, 3)) == 2) { } 95 81 176
780  
781 # Self contained
782 #
783 95 0 && debug("split to $key: $value");
784 95 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) { } 30 65 95
785 30 push @html, $self->SUPER::meta({$key => $value, content => $content});
786 }
787 else {
788 65 push @html, $self->SUPER::meta({$key => $value});
789 }
790 }
791 else {
792 81 push @html, $self->SUPER::meta({name => $name, content => $content});
793 }
794 }
795 }
796 else {
797 88 0 && debug('meta is plain');
798 88 push @html, $self->SUPER::meta($attr_hr)
799 }
800 154 return join($/, @html);
801  
802 }
803  
804  
805 # Link tag - expand array into multiple if needed
806 #
807 sub link {
808  
809 0 ▶ my ($self, $attr_hr)=@_;
Subroutine link: not called CC=2 SCAR=17.9
Pod undocumented
810 0 0 && debug("$self link, attr %s", Dumper($attr_hr));
811 0 my @html;
812 0 ▶ if (ref($attr_hr->{'href'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr_hr->{'href'} eq 'ARRAY') { } 0 0 0
813 0 my %attr=%{$attr_hr};
814 0 my $href_ar=delete $attr{'href'};
815 0 map {push @html, $self->SUPER::link({%attr, href => $_})} @{$href_ar}
816 }
817 else {
818 0 push @html, $self->SUPER::link($attr_hr)
819 }
820 0 return join($/, @html);
821  
822 }
823  
824  
825 # Script tag - same deal
826 #
827 sub script {
828  
829 0 ▶ my ($self, $attr_hr, @param)=@_;
Subroutine script: not called CC=8 SCAR=42.8
Pod undocumented
830 0 0 && debug("$self script, attr %s", Dumper($attr_hr));
831
832
833 # Take copy of attribute hash ref so we don't alter original
834 #
835 0 my @html;
836 0 my %attr=%{$attr_hr};
837 0 ▶ if ($attr{'src'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr{'src'}) { } 0 0 0
838
839
840 # Convert to array
841 #
842 0 my $script_ar;
843 0 ▶ unless (ref($script_ar=$attr{'src'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($script_ar = $attr{"src"}) eq "ARRAY") 0 0 0
844 0 $script_ar=[$script_ar]
845 }
846 0 0 && debug('attr_hr: %s, script_ar: %s', Dumper($attr_hr, $script_ar));
847
848 # Iterate over each one
849 #
850 0 foreach my $src (@{$script_ar}) {
851 0 0 && debug("src: $src");
852 0 my %src_attr=%attr;
853
854 # Split off any fragments and use them as attributes, e.g. #defer becomes defer, ?foo=bar becomes foo=bar in attr
855 0 my @src=split(/#/, $src);
856 0 $src=$src[0];
857 0 0 && debug("src post split: $src");
858 0 ▶ if ($src[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src[1]) 0 0 0
859 0 0 && debug('split src: %s', Dumper(\@src));
860 0 foreach my $kv (split /&/, $src[1]) {
861 0 ▶ next unless length($kv);
Branch: 1 branch
BranchTrueFalseTotal
unless length $kv 0 0 0
862 0 ▶ if ( $kv =~ /^([^=]+)=(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kv =~ /^([^=]+)=(.*)$/) { } 0 0 0
863 0 $src_attr{$1}=$2;
864 }
865 else {
866 # no “=” means flag parameter
867 0 $src_attr{$kv} = [];
868 }
869 }
870 0 0 && debug("fragment attr: $src[1] decoded as %s from query_param: %s", Dumper(\%attr, \@src));
871 }
872 0 push @html, $self->SUPER::script({%src_attr, src => $src}, @param)
873 }
874 }
875 else {
876 0 push @html, $self->SUPER::script($attr_hr, @param)
877 }
878 0 0 && debug('html: %s', Dumper(\@html));
879 0 return join($/, @html);
880  
881 }
882  
883  
884 sub _radio_checkbox {
885  
886  
887 # Return a radio or checkboxinput field, adding label tags if needed
888 #
889 0 ▶ my ($self, $tag, $attr_hr, $html)=@_;
Subroutine _radio_checkbox: not called CC=2 SCAR=17.9
890 0 0 && debug("$self _radio_checkbox, tag:$tag attr_hr:%s", Dumper($attr_hr));
891 0 my %attr=%{$attr_hr};
892 0 ▶ if (my $label=delete $attr{'label'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $label = delete $attr{'label'}) { } 0 0 0
893 0 return $self->label($self->input({type => $tag, %attr}) . join('', grep {$_} $html, $label));
894 }
895 else {
896 0 return $self->input({type => $tag, %attr}) . $html;
897 }
898  
899 }
900  
901  
902 # Checkbox group
903 #
904 sub _radio_checkbox_group {
905  
906  
907 # Build a checkbox or radio group
908 #
909 0 ▶ my ($self, $tag, $attr_hr)=@_;
Subroutine _radio_checkbox_group: not called CC=24 SCAR=64.0
910 0 0 && debug("$self _radio_checbox_group tag:$tag attr: %s", Dumper($attr_hr));
911 0 my %attr=%{$attr_hr};
912  
913  
914 # Get hash ref of any existing CGI param
915 #
916 0 ▶ my $param_hr=($self->{'_Vars'} ||= $self->Vars()) ||
Condition0%0/5
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
l!l
00
$self->{"_Vars"} ||= $self->Vars
l!l&&r!l&&!r
000
MC/DC0%0/1
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
($self->{'_Vars'} ||= $self->Vars)
MC/DC0%0/2
$self->{"_Vars"} ||= $self->Vars
$self->{"_Vars"} $self->Vars
Truth table0%0/2
A
A= ($self->{'_Vars'} ||= $self->Vars)
Aresult
11
00
Truth table0%0/3
A ||= B
A= $self->{"_Vars"}B= $self->Vars
ABresult
1X1
011
000
917 return err('unable able to CGI::Simple Vars');
918
919
920 # And CGI object
921 #
922 0 ▶ my $cgi_or=$self->CGI() ||
Condition0%0/2
$self->CGI || (return err('unable to get CGI object'))
l!l
00
MC/DC0%0/1
$self->CGI || (return err('unable to get CGI object'))
$self->CGI
Truth table0%0/2
A
A= $self->CGI
Aresult
11
00
923 return err('unable to get CGI object');
924  
925  
926 # Hold generated HTML in array until end
927 #
928 0 my @html;
929  
930  
931 # Convert arrays of default values (i.e checked/enabled) and any disabled entries into hash - easier to check
932 #
933 my %attr_group;
934 0 foreach my $attr (qw(default defaults checked disabled)) {
935 0 ▶ map {$attr_group{$attr}{$_}=1} @{(ref($attr{$attr}) eq 'ARRAY') ? $attr{$attr} : [$attr{$attr}]}
Branch: 1 branch
BranchTrueFalseTotal
ref $attr{$attr} eq 'ARRAY' ? : 0 0 0
936 0 ▶ if $attr{$attr};
Branch: 1 branch
BranchTrueFalseTotal
if $attr{$attr} 0 0 0
937 }
938 0 0 && debug('attr_group: %s', Dumper(\%attr_group));
939  
940  
941 # If values is a hash not an array then convert to array and use hash as values
942 #
943 0 ▶ if (ref($attr{'values'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr{"values"} eq "HASH") 0 0 0
944  
945  
946 # It's a hash - use as labels, and push keys to values
947 #
948 0 $attr{'labels'}=(my $hr=delete $attr{'values'});
949 0 $attr{'values'}=[keys %{$hr}]
950  
951 }
952  
953  
954 # Make sure checked values persist by default unless "force" attribute used to override
955 #
956 #if ($attr_hr->{'name'} && (my $checked=$param_hr->{$attr_hr->{'name'}}) && !$attr_hr->{'force'}) {
957 0 ▶ if ($attr_hr->{'name'} && (my @checked=$cgi_or->param($attr_hr->{'name'})) && !$attr_hr->{'force'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hr->{'name'} and my(@checked) = $cgi_or->param($attr_hr->{'name'}) and not $attr_hr->{'force'}) { } 0 0 0
Condition0%0/6
$attr_hr->{"name"} and my(@checked) = $cgi_or->param($attr_hr->{"name"}) and not $attr_hr->{"force"}
!ll&&!rl&&r
000
$attr_hr->{"name"} and my(@checked) = $cgi_or->param($attr_hr->{"name"})
!ll&&!rl&&r
000
MC/DC0%0/3
$attr_hr->{"name"} and my(@checked) = $cgi_or->param($attr_hr->{"name"}) and not $attr_hr->{"force"}
$attr_hr->{"name"} my(@checked) = $cgi_or->param($attr_hr->{"name"}) not $attr_hr->{"force"}
Truth table0%0/4
A and B and not(C)
A= $attr_hr->{"name"}B= my(@checked) = $cgi_or->param($attr_hr->{"name"})C= not $attr_hr->{"force"}
ABCresult
0XX0
10X0
1100
1111
958  
959 # The tag has a name, and has some selected (checked) values from a form submision. Map the submitted values
960 # into the checked attribute, splitting on \0 as per spec
961 #
962 # UPDATE: changed to accommodate use of Hash::Multivalue params now
963 #
964 0 my @checked=$cgi_or->param($attr_hr->{'name'});
965 0 0 && debug('checked: %s', Dumper(\@checked));
966 #$attr_group{'checked'} = { map { $_=>1 } (split(/\0/, $checked)) }
967 0 $attr_group{'checked'} = { map { $_=>1 } @checked }
968  
969 }
970 else {
971  
972 # Convert 'defaults' key to 'selected'
973 #
974 0 ▶ do {$attr_group{'checked'} ||= (delete($attr_group{'default'}) || delete($attr_group{'defaults'}))}
Condition0%0/6
$attr_group{"checked"} ||= delete $attr_group{"default"} || delete $attr_group{"defaults"}
l!l&&r!l&&!r
000
delete $attr_group{'default'} || delete $attr_group{'defaults'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$attr_group{"checked"} ||= delete $attr_group{"default"} || delete $attr_group{"defaults"}
$attr_group{"checked"} delete $attr_group{'default'} delete $attr_group{'defaults'}
Truth table0%0/4
A ||= B || C
A= $attr_group{"checked"}B= delete $attr_group{'default'}C= delete $attr_group{'defaults'}
ABCresult
1XX1
01X1
0011
0000
975 0 ▶ if ($attr_group{'default'} || $attr_group{'defaults'});
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_group{"default"} or $attr_group{"defaults"}) 0 0 0
Condition0%0/3
$attr_group{"default"} or $attr_group{"defaults"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr_group{"default"} or $attr_group{"defaults"}
$attr_group{"default"} $attr_group{"defaults"}
Truth table0%0/3
A or B
A= $attr_group{"default"}B= $attr_group{"defaults"}
ABresult
1X1
011
000
976
977 }
978  
979  
980 # Radio groups can only have one option checked. If multiple discard and only use first one in alphabetical order
981 #
982 0 ▶ if ($tag eq 'radio') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "radio") 0 0 0
983 #%{$attr_group{'defaults'}}=map {$_ => $attr_group{'defaults'}{$_}} ([sort keys %{$attr_group{'defaults'}}]->[0])
984 # if $attr_group{'defaults'};
985 0 %{$attr_group{'checked'}}=map {$_ => $attr_group{'checked'}{$_}} ([sort keys %{$attr_group{'checked'}}]->[0])
986 0 ▶ if $attr_group{'checked'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_group{"checked"} 0 0 0
987 }
988  
989  
990 # Now iterate and build actual tag, push onto HTML array
991 #
992 0 foreach my $value (@{$attr{'values'}}) {
993 my %attr_tag=$attr{'attributes'}{$value}
994 ?
995 0 ▶ (%{$attr{'attributes'}{$value}})
Branch: 1 branch
BranchTrueFalseTotal
$attr{'attributes'}{$value} ? : 0 0 0
996 :
997 ();
998 0 ▶ $attr_tag{'name'}=$attr{'name'} if $attr{'name'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr{"name"} 0 0 0
999 0 $attr_tag{'value'}=$value;
1000  
1001 # Note use of empty array for checked and disabled values as per HTML::Tiny specs
1002 #$attr_tag{'checked'}=[] if $attr_group{'defaults'}{$value};
1003 0 ▶ $attr_tag{'checked'}=[] if $attr_group{'checked'}{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_group{"checked"}{$value} 0 0 0
1004 0 ▶ $attr_tag{'disabled'}=[] if $attr_group{'disabled'}{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_group{"disabled"}{$value} 0 0 0
1005 0 ▶ $attr_tag{'label'}=$attr{'labels'}{$value} ? $attr{'labels'}{$value} : $value;
Branch: 1 branch
BranchTrueFalseTotal
$attr{'labels'}{$value} ? : 0 0 0
1006 0 push @html, $self->_radio_checkbox($tag, \%attr_tag);
1007 }
1008  
1009  
1010 # Return, separating with linebreaks if that is what is wanted.
1011 #
1012 0 ▶ return join($attr{'linebreak'} ? $self->br() : '', @html);
Branch: 1 branch
BranchTrueFalseTotal
$attr{'linebreak'} ? : 0 0 0
1013  
1014 }
1015  
1016  
1017 sub checkbox_group {
1018 0 ▶ 0 && debug("$_[0] checkbox_group");
Subroutine checkbox_group: not called CC=1 SCAR=6.9
Pod undocumented
1019 0 return shift()->_radio_checkbox_group('checkbox', @_)
1020 }
1021  
1022  
1023 sub radio_group {
1024 0 ▶ 0 && debug("$_[0] radio_group");
Subroutine radio_group: not called CC=1 SCAR=6.9
Pod undocumented
1025 0 return shift()->_radio_checkbox_group('radio', @_)
1026 }
1027  
1028  
1029 sub checkbox {
1030
1031  
1032 # Bit more complex
1033 #
1034 0 ▶ my ($self, $attr_hr, @html)=@_;
Subroutine checkbox: not called CC=11 SCAR=48.8
Pod undocumented
1035 0 0 && debug("$self checkbox, attr_hr:%s", Dumper($attr_hr));
1036
1037
1038 # Mirror attributes so if we change we don't alter originals
1039 #
1040 0 my %attr=%{$attr_hr};
1041  
1042  
1043 # Get hash ref of any existing CGI param
1044 #
1045 0 ▶ my $param_hr=($self->{'_Vars'} ||= $self->Vars()) ||
Condition0%0/5
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
l!l
00
$self->{"_Vars"} ||= $self->Vars
l!l&&r!l&&!r
000
MC/DC0%0/1
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
($self->{'_Vars'} ||= $self->Vars)
MC/DC0%0/2
$self->{"_Vars"} ||= $self->Vars
$self->{"_Vars"} $self->Vars
Truth table0%0/2
A
A= ($self->{'_Vars'} ||= $self->Vars)
Aresult
11
00
Truth table0%0/3
A ||= B
A= $self->{"_Vars"}B= $self->Vars
ABresult
1X1
011
000
1046 return err('unable able to CGI::Simple Vars');
1047
1048  
1049 # And CGI object
1050 #
1051 0 ▶ my $cgi_or=$self->CGI() ||
Condition0%0/2
$self->CGI || (return err('unable to get CGI object'))
l!l
00
MC/DC0%0/1
$self->CGI || (return err('unable to get CGI object'))
$self->CGI
Truth table0%0/2
A
A= $self->CGI
Aresult
11
00
1052 return err('unable to get CGI object');
1053
1054  
1055 # Var to hold hidden tag
1056 #
1057 0 my $hidden='';
1058  
1059
1060 # Massage to set default value of "1" for checkboxes if no value
1061 # attr found. If one is found assume user knows what they are doing
1062 #
1063 0 ▶ unless (my $value=$attr_hr->{'value'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $attr_hr->{'value'}) { } 0 0 0
1064 0 ▶ if (my $name=$attr_hr->{'name'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $attr_hr->{'name'}) { } 0 0 0
1065
1066 # Add hidden field with same name but 0 value
1067 #
1068 0 0 && debug("using hidden field for checkbox: $name, setting checked value to 1 if selected");
1069 #push @html, $self->hidden({ name=>$name, value=>0, force=>1 });
1070 0 $hidden=$self->hidden({ name=>$name, value=>0, force=>1 });
1071
1072
1073 # Set value of this checkbox (if checked) to 1
1074 #
1075 0 $attr{'value'}=1;
1076
1077
1078 # Add up all values for this checkbox now.
1079 #
1080 # UPDATE: Changed to accommodate use of Hash::Multivalue params now.
1081 #
1082 0 my $checked;
1083 #if (my $value=$param_hr->{$name}) {
1084 # map { $checked+=int($_) } split(/\0/, $value);
1085 #}
1086 0 ▶ if (my @value=$cgi_or->param($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@value) = $cgi_or->param($name)) 0 0 0
1087 0 map { $checked+=int($_) } @value;
1088 }
1089
1090
1091 # Run checkbox logic
1092 #
1093 0 ▶ if(exists($param_hr->{$name}) && $checked) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $param_hr->{$name} and $checked) { } 0 0 0
elsif (exists $param_hr->{$name} and not $checked) { } 0 0 0
Condition0%0/3
exists $param_hr->{$name} and $checked
!ll&&!rl&&r
000
MC/DC0%0/2
exists $param_hr->{$name} and $checked
exists $param_hr->{$name} $checked
Truth table0%0/3
A and B
A= exists $param_hr->{$name}B= $checked
ABresult
0X0
100
111
1094
1095 0 0 && debug("param name:$name exists and is checked, setting checked to true");
1096 0 $attr{'checked'}=[];
1097
1098 }
1099 ▶ elsif(exists($param_hr->{$name}) && !$checked) {
Condition0%0/3
exists $param_hr->{$name} and not $checked
!ll&&!rl&&r
000
MC/DC0%0/2
exists $param_hr->{$name} and not $checked
exists $param_hr->{$name} not $checked
Truth table0%0/3
A and not(B)
A= exists $param_hr->{$name}B= not $checked
ABresult
0X0
100
111
1100
1101 0 0 && debug("param name:$name exists but is not defined, clearing checked attribute");
1102 0 delete $attr{'checked'};
1103
1104 }
1105 else {
1106
1107 0 0 && debug("no $name param, using tag default: %s", $attr{'checked'} ? 'checked=1' : '<unchecked>');
1108
1109 }
1110 }
1111 else {
1112
1113 0 0 && debug('no name attr');
1114
1115 }
1116 }
1117 else {
1118
1119 # Custom value
1120 #
1121 0 0 && debug("custom value: $value, checkbox logic bypassed");
1122
1123 }
1124
1125
1126 # Done, return result
1127 #
1128 #return shift()->_radio_checkbox('checkbox', @_)
1129 #return $self->_radio_checkbox('checkbox', grep {$_} $attr_hr, @_) . join(undef, grep {$_} @html);
1130 0 0 && debug('calling radio_checkbox');
1131 0 return $hidden.$self->_radio_checkbox('checkbox', \%attr, join('', @html))
1132 }
1133  
1134  
1135 # Popup menu or scrolling list
1136 #
1137 sub popup_menu {
1138  
1139  
1140 # Build a checkbox or radio group
1141 #
1142 0 ▶ my ($self, $attr_hr)=@_;
Subroutine popup_menu: not called CC=26 SCAR=65.5
Pod undocumented
1143 0 my %attr_select=%{$attr_hr};
1144 0 0 && debug("$self popup_menu, attr_hr:%s", Dumper($attr_hr));
1145
1146
1147 # Get hash ref of any existing CGI param
1148 #
1149 0 ▶ my $param_hr=($self->{'_Vars'} ||= $self->Vars()) ||
Condition0%0/5
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
l!l
00
$self->{"_Vars"} ||= $self->Vars
l!l&&r!l&&!r
000
MC/DC0%0/1
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
($self->{'_Vars'} ||= $self->Vars)
MC/DC0%0/2
$self->{"_Vars"} ||= $self->Vars
$self->{"_Vars"} $self->Vars
Truth table0%0/2
A
A= ($self->{'_Vars'} ||= $self->Vars)
Aresult
11
00
Truth table0%0/3
A ||= B
A= $self->{"_Vars"}B= $self->Vars
ABresult
1X1
011
000
1150 return err('unable able to CGI::Simple Vars');
1151  
1152  
1153 # And CGI object
1154 #
1155 0 ▶ my $cgi_or=$self->CGI() ||
Condition0%0/2
$self->CGI || (return err('unable to get CGI object'))
l!l
00
MC/DC0%0/1
$self->CGI || (return err('unable to get CGI object'))
$self->CGI
Truth table0%0/2
A
A= $self->CGI
Aresult
11
00
1156 return err('unable to get CGI object');
1157  
1158  
1159 # Hold generated HTML in array until end
1160 #
1161 0 my @html;
1162
1163
1164 # Pull off any label
1165 #
1166 0 my $label=delete $attr_select{'label'};
1167  
1168  
1169 # If values is a hash not an array then convert to array and use hash as values
1170 #
1171 0 ▶ if (ref($attr_select{'values'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr_select{"values"} eq "HASH") 0 0 0
1172  
1173  
1174 # It's a hash - use as labels, and push keys to values
1175 #
1176 0 $attr_select{'labels'}=(my $hr=delete $attr_select{'values'});
1177 0 $attr_select{'values'}=[keys %{$hr}]
1178  
1179 }
1180  
1181 # Convert arrays of default values (i.e checked/enabled) and any disabled entries into hash - easier to check
1182 #
1183 my %attr_option=(
1184 values => delete $attr_select{'values'},
1185 attributes => delete $attr_select{'attributes'},
1186 0 labels => delete $attr_select{'labels'}
1187 );
1188  
1189  
1190 # Carefully handle options
1191 #
1192 0 foreach my $attr (qw(default defaults selected disabled)) {
1193  
1194 0 ▶ next unless exists $attr_select{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attr_select{$attr} 0 0 0
1195 0 my @values;
1196 0 ▶ if (ref($attr_select{$attr}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr_select{$attr} eq 'ARRAY') { } 0 0 0
1197 0 @values=@{$attr_select{$attr}}
1198 }
1199 else {
1200 # Single value
1201 0 @values=(grep {$_} $attr_select{$attr})
1202 }
1203  
1204 0 ▶ unless ($attr eq 'disabled') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr eq 'disabled') { } 0 0 0
1205 0 foreach my $value (@values) {
1206 0 0 && debug("value $value");
1207 0 $attr_option{$attr}{$value}=1;
1208 }
1209 0 delete $attr_select{$attr};
1210 }
1211 else { # handle disabled attr carefully
1212 0 ▶ if (@values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values) { } 0 0 0
1213 0 foreach my $value (@values) {
1214 0 $attr_option{$attr}{$value}=1;
1215 }
1216 0 delete $attr_select{$attr};
1217 }
1218 else {
1219 0 $attr_select{$attr}=[];
1220 }
1221 }
1222 }
1223  
1224  
1225 # Debug
1226 #
1227 0 0 && debug('in popup_menu attr_option: %s', Dumper(\%attr_option));
1228
1229
1230 # Make sure selected values persist by default unless "force" attribute used to override
1231 #
1232 #if ($attr_hr->{'name'} && (my $selected=$param_hr->{$attr_hr->{'name'}}) && !$attr_hr->{'force'}) {
1233 0 ▶ if ($attr_hr->{'name'} && (my @selected=$cgi_or->param($attr_hr->{'name'})) && !$attr_hr->{'force'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hr->{'name'} and my(@selected) = $cgi_or->param($attr_hr->{'name'}) and not $attr_hr->{'force'}) { } 0 0 0
Condition0%0/6
$attr_hr->{"name"} and my(@selected) = $cgi_or->param($attr_hr->{"name"}) and not $attr_hr->{"force"}
!ll&&!rl&&r
000
$attr_hr->{"name"} and my(@selected) = $cgi_or->param($attr_hr->{"name"})
!ll&&!rl&&r
000
MC/DC0%0/3
$attr_hr->{"name"} and my(@selected) = $cgi_or->param($attr_hr->{"name"}) and not $attr_hr->{"force"}
$attr_hr->{"name"} my(@selected) = $cgi_or->param($attr_hr->{"name"}) not $attr_hr->{"force"}
Truth table0%0/4
A and B and not(C)
A= $attr_hr->{"name"}B= my(@selected) = $cgi_or->param($attr_hr->{"name"})C= not $attr_hr->{"force"}
ABCresult
0XX0
10X0
1100
1111
1234  
1235 # The tag has a name, and has some selected (checked) values from a form submision. Map the submitted values
1236 # into the selected field, splitting on \0 as per spec
1237 #
1238 # UPDATE: changed to accommodate use of Hash::Multivalue params now
1239 #
1240 #$attr_option{'selected'} = { map { $_=>1 } (split(/\0/, $selected)) }
1241 0 $attr_option{'selected'} = { map { $_=>1 } @selected }
1242  
1243 }
1244 else {
1245  
1246 # Convert 'defaults' key to 'selected'
1247 #
1248 0 ▶ do {$attr_option{'selected'} ||= (delete($attr_option{'default'}) || delete($attr_option{'defaults'}))}
Condition0%0/6
$attr_option{"selected"} ||= delete $attr_option{"default"} || delete $attr_option{"defaults"}
l!l&&r!l&&!r
000
delete $attr_option{'default'} || delete $attr_option{'defaults'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$attr_option{"selected"} ||= delete $attr_option{"default"} || delete $attr_option{"defaults"}
$attr_option{"selected"} delete $attr_option{'default'} delete $attr_option{'defaults'}
Truth table0%0/4
A ||= B || C
A= $attr_option{"selected"}B= delete $attr_option{'default'}C= delete $attr_option{'defaults'}
ABCresult
1XX1
01X1
0011
0000
1249 0 ▶ if ($attr_option{'default'} || $attr_option{'defaults'});
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_option{"default"} or $attr_option{"defaults"}) 0 0 0
Condition0%0/3
$attr_option{"default"} or $attr_option{"defaults"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr_option{"default"} or $attr_option{"defaults"}
$attr_option{"default"} $attr_option{"defaults"}
Truth table0%0/3
A or B
A= $attr_option{"default"}B= $attr_option{"defaults"}
ABresult
1X1
011
000
1250
1251 }
1252  
1253 # If disabled option is an array but is empty then it is meant for the parent tag
1254 #
1255 #if ($attr_option{'disabled'} && !@{$attr_option{'disabled'}}) {
1256 #if ($attr_option{'disabled'} && !@{$attr_options{'disabled'}}) {
1257 #if (exists $attr_option{'disabled'} && !(keys %{$attr_option{'disabled'}})) {
1258  
1259 # Yes, it is empty, so user wants whole option disabled
1260 #
1261 # debug('disable entire popup_menu');
1262 # $attr_select{'disabled'}=[]
1263  
1264 #}
1265 #else {
1266  
1267 # debug('deleting attr_select disabled attr');
1268 # delete $attr_select{'disabled'};
1269  
1270 #}
1271  
1272 #map { delete $attr_select{$_} } (qw(default selected disabled));
1273  
1274  
1275 # Fix multiple tag if true
1276 #
1277 0 ▶ $attr_select{'multiple'}=[] if $attr_select{'multiple'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_select{"multiple"} 0 0 0
1278 #map { delete $attr_select{$_} } (qw(default selected disabled));
1279 0 0 && debug('in popup_menu attr_select: %s', Dumper(\%attr_select));
1280  
1281  
1282 # Now iterate and build actual tag, push onto HTML array
1283 #
1284 0 foreach my $value (@{$attr_option{'values'}}) {
1285 my %attr_tag=$attr_option{'attributes'}{$value}
1286 ?
1287 0 ▶ (%{$attr_option{'attributes'}{$value}})
Branch: 1 branch
BranchTrueFalseTotal
$attr_option{'attributes'}{$value} ? : 0 0 0
1288 :
1289 ();
1290 0 $attr_tag{'value'}=$value;
1291  
1292 # Note use of empty array for checked and disabled values as per HTML::Tiny specs
1293 0 ▶ $attr_tag{'selected'}=[] if $attr_option{'selected'}{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_option{"selected"}{$value} 0 0 0
1294 0 ▶ $attr_tag{'disabled'}=[] if $attr_option{'disabled'}{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_option{"disabled"}{$value} 0 0 0
1295 0 ▶ my $label=$attr_option{'labels'}{$value} ? $attr_option{'labels'}{$value} : $value;
Branch: 1 branch
BranchTrueFalseTotal
$attr_option{'labels'}{$value} ? : 0 0 0
1296 #debug("attr_option label: %s, value: $value, label: $label", Dumper($attr_option{'labels'}));
1297  
1298 #if ($label) {
1299 # push @html, $self->label($self->option(\%attr_tag) . $label);
1300 #}
1301 #else {
1302 0 0 && debug("pushing option tag with label: $label, attr_tag: %s", Dumper(\%attr_tag));
1303 0 push @html, $self->option(\%attr_tag, $label)
1304  
1305 #}
1306 }
1307
1308
1309 # Now wrap in label if needed
1310 #
1311 0 0 && debug('creating select group with attr: %s, options:%s, label: %s', Dumper(\%attr_select, \@html), $label);
1312 0 ▶ if ($label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label) { } 0 0 0
1313 0 return $self->label($label . $self->select(\%attr_select, join($/, @html)));
1314 }
1315 else {
1316 0 return $self->select(\%attr_select, join($/, @html));
1317 }
1318
1319  
1320 # Return
1321 #
1322 #return $self->select(\%attr_select, join($/, @html));
1323  
1324 }
1325  
1326  
1327 sub scrolling_list {
1328  
1329 # Only difference between popup_menu and scrolling list is size attrribute, which we calculate -if
1330 # supplied will overwrite calculated value
1331 #
1332 0 ▶ my ($self, $attr_hr, @param)=@_;
Subroutine scrolling_list: not called CC=2 SCAR=17.9
Pod undocumented
1333 0 0 && debug("self $self scrolling_list, attr_hr: %s", Dumper($attr_hr));
1334 0 ▶ my $size=(ref($attr_hr->{'values'}) eq 'ARRAY') ? scalar @{$attr_hr->{'values'}} : scalar keys %{$attr_hr->{'values'}};
Branch: 1 branch
BranchTrueFalseTotal
ref $attr_hr->{'values'} eq 'ARRAY' ? : 0 0 0
1335 #return shift()->popup_menu({size => scalar @{$_[0]->{'values'}}, %{shift()}}, @_);
1336 0 return $self->popup_menu({size => $size, %{$attr_hr}}, @param);
1337  
1338 }
1339  
1340  
1341 sub textarea {
1342  
1343 # Slightly different handling for textarea
1344 #
1345 0 ▶ my ($self, $attr_hr, @param)=@_;
Subroutine textarea: not called CC=7 SCAR=40.3
Pod undocumented
1346 0 0 && debug("self $self textarea, attr_hr: %s", Dumper($attr_hr));
1347  
1348  
1349 # Get hash ref of any existing CGI param
1350 #
1351 0 ▶ my $param_hr=($self->{'_Vars'} ||= $self->Vars()) ||
Condition0%0/5
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
l!l
00
$self->{"_Vars"} ||= $self->Vars
l!l&&r!l&&!r
000
MC/DC0%0/1
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
($self->{'_Vars'} ||= $self->Vars)
MC/DC0%0/2
$self->{"_Vars"} ||= $self->Vars
$self->{"_Vars"} $self->Vars
Truth table0%0/2
A
A= ($self->{'_Vars'} ||= $self->Vars)
Aresult
11
00
Truth table0%0/3
A ||= B
A= $self->{"_Vars"}B= $self->Vars
ABresult
1X1
011
000
1352 return err('unable able to CGI::Simple Vars');
1353
1354
1355 # Copy attr_hr so don't mangle original
1356 #
1357 0 my %attr=%{$attr_hr};
1358
1359
1360 # Label ?
1361 #
1362 0 my $label=delete $attr{'label'};
1363
1364  
1365 # Make sure entered text persists unless force in effect
1366 #
1367 0 my $content=delete($attr{'default'});
1368 0 ▶ if ($attr{'name'} && (my $entered=$param_hr->{$attr{'name'}}) && !$attr{'force'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr{"name"} and my $entered = $$param_hr{$attr{"name"}} and not $attr{"force"}) 0 0 0
Condition0%0/6
$attr{"name"} and my $entered = $$param_hr{$attr{"name"}} and not $attr{"force"}
!ll&&!rl&&r
000
$attr{"name"} and my $entered = $$param_hr{$attr{"name"}}
!ll&&!rl&&r
000
MC/DC0%0/3
$attr{"name"} and my $entered = $$param_hr{$attr{"name"}} and not $attr{"force"}
$attr{"name"} my $entered = $$param_hr{$attr{"name"}} not $attr{"force"}
Truth table0%0/4
A and B and not(C)
A= $attr{"name"}B= my $entered = $$param_hr{$attr{"name"}}C= not $attr{"force"}
ABCresult
0XX0
10X0
1100
1111
1369  
1370 # The tag has a name, and has some already entered text. That wins
1371 #
1372 0 $content=$entered
1373  
1374 }
1375
1376
1377 # Wrap in label if needed
1378 #
1379 0 ▶ if ($label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label) { } 0 0 0
1380 0 return $self->label( $label . $self->SUPER::textarea(grep {$_} \%attr, $content));
1381 }
1382 else {
1383 # Have enough to build now
1384 #
1385 0 return $self->SUPER::textarea(grep {$_} \%attr, $content);
1386 }
1387
1388 }
1389  
1390  
1391 sub AUTOLOAD {
1392 96 ▶ 0 && debug("AUTOLOAD: $AUTOLOAD");
Subroutine AUTOLOAD: called CC=2 SCAR=6.9
1393 96 ▶ if (my ($action, $tag)=($AUTOLOAD=~/\:\:(start|end|open|close)_([^:]+)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $WebDyne::HTML::Tiny::AUTOLOAD =~ /\:\:(start|end|open|close)_([^:]+)$/) 38 58 96
1394 38 0 && debug("action: $action, tag: $tag");
1395 38 ▶ *{$AUTOLOAD}=sub {shift()->$action($tag, @_)};
Subroutine __ANON__: called CC=1 SCAR=0.0
1396 38 return &{$AUTOLOAD}(@_);
1397 }
1398 }
1399 __END__
« blib/lib/WebDyne/Template.pm ↑ Summary blib/lib/WebDyne/Util.pm »