lib/WebDyne/HTML/Tiny.pm

filter: Statementstmt 37.0% 188 / 508 Branchbran 16.6% 31 / 186 Conditioncond 9.8% 13 / 132 MC/DCmcdc 0.0% 0 / 79 Subroutinesub 52.0% 25 / 48 Podpod 5.5% 1 / 18 totaltotal 26.5% 258 / 971 CC 157 SCAR 55.8
CC
157
Cov
28%
popup_menu
702.0
_radio_checkbox_group
600.0
_start_html
417.6
CRAP 265.4
« lib/WebDyne/Compile.pm ↑ Summary 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 3 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # Constants, inheritance
24 #
25 3 our $AUTOLOAD;
26 3 our @ISA=qw(HTML::Tiny);
27  
28  
29 # External Modules
30 #
31 3 ▶use HTML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 #use CGI::Simple;
33 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶use HTML::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36  
37 # WebDyne Modules
38 #
39 3 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 3 ▶use WebDyne::CGI::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43  
44 # Constants
45 #
46 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 3 URL_ENCODED => 'application/x-www-form-urlencoded',
49 MULTIPART => 'multipart/form-data'
50  
51 3 };
52  
53  
54 # Package state
55 #
56 3 my %Package;
57  
58  
59 # Version information
60 #
61 3 $VERSION='3.029';
62  
63  
64 # Debug load
65 #
66 3 debug("Loading %s version $VERSION", __PACKAGE__);
67  
68  
69 # Trick to allow use of illegal subroutine name to suppport treebuilder comment format
70 #
71 3 *{'WebDyne::HTML::Tiny::~comment'}=\&_comment;
72 3 ▶*{'WebDyne::HTML::Tiny::entity_encode'}=sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 24 my ($self, $value)=@_;
74 24 return $value unless WEBDYNE_CGI_AUTOESCAPE;
75 24 return HTML::Tiny::entity_encode($self, $value);
76 3 };
77  
78  
79 # All done. Positive return
80 #
81 3 ▶return ${&_init()} || err('error running init code');
Condition33%1/3
${&_init();} || err('error running init code')
l!l&&r!l&&!r
300
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 8 ▶sub new {
Subroutine new: called CC=4 SCAR=15.2
Pod documented
88  
89  
90 # Start new instance
91 #
92 8 my ($class, @param)=@_;
93 8 my %param;
94 8 ▶ if (ref($param[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param[0] eq 'HASH') { } 0 8 8
95 0 %param=%{$param[0]};
96 }
97 else {
98 8 %param=@param;
99 }
100 8 debug("$class new, %s", Dumper(\%param));
101
102
103 # Shortcuts (start_html, start_form etc.) enabled by default.
104 #
105 &shortcut_enable() unless
106 8 ▶ $param{'noshortcut'}; # no sense before ? was || $Package{'_shortcut_enable'};
Branch: 1 branch
BranchTrueFalseTotal
unless $param{"noshortcut"} 8 0 8
107
108
109 # Get HTML::Tiny ref
110 #
111 8 ▶ my $self=$class->SUPER::new( mode=>(delete($param{'mode'}) || $WEBDYNE_HTML_TINY_MODE));
Condition33%1/3
delete $param{'mode'} || $WebDyne::HTML::Tiny::WEBDYNE_HTML_TINY_MODE
l!l&&r!l&&!r
800
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 table33%1/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 8 $self->{'_r'}=$param{'r'};
117
118  
119 # Done
120 #
121 8 return $self;
122  
123 }
124  
125  
126 0 ▶sub Vars {
Subroutine Vars: not called CC=2 SCAR=17.9
Pod undocumented
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();
131 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 0 ▶sub CGI {
Subroutine CGI: not called CC=2 SCAR=17.9
Pod undocumented
138  
139
140 # Get CGI::Simple object ref
141 #
142 0 my $self=shift();
143 0 debug("$self CGI");
144 0 ▶ return ($self->{'_CGI'} ||= WebDyne::CGI::Simple->new($self->{'_r'}));
Condition0%0/3
$self->{"_CGI"} ||= "WebDyne::CGI::Simple"->new($self->{"_r"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_CGI"} ||= "WebDyne::CGI::Simple"->new($self->{"_r"})
$self->{"_CGI"} "WebDyne::CGI::Simple"->new($self->{"_r"})
Truth table0%0/3
A ||= B
A= $self->{"_CGI"}B= "WebDyne::CGI::Simple"->new($self->{"_r"})
ABresult
1X1
011
000
145
146 }
147  
148  
149 3 ▶sub _init {
Subroutine _init: called CC=7 SCAR=31.7
150  
151  
152 # Initialise various subs
153 #
154 3 ▶ *HTML::Tiny::start=\&HTML::Tiny::open || *HTML::Tiny::start; # || *HTML::Tiny::Start stops warning
Condition33%1/3
\&HTML::Tiny::open || *HTML::Tiny::start
l!l&&r!l&&!r
300
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 3 ▶ *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
300
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 3 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 3 my %persist=(
173 textfield => 1,
174 password_field => 1,
175 filefield => 1
176 );
177  
178  
179 # Re-impliment CGI input shortcut tags
180 #
181 3 foreach my $tag (qw(textfield password_field filefield button submit reset defaults image_button hidden button)) {
182
183 24 ▶ *{$tag}=sub {
Subroutine __ANON__: not called CC=10 SCAR=46.3
184 0 my ($self, $attr_hr, @param)=@_;
185 0 debug("$self $tag, attr_hr: %s", Dumper($attr_hr));
186 0 ▶ if (defined($attr_hr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr_hr) { } 0 0 0
187 # Copy attr so don't pollute ref
188 0 my %attr=%{$attr_hr};
189 0 my $label=delete $attr{'label'};
190 #my $param_hr=$self->Vars();
191 0 my $param_hr=$self->CGI->Vars();
192 0 ▶ if ($persist{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($persist{$tag}) 0 0 0
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 0 ▶ if ($label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label) { } 0 0 0
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 0 ▶ return $self->input({type => $type{$tag} || $tag, %attr}, @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
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 30 ▶ } unless UNIVERSAL::can(__PACKAGE__, $tag);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can(__PACKAGE__, $tag) 24 6 30
212 }
213  
214  
215 # Isindex deprecated but reimplement anyway
216 #
217 3 foreach my $tag (qw(isindex)) {
218  
219 3 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
220 0 ▶ *{$tag}=sub {shift()->closed($tag, @_)}
Subroutine __ANON__: not called CC=1 SCAR=1.2
221 3 ▶ unless UNIVERSAL::can(__PACKAGE__, $tag);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can(__PACKAGE__, $tag) 3 0 3
222  
223 }
224  
225  
226 # Done return OK
227 #
228 3 return \1;
229  
230 }
231  
232  
233 0 ▶sub shortcut {
Subroutine shortcut: not called CC=3 SCAR=24.8
Pod undocumented
234  
235 # Set or return passthough flag which flags us to ignore all start_* methods
236 #
237 0 my $self=shift();
238 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 6 ▶sub shortcut_disable {
Subroutine shortcut_disable: called CC=4 SCAR=14.2
Pod undocumented
250  
251 3 ▶ no warnings qw(redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
252 6 debug('shortcut_disable: %s', Dumper(\@_));
253 6 foreach my $sub (grep {/^(?:_start|_end)/} keys %{__PACKAGE__ . '::'}) {
254 36 (my $sub_start=$sub)=~s/^_//;
255  
256 #print "disable $sub_start=>$sub";
257 36 ▶ if (my ($action, $tag)=($sub_start=~/^(start|end)_([^:]+)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sub_start =~ /^(start|end)_([^:]+)$/) 36 0 36
258  
259 #print "action: $action, tag: $tag\n";
260 0 ▶ *{$sub_start}=sub {shift()->$action($tag, @_)};
Subroutine __ANON__: not called CC=1 SCAR=0.4
261 }
262 }
263 6 delete $Package{'_shortcut_enable'};
264
265 # || *start_html to remove warnings
266 6 ▶ *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
600
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 14 ▶sub shortcut_enable {
Subroutine shortcut_enable: called CC=2 SCAR=6.9
Pod undocumented
272  
273 3 ▶ no warnings qw(redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
274 14 debug('shortcut_enable: %s', Dumper(\@_));
275 14 foreach my $sub (grep {/^(?:_start|_end])/} keys %{__PACKAGE__ . '::'}) {
276 70 (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 70 debug("enable $sub_start=>$sub, %s", *{__PACKAGE__ . "::${sub_start}"}{'CODE'});
287 70 *{$sub_start}=\&{$sub};
288 }
289 14 $Package{'_shortcut_enable'}++;
290  
291 #*start_html=\&_start_html_bare;
292  
293 }
294  
295  
296 # Start_html shorcut and include DTD
297 #
298 3 ▶sub _start_html {
Subroutine _start_html: called CC=41 SCAR=60.3
299  
300  
301 # Get self ref and any attributes passed
302 #
303 3 my ($self, $attr_hr, @param)=@_;
304 3 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 3 my $r=$self->{'_r'};
312 3 ▶ my $no_head_insert=(ref($r) && $r->{'no_head_insert'});
Condition33%1/3
ref $r && $r->{'no_head_insert'}
!ll&&!rl&&r
030
MC/DC0%0/2
ref $r && $r->{'no_head_insert'}
ref $r $r->{'no_head_insert'}
Truth table33%1/3
A && B
A= ref $rB= $r->{'no_head_insert'}
ABresult
0X0
100
111
313 3 ▶ my $webdyne_start_html_param_hr=$no_head_insert
Branch: 1 branch
BranchTrueFalseTotal
$no_head_insert ? : 0 3 3
314 ? {}
315 : $WEBDYNE_START_HTML_PARAM;
316  
317  
318 # Attributes we are going to use
319 #
320 3 debug('WEBDYNE_START_HTML_PARAM: %s', Dumper($WEBDYNE_START_HTML_PARAM));
321 my %attr=(
322 3 %{$WEBDYNE_HTML_PARAM},
323 3 %{$webdyne_start_html_param_hr},
324 3 %{$attr_hr}
325 );
326 3 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 0 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 3 ), keys %{$WEBDYNE_START_HTML_SHORTCUT_HR});
366 3 debug('start_html %s', Dumper(\%attr_page));
367  
368  
369 # Start with the DTD
370 #
371 3 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 3 foreach my $attr (qw(static cache handler sse ws require import)) {
378 21 ▶ if (my $value=$attr_page{$attr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $attr_page{$attr}) 0 21 21
379 0 debug("found attr: $attr, setting to value: $value");
380 0 $self->{"_${attr}"}=$value;
381 0 ▶ $self->{'_static'} ||=1 if ($attr eq 'cache');
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "cache" 0 0 0
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 3 foreach my $shortcut (grep {$attr_page{$_}} keys %{$WEBDYNE_START_HTML_SHORTCUT_HR}) {
389 0 my $shortcut_hr=$WEBDYNE_START_HTML_SHORTCUT_HR->{$shortcut};
390 0 my $version=$attr_page{$shortcut};
391 0 debug("found shortcut tag: $shortcut, content: %s", Dumper($shortcut_hr));
392 0 ▶ while (my($type, $href_ar)=each %{$shortcut_hr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$shortcut_hr;}) 0 0 0
393 0 ▶ my @href=ref($href_ar) eq 'ARRAY' ? @{$href_ar} : ($href_ar);
Branch: 1 branch
BranchTrueFalseTotal
ref $href_ar eq 'ARRAY' ? : 0 0 0
394 0 ▶ if ($version=~/^\@/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /^\@/) 0 0 0
395 0 s/\@latest/$version/g for @href;
396 }
397 0 $href_ar=\@href;
398 0 debug("processing type: $type, href: %s", Dumper($href_ar));
399 0 ▶ if (my $type_attr_value_ar=$attr_page{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type_attr_value_ar = $attr_page{$type}) { } 0 0 0
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 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 debug("updated start_html attr type: $type to: %s", Dumper($type_attr_value_ar));
405 }
406 else {
407 0 debug("no start_hrml attr type: $type found, creating with content: %s", Dumper($href_ar));
408 0 $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 3 ▶ if ($attr_page{'style_prepend'} || $attr_page{'style_append'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"style_prepend"} or $attr_page{"style_append"}) 0 3 3
Condition33%1/3
$attr_page{"style_prepend"} or $attr_page{"style_append"}
l!l&&r!l&&!r
003
MC/DC0%0/2
$attr_page{"style_prepend"} or $attr_page{"style_append"}
$attr_page{"style_prepend"} $attr_page{"style_append"}
Truth table33%1/3
A or B
A= $attr_page{"style_prepend"}B= $attr_page{"style_append"}
ABresult
1X1
011
000
418 0 ▶ my @style=map { ref($_) eq 'ARRAY' ? @{$_} : $_ } grep {$_} (
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
419 $attr_page{'style_prepend'},
420 $attr_page{'style'},
421 0 $attr_page{'style_append'}
422 );
423 0 ▶ $attr_page{'style'}=\@style if @style;
Branch: 1 branch
BranchTrueFalseTotal
if @style 0 0 0
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 3 ▶ if ($attr_page{'script_prepend'} || $attr_page{'script_append'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"script_prepend"} or $attr_page{"script_append"}) 0 3 3
Condition33%1/3
$attr_page{"script_prepend"} or $attr_page{"script_append"}
l!l&&r!l&&!r
003
MC/DC0%0/2
$attr_page{"script_prepend"} or $attr_page{"script_append"}
$attr_page{"script_prepend"} $attr_page{"script_append"}
Truth table33%1/3
A or B
A= $attr_page{"script_prepend"}B= $attr_page{"script_append"}
ABresult
1X1
011
000
431 0 ▶ my @script=map { ref($_) eq 'ARRAY' ? @{$_} : $_ } grep {$_} (
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
432 $attr_page{'script_prepend'},
433 $attr_page{'script'},
434 0 $attr_page{'script_append'}
435 );
436 0 ▶ $attr_page{'script'}=\@script if @script;
Branch: 1 branch
BranchTrueFalseTotal
if @script 0 0 0
437 }
438  
439  
440 # Add meta section
441 #
442 3 my @meta;
443 3 ▶ if (my $hr=$attr_page{'meta'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hr = $attr_page{'meta'}) { } 0 3 3
444 0 debug('have meta hr: %s', Dumper($hr));
445 0 @meta=$self->meta({content => $attr_page{'meta'}});
446 0 debug('processed to: %s', Dumper(\@meta));
447 }
448 else {
449 3 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 3 my @base;
473 3 ▶ if ($attr_page{'base'} || $attr_page{'target'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"base"} or $attr_page{"target"}) 0 3 3
Condition33%1/3
$attr_page{"base"} or $attr_page{"target"}
l!l&&r!l&&!r
003
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 3 my @link;
484 3 ▶ if (my $style=$attr_page{'style'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $style = $attr_page{"style"}) 0 3 3
485
486 # Generate HTML for link tag stylheet
487 #
488 0 push @link, $self->_start_html_tag('link', 'href', $style,
489 { rel=>'stylesheet'});
490  
491 }
492 3 ▶ if (my $include_style=$attr_page{'include_style'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $include_style = $attr_page{"include_style"}) 0 3 3
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 3 ▶ if (my $author=$attr_page{'author'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $author = $attr_page{"author"}) 0 3 3
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 3 my @script;
516 3 ▶ if (my $script=$attr_page{'script'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $script = $attr_page{"script"}) 0 3 3
517
518 # Script same as style above
519 #
520 0 push @script, $self->_start_html_tag('script', 'src', $script);
521 }
522 3 ▶ if (my $include_script=$attr_page{'include_script'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $include_script = $attr_page{"include_script"}) 0 3 3
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 3 my @include;
535 3 ▶ if (my $fn=$attr_page{'include'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fn = $attr_page{'include'}) { } 0 3 3
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 3 debug('no include file, adding default metadata');
563 3 push @meta, $self->meta({ content => $WEBDYNE_META });
564
565 }
566  
567
568
569 # Build title
570 #
571 3 my ($title, $title_html);
572 0 ▶ unless (@include && (grep {/<title>.*?<\/title>/i} @include)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@include and grep {m[<title>.*?</title>]i;} @include) 3 0 3
Condition33%1/3
@include and grep {m[<title>.*?</title>]i;} @include
!ll&&!rl&&r
300
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 3 ▶ if (defined($attr_page{'title'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $attr_page{'title'}) { } 0 3 3
elsif (exists $attr_page{'title'}) { } 0 3 3
574 # Title is defined (presumably some string)
575 #
576 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 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 3 debug('title attr not present, using default title');
589 3 $title_html=$self->title($title=$WEBDYNE_HTML_DEFAULT_TITLE);
590 }
591 }
592 3 ▶ debug('title: %s', $title || '*undef*');
Condition50%1/2
$title || '*undef*'
l!l
30
MC/DC0%0/1
$title || '*undef*'
$title
Truth table50%1/2
A
A= $title
Aresult
11
00
593
594
595 # Add title as introductory heading if wanted
596 #
597 3 my $heading_html='';
598 3 ▶ 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 3 3
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 3 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 3 push @html, $self->open('html', \%attr), $head . $self->open('body') . $heading_html;
626 3 debug('html: %s', Dumper(\@html));
627 3 return join($/, @html);
628  
629 }
630  
631  
632 0 ▶sub _start_html_tag {
Subroutine _start_html_tag: not called CC=4 SCAR=30.0
633  
634 0 my ($self, $tag, $attr, $param_ar, $attr_hr)=@_;
635 0 my @html;
636 0 ▶ unless (ref($param_ar) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $param_ar eq "ARRAY") 0 0 0
637 0 $param_ar=[$param_ar];
638 }
639 0 ▶ if ($WEBDYNE_START_HTML_PARAM_STATIC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WebDyne::HTML::Tiny::WEBDYNE_START_HTML_PARAM_STATIC) 0 0 0
640 0 $attr_hr->{'static'}=1;
641 }
642 0 foreach my $param (@{$param_ar}) {
643 0 my $html_or=HTML::Element->new($tag, $attr=>$param, %{$attr_hr} );
644 0 push @html, $html_or->as_HTML();
645 }
646 0 return join('', @html);
647
648 }
649
650  
651 0 ▶sub _end_html0 { # No longer needed
Subroutine _end_html0: not called CC=1 SCAR=6.9
652  
653 # Stub for WebDyne UNIVERSAL::can to find
654 #
655 #shift()->SUPER::end_html(@_);
656 0 my ($self, $attr_hr)=@_;
657 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 0 ▶sub html {
Subroutine html: not called CC=2 SCAR=17.9
Pod undocumented
670  
671 0 my $self=shift();
672 0 debug("$self html() param: %s", Dumper(\@_));
673 # Move default attributes into <html> tag unless user has explicitely supplied
674 0 ▶ unshift (@_, $WEBDYNE_HTML_PARAM) unless (ref $_[0] eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 0 0 0
675 0 return $WEBDYNE_DTD . $self->SUPER::html(@_);
676  
677 }
678  
679  
680 3 ▶sub head {
Subroutine head: called CC=4 SCAR=15.2
Pod undocumented
681  
682 3 my ($self, $html, @param)=@_;
683 #debug("$self head, html:$html, attr:%s", Dumper(\@_));
684 3 debug("$self head, param:%s", Dumper($_[2]));
685 3 my $r=$self->{'_r'};
686 3 ▶ my $no_head_insert=(ref($r) && $r->{'no_head_insert'});
Condition33%1/3
ref $r && $r->{'no_head_insert'}
!ll&&!rl&&r
030
MC/DC0%0/2
ref $r && $r->{'no_head_insert'}
ref $r $r->{'no_head_insert'}
Truth table33%1/3
A && B
A= ref $rB= $r->{'no_head_insert'}
ABresult
0X0
100
111
687 3 ▶ $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 3 0 3
Condition33%1/3
$WebDyne::HTML::Tiny::WEBDYNE_HEAD_INSERT and not $no_head_insert
!ll&&!rl&&r
003
MC/DC0%0/2
$WebDyne::HTML::Tiny::WEBDYNE_HEAD_INSERT and not $no_head_insert
$WebDyne::HTML::Tiny::WEBDYNE_HEAD_INSERT not $no_head_insert
Truth table33%1/3
A and not(B)
A= $WebDyne::HTML::Tiny::WEBDYNE_HEAD_INSERTB= not $no_head_insert
ABresult
0X0
100
111
688 3 return $self->SUPER::head(grep {$_} ($html, @param));
689
690 }
691  
692  
693 3 ▶sub _start_html_bare {
Subroutine _start_html_bare: called CC=1 SCAR=0.0
694  
695 # Special. Called by optimise_two in WebDybe compile instead of start_html above
696 #
697 3 my $self=shift();
698 3 debug("$self _start_html_bare param:%s", Dumper(\@_));
699 3 return $WEBDYNE_DTD . $self->SUPER::open('html', @_);
700 #return $WEBDYNE_DTD
701  
702 }
703  
704  
705 # Start_form shortcut
706 #
707 0 ▶sub _start_form {
Subroutine _start_form: not called CC=2 SCAR=17.9
708  
709 0 my ($self, $attr_hr, @param)=@_;
710 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 0 ▶sub _start_multipart_form {
Subroutine _start_multipart_form: not called CC=2 SCAR=17.9
726 0 debug("$_[0] _start_multipart_form");
727 0 ▶ return shift()->start_form({enctype => +MULTIPART, %{$_[0] ? shift() : {}}}, @_);
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
728 }
729  
730  
731 0 ▶sub end_multipart_form {
Subroutine end_multipart_form: not called CC=1 SCAR=6.9
Pod undocumented
732 0 debug("$_[0] _end_multipart_form");
733 0 return shift()->end_form(@_);
734 }
735  
736  
737 # Support CGI comment syntax. See aliasing to ~comment in top section
738 #
739 0 ▶sub _comment {
Subroutine _comment: not called CC=1 SCAR=6.9
740  
741 0 my ($self, $attr_hr)=@_;
742 0 debug("$self comment, attr:%s", Dumper($attr_hr));
743 #return sprintf("\n<!-- %s -->\n", $attr_hr->{'text'});
744 0 my $html=sprintf('<!-- %s -->', $attr_hr->{'text'});
745 0 if (WEBDYNE_HTML_NEWLINE) {
746 $html="\n${html}\n";
747 }
748 0 return $html;
749  
750 }
751  
752  
753 # Meta tag
754 #
755 9 ▶sub meta {
Subroutine meta: called CC=6 SCAR=18.0
Pod undocumented
756  
757 9 my ($self, $attr_hr)=@_;
758 9 debug("$self in meta, attr %s", Dumper($attr_hr));
759 9 my @html;
760 9 ▶ if (ref(my $meta_hr=$attr_hr->{'content'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref(my $meta_hr = $attr_hr->{'content'}) eq 'HASH') { } 3 6 9
761 3 debug('meta is HASH');
762
763 # Want to be determenistic so sort keys unless tied
764 #
765 3 my @name=keys(%{$meta_hr});
766 3 ▶ unless(my $or=tied(%{$meta_hr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $or = tied %{$meta_hr;}) { } 0 3 3
767 # Not tied hash to sort keys
768 #
769 3 debug('meta hash not tied, sorting');
770 3 @name=sort { $a cmp $b } @name;
771 }
772 else {
773 0 debug("meta_hr is tied to $or");
774 }
775
776 #while (my ($name, $content)=each %{$attr_hr->{'content'}}) {
777 3 foreach my $name (@name) {
778 6 my $content=$meta_hr->{$name};
779 6 ▶ if ((my ($key, $value)=split(/=/, $name)) == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ((() = split(/=/, $name, 3)) == 2) { } 3 3 6
780  
781 # Self contained
782 #
783 3 debug("split to $key: $value");
784 3 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) { } 0 3 3
785 0 push @html, $self->SUPER::meta({$key => $value, content => $content});
786 }
787 else {
788 3 push @html, $self->SUPER::meta({$key => $value});
789 }
790 }
791 else {
792 3 push @html, $self->SUPER::meta({name => $name, content => $content});
793 }
794 }
795 }
796 else {
797 6 debug('meta is plain');
798 6 push @html, $self->SUPER::meta($attr_hr)
799 }
800 9 return join($/, @html);
801  
802 }
803  
804  
805 # Link tag - expand array into multiple if needed
806 #
807 0 ▶sub link {
Subroutine link: not called CC=2 SCAR=17.9
Pod undocumented
808  
809 0 my ($self, $attr_hr)=@_;
810 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 0 ▶sub script {
Subroutine script: not called CC=8 SCAR=42.8
Pod undocumented
828  
829 0 my ($self, $attr_hr, @param)=@_;
830 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 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 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 debug("src post split: $src");
858 0 ▶ if ($src[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src[1]) 0 0 0
859 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 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 debug('html: %s', Dumper(\@html));
879 0 return join($/, @html);
880  
881 }
882  
883  
884 0 ▶sub _radio_checkbox {
Subroutine _radio_checkbox: not called CC=2 SCAR=17.9
885  
886  
887 # Return a radio or checkboxinput field, adding label tags if needed
888 #
889 0 my ($self, $tag, $attr_hr, $html)=@_;
890 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 0 ▶sub _radio_checkbox_group {
Subroutine _radio_checkbox_group: not called CC=24 SCAR=64.0
905  
906  
907 # Build a checkbox or radio group
908 #
909 0 my ($self, $tag, $attr_hr)=@_;
910 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 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 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 0 ▶sub checkbox_group {
Subroutine checkbox_group: not called CC=1 SCAR=6.9
Pod undocumented
1018 0 debug("$_[0] checkbox_group");
1019 0 return shift()->_radio_checkbox_group('checkbox', @_)
1020 }
1021  
1022  
1023 0 ▶sub radio_group {
Subroutine radio_group: not called CC=1 SCAR=6.9
Pod undocumented
1024 0 debug("$_[0] radio_group");
1025 0 return shift()->_radio_checkbox_group('radio', @_)
1026 }
1027  
1028  
1029 0 ▶sub checkbox {
Subroutine checkbox: not called CC=12 SCAR=50.5
Pod undocumented
1030
1031  
1032 # Bit more complex
1033 #
1034 0 my ($self, $attr_hr, @html)=@_;
1035 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 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 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 debug("param name:$name exists but is not defined, clearing checked attribute");
1102 0 delete $attr{'checked'};
1103
1104 }
1105 else {
1106
1107 0 ▶ debug("no $name param, using tag default: %s", $attr{'checked'} ? 'checked=1' : '<unchecked>');
Branch: 1 branch
BranchTrueFalseTotal
$attr{'checked'} ? : 0 0 0
1108
1109 }
1110 }
1111 else {
1112
1113 0 debug('no name attr');
1114
1115 }
1116 }
1117 else {
1118
1119 # Custom value
1120 #
1121 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 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 0 ▶sub popup_menu {
Subroutine popup_menu: not called CC=26 SCAR=65.5
Pod undocumented
1138  
1139  
1140 # Build a checkbox or radio group
1141 #
1142 0 my ($self, $attr_hr)=@_;
1143 0 my %attr_select=%{$attr_hr};
1144 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 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 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 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 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 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 0 ▶sub scrolling_list {
Subroutine scrolling_list: not called CC=2 SCAR=17.9
Pod undocumented
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)=@_;
1333 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 0 ▶sub textarea {
Subroutine textarea: not called CC=7 SCAR=40.3
Pod undocumented
1342  
1343 # Slightly different handling for textarea
1344 #
1345 0 my ($self, $attr_hr, @param)=@_;
1346 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 11 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=2 SCAR=6.9
1392 11 debug("AUTOLOAD: $AUTOLOAD");
1393 11 ▶ if (my ($action, $tag)=($AUTOLOAD=~/\:\:(start|end|open|close)_([^:]+)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $WebDyne::HTML::Tiny::AUTOLOAD =~ /\:\:(start|end|open|close)_([^:]+)$/) 3 8 11
1394 3 debug("action: $action, tag: $tag");
1395 3 ▶ *{$AUTOLOAD}=sub {shift()->$action($tag, @_)};
Subroutine __ANON__: called CC=1 SCAR=0.0
1396 3 return &{$AUTOLOAD}(@_);
1397 }
1398 }
1399 __END__
« lib/WebDyne/Compile.pm ↑ Summary lib/WebDyne/Util.pm »