blib/lib/WebDyne/HTML/Tiny.pm

filter: Statementstmt 91.5% 464 / 507 Branchbran 78.8% 145 / 184 Conditioncond 54.6% 71 / 130 MC/DCmcdc 21.7% 17 / 78 Subroutinesub 93.7% 45 / 48 Podpod 5.5% 1 / 18 totaltotal 76.9% 743 / 965 CC 155 SCAR 29.8
CC
155
Cov
83%
_start_html
48.5
_radio_checkbox_group
27.0
popup_menu
26.9
CRAP 19.8
« lib/WebDyne/CGI/Simple.pm ↑ Summary lib/WebDyne/Request/Fake.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 40 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 40 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # Constants, inheritance
24 #
25 40 our $AUTOLOAD;
26 40 our @ISA=qw(HTML::Tiny);
27  
28  
29 # External Modules
30 #
31 40 ▶use HTML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 #use CGI::Simple;
33 40 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 40 ▶use HTML::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36  
37 # WebDyne Modules
38 #
39 40 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 40 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 40 ▶use WebDyne::CGI::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43  
44 # Constants
45 #
46 40 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 40 URL_ENCODED => 'application/x-www-form-urlencoded',
49 MULTIPART => 'multipart/form-data'
50  
51 40 };
52  
53  
54 # Package state
55 #
56 40 my %Package;
57  
58  
59 # Version information
60 #
61 40 $VERSION='3.029';
62  
63  
64 # Debug load
65 #
66 40 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 40 *{'WebDyne::HTML::Tiny::~comment'}=\&_comment;
72 40 ▶*{'WebDyne::HTML::Tiny::entity_encode'}=sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 12627 my ($self, $value)=@_;
74 12627 return $value unless WEBDYNE_CGI_AUTOESCAPE;
75 12627 return HTML::Tiny::entity_encode($self, $value);
76 40 };
77  
78  
79 # All done. Positive return
80 #
81 40 ▶return ${&_init()} || err('error running init code');
Condition33%1/3
${&_init();} || err('error running init code')
l!l&&r!l&&!r
4000
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 561 ▶sub new {
Subroutine new: called CC=4 SCAR=14.7
Pod documented
88  
89  
90 # Start new instance
91 #
92 561 my ($class, @param)=@_;
93 561 my %param;
94 561 ▶ if (ref($param[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param[0] eq 'HASH') { } 0 561 561
95 0 %param=%{$param[0]};
96 }
97 else {
98 561 %param=@param;
99 }
100 561 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 561 ▶ $param{'noshortcut'}; # no sense before ? was || $Package{'_shortcut_enable'};
Branch: 1 branch
BranchTrueFalseTotal
unless $param{"noshortcut"} 561 0 561
107
108
109 # Get HTML::Tiny ref
110 #
111 561 ▶ 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
55920
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 561 $self->{'_r'}=$param{'r'};
117
118  
119 # Done
120 #
121 561 return $self;
122  
123 }
124  
125  
126 38 ▶sub Vars {
Subroutine Vars: called CC=2 SCAR=7.6
Pod undocumented
127  
128 # Get CGI::Simple Vars to ensure we can find values needed to persist choices across form submissions
129 #
130 38 my $self=shift();
131 38 0 && debug("$self Vars");
132 38 ▶ return ($self->{'_Vars'} ||= $self->CGI()->Vars());
Condition33%1/3
$self->{"_Vars"} ||= $self->CGI->Vars
l!l&&r!l&&!r
0380
MC/DC0%0/2
$self->{"_Vars"} ||= $self->CGI->Vars
$self->{"_Vars"} $self->CGI->Vars
Truth table33%1/3
A ||= B
A= $self->{"_Vars"}B= $self->CGI->Vars
ABresult
1X1
011
000
133  
134 }
135  
136  
137 313 ▶sub CGI {
Subroutine CGI: called CC=2 SCAR=7.0
Pod undocumented
138  
139
140 # Get CGI::Simple object ref
141 #
142 313 my $self=shift();
143 313 0 && debug("$self CGI");
144 313 ▶ 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
259540
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 40 ▶sub _init {
Subroutine _init: called CC=7 SCAR=20.1
150  
151  
152 # Initialise various subs
153 #
154 40 ▶ *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
4000
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 40 ▶ *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
4000
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 40 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 40 my %persist=(
173 textfield => 1,
174 password_field => 1,
175 filefield => 1
176 );
177  
178  
179 # Re-impliment CGI input shortcut tags
180 #
181 40 foreach my $tag (qw(textfield password_field filefield button submit reset defaults image_button hidden button)) {
182
183 320 ▶ *{$tag}=sub {
Subroutine __ANON__: called CC=10 SCAR=23.6
184 233 my ($self, $attr_hr, @param)=@_;
185 233 0 && debug("$self $tag, attr_hr: %s", Dumper($attr_hr));
186 233 ▶ if (defined($attr_hr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr_hr) { } 197 36 233
187 # Copy attr so don't pollute ref
188 197 my %attr=%{$attr_hr};
189 197 my $label=delete $attr{'label'};
190 #my $param_hr=$self->Vars();
191 197 my $param_hr=$self->CGI->Vars();
192 197 ▶ if ($persist{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($persist{$tag}) 19 178 197
193 19 ▶ 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"}) 2 17 19
Condition66%4/6
$attr{"name"} and my $value = $$param_hr{$attr{"name"}} and not $attr{"force"}
!ll&&!rl&&r
1702
$attr{"name"} and my $value = $$param_hr{$attr{"name"}}
!ll&&!rl&&r
0172
MC/DC33%1/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 table50%2/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 2 $attr{'value'}=$value;
195 }
196 }
197
198 # Wrap in label if needed
199 #
200 197 ▶ if ($label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label) { } 2 195 197
201 2 ▶ return $self->label(join('', grep {$_} @param, $label) . $self->input({type => $type{$tag} || $tag, %attr}));
Condition33%1/3
$type{$tag} || $tag
l!l&&r!l&&!r
200
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
202 }
203 else {
204 195 ▶ return $self->input({type => $type{$tag} || $tag, %attr}, @param);
Condition66%2/3
$type{$tag} || $tag
l!l&&r!l&&!r
351600
MC/DC0%0/2
$type{$tag} || $tag
$type{$tag} $tag
Truth table66%2/3
A || B
A= $type{$tag}B= $tag
ABresult
1X1
011
000
205 }
206 }
207 else {
208 36 ▶ return $self->input({type => $type{$tag} || $tag}, @param)
Condition33%1/3
$type{$tag} || $tag
l!l&&r!l&&!r
0360
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
209 }
210  
211 400 ▶ } unless UNIVERSAL::can(__PACKAGE__, $tag);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can(__PACKAGE__, $tag) 320 80 400
212 }
213  
214  
215 # Isindex deprecated but reimplement anyway
216 #
217 40 foreach my $tag (qw(isindex)) {
218  
219 40 ▶ 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 40 ▶ unless UNIVERSAL::can(__PACKAGE__, $tag);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can(__PACKAGE__, $tag) 40 0 40
222  
223 }
224  
225  
226 # Done return OK
227 #
228 40 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 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 1974 ▶sub shortcut_disable {
Subroutine shortcut_disable: called CC=4 SCAR=14.0
Pod undocumented
250  
251 40 ▶ no warnings qw(redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
252 1974 0 && debug('shortcut_disable: %s', Dumper(\@_));
253 1974 foreach my $sub (grep {/^(?:_start|_end)/} keys %{__PACKAGE__ . '::'}) {
254 11844 (my $sub_start=$sub)=~s/^_//;
255  
256 #print "disable $sub_start=>$sub";
257 11844 ▶ if (my ($action, $tag)=($sub_start=~/^(start|end)_([^:]+)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sub_start =~ /^(start|end)_([^:]+)$/) 11844 0 11844
258  
259 #print "action: $action, tag: $tag\n";
260 11844 ▶ *{$sub_start}=sub {shift()->$action($tag, @_)};
Subroutine __ANON__: called CC=1 SCAR=0.0
261 }
262 }
263 1974 delete $Package{'_shortcut_enable'};
264
265 # || *start_html to remove warnings
266 1974 ▶ *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
197400
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 2535 ▶sub shortcut_enable {
Subroutine shortcut_enable: called CC=2 SCAR=6.9
Pod undocumented
272  
273 40 ▶ no warnings qw(redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
274 2535 0 && debug('shortcut_enable: %s', Dumper(\@_));
275 2535 foreach my $sub (grep {/^(?:_start|_end])/} keys %{__PACKAGE__ . '::'}) {
276 12675 (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 12675 0 && debug("enable $sub_start=>$sub, %s", *{__PACKAGE__ . "::${sub_start}"}{'CODE'});
287 12675 *{$sub_start}=\&{$sub};
288 }
289 2535 $Package{'_shortcut_enable'}++;
290  
291 #*start_html=\&_start_html_bare;
292  
293 }
294  
295  
296 # Start_html shorcut and include DTD
297 #
298 1564 ▶sub _start_html {
Subroutine _start_html: called CC=40 SCAR=38.8
299  
300  
301 # Get self ref and any attributes passed
302 #
303 1564 my ($self, $attr_hr, @param)=@_;
304 1564 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 1564 my $r=$self->{'_r'};
312 1564 ▶ my $no_head_insert=(ref($r) && $r->{'no_head_insert'});
Condition100%3/3
ref $r && $r->{'no_head_insert'}
!ll&&!rl&&r
1415437
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 1564 ▶ my $webdyne_start_html_param_hr=$no_head_insert
Branch: 1 branch
BranchTrueFalseTotal
$no_head_insert ? : 7 1557 1564
314 ? {}
315 : $WEBDYNE_START_HTML_PARAM;
316  
317  
318 # Attributes we are going to use
319 #
320 1564 0 && debug('WEBDYNE_START_HTML_PARAM: %s', Dumper($WEBDYNE_START_HTML_PARAM));
321 my %attr=(
322 1564 %{$WEBDYNE_HTML_PARAM},
323 1564 %{$webdyne_start_html_param_hr},
324 1564 %{$attr_hr}
325 );
326 1564 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 617 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 1564 ), keys %{$WEBDYNE_START_HTML_SHORTCUT_HR});
366 1564 0 && debug('start_html %s', Dumper(\%attr_page));
367  
368  
369 # Start with the DTD
370 #
371 1564 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 1564 foreach my $attr (qw(static cache handler sse ws require import)) {
378 10948 ▶ if (my $value=$attr_page{$attr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $attr_page{$attr}) 37 10911 10948
379 37 0 && debug("found attr: $attr, setting to value: $value");
380 37 $self->{"_${attr}"}=$value;
381 37 ▶ $self->{'_static'} ||=1 if ($attr eq 'cache');
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "cache" 21 16 37
Condition100%2/2
$self->{"_static"} ||= 1
l!l
147
MC/DC100%1/1
$self->{"_static"} ||= 1
$self->{"_static"}
Truth table100%2/2
A
A= $self->{"_static"}
Aresult
11
00
382 }
383 }
384
385
386 # Shortcuts ? Add to relevant attributes
387 #
388 1564 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 0 ▶ 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 1564 ▶ if ($attr_page{'style_prepend'} || $attr_page{'style_append'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"style_prepend"} or $attr_page{"style_append"}) 3 1561 1564
Condition100%3/3
$attr_page{"style_prepend"} or $attr_page{"style_append"}
l!l&&r!l&&!r
211561
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 1564 ▶ if ($attr_page{'script_prepend'} || $attr_page{'script_append'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"script_prepend"} or $attr_page{"script_append"}) 3 1561 1564
Condition100%3/3
$attr_page{"script_prepend"} or $attr_page{"script_append"}
l!l&&r!l&&!r
211561
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 1564 my @meta;
443 1564 ▶ if (my $hr=$attr_page{'meta'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hr = $attr_page{'meta'}) { } 67 1497 1564
444 67 0 && debug('have meta hr: %s', Dumper($hr));
445 67 @meta=$self->meta({content => $attr_page{'meta'}});
446 67 0 && debug('processed to: %s', Dumper(\@meta));
447 }
448 else {
449 1497 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 1564 my @base;
473 1564 ▶ if ($attr_page{'base'} || $attr_page{'target'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"base"} or $attr_page{"target"}) 15 1549 1564
Condition66%2/3
$attr_page{"base"} or $attr_page{"target"}
l!l&&r!l&&!r
1501549
MC/DC50%1/2
$attr_page{"base"} or $attr_page{"target"}
$attr_page{"base"} $attr_page{"target"}
Truth table66%2/3
A or B
A= $attr_page{"base"}B= $attr_page{"target"}
ABresult
1X1
011
000
474 15 my %attr_base;
475 15 ▶ $attr_base{'href'} = $attr_page{'base'} if $attr_page{'base'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_page{"base"} 15 0 15
476 15 ▶ $attr_base{'target'} = $attr_page{'target'} if $attr_page{'target'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_page{"target"} 15 0 15
477 15 push @base, $self->base(\%attr_base);
478 }
479
480  
481 # Add any stylesheets
482 #
483 1564 my @link;
484 1564 ▶ if (my $style=$attr_page{'style'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $style = $attr_page{"style"}) 86 1478 1564
485
486 # Generate HTML for link tag stylheet
487 #
488 86 push @link, $self->_start_html_tag('link', 'href', $style,
489 { rel=>'stylesheet'});
490  
491 }
492 1564 ▶ if (my $include_style=$attr_page{'include_style'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $include_style = $attr_page{"include_style"}) 30 1534 1564
493  
494 # Generate HTML to make an include section for any styles user wants, wrap in <style> tag
495 #
496 30 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 1564 ▶ if (my $author=$attr_page{'author'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $author = $attr_page{"author"}) 0 1564 1564
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 1564 my @script;
516 1564 ▶ if (my $script=$attr_page{'script'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $script = $attr_page{"script"}) 71 1493 1564
517
518 # Script same as style above
519 #
520 71 push @script, $self->_start_html_tag('script', 'src', $script);
521 }
522 1564 ▶ if (my $include_script=$attr_page{'include_script'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $include_script = $attr_page{"include_script"}) 15 1549 1564
523
524 # Include script same as style above
525 #
526 15 push @script, $self->_start_html_tag('include', 'file', $include_script,
527 { wrap =>'script'});
528  
529 }
530
531
532 # Include any other files
533 #
534 1564 my @include;
535 1564 ▶ if (my $fn=$attr_page{'include'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fn = $attr_page{'include'}) { } 0 1564 1564
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 1564 0 && debug('no include file, adding default metadata');
563 1564 push @meta, $self->meta({ content => $WEBDYNE_META });
564
565 }
566  
567
568
569 # Build title
570 #
571 1564 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) 1564 0 1564
Condition33%1/3
@include and grep {m[<title>.*?</title>]i;} @include
!ll&&!rl&&r
156400
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 1564 ▶ if (defined($attr_page{'title'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $attr_page{'title'}) { } 243 1321 1564
elsif (exists $attr_page{'title'}) { } 0 1321 1321
574 # Title is defined (presumably some string)
575 #
576 243 0 && debug('title attr defined, using: %s', $attr_page{'title'});
577 243 $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 1321 0 && debug('title attr not present, using default title');
589 1321 $title_html=$self->title($title=$WEBDYNE_HTML_DEFAULT_TITLE);
590 }
591 }
592 1564 0 && debug('title: %s', $title || '*undef*');
593
594
595 # Add title as introductory heading if wanted
596 #
597 1564 my $heading_html='';
598 1564 ▶ 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")) 15 1549 1564
599 15 ▶ $heading_html=$self->$heading_tag($title) if $title;
Branch: 1 branch
BranchTrueFalseTotal
if $title 15 0 15
600 15 ▶ if ($attr_page{'hr'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_page{"hr"}) 15 0 15
601 15 $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 1564 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 1564 push @html, $self->open('html', \%attr), $head . $self->open('body') . $heading_html;
626 1564 0 && debug('html: %s', Dumper(\@html));
627 1564 return join($/, @html);
628  
629 }
630  
631  
632 202 ▶sub _start_html_tag {
Subroutine _start_html_tag: called CC=4 SCAR=13.9
633  
634 202 my ($self, $tag, $attr, $param_ar, $attr_hr)=@_;
635 202 my @html;
636 202 ▶ unless (ref($param_ar) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $param_ar eq "ARRAY") 182 20 202
637 182 $param_ar=[$param_ar];
638 }
639 202 ▶ if ($WEBDYNE_START_HTML_PARAM_STATIC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WebDyne::HTML::Tiny::WEBDYNE_START_HTML_PARAM_STATIC) 202 0 202
640 202 $attr_hr->{'static'}=1;
641 }
642 202 foreach my $param (@{$param_ar}) {
643 222 my $html_or=HTML::Element->new($tag, $attr=>$param, %{$attr_hr} );
644 222 push @html, $html_or->as_HTML();
645 }
646 202 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 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 320 ▶sub html {
Subroutine html: called CC=2 SCAR=6.9
Pod undocumented
670  
671 320 my $self=shift();
672 320 0 && debug("$self html() param: %s", Dumper(\@_));
673 # Move default attributes into <html> tag unless user has explicitely supplied
674 320 ▶ unshift (@_, $WEBDYNE_HTML_PARAM) unless (ref $_[0] eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 28 292 320
675 320 return $WEBDYNE_DTD . $self->SUPER::html(@_);
676  
677 }
678  
679  
680 991 ▶sub head {
Subroutine head: called CC=4 SCAR=13.9
Pod undocumented
681  
682 991 my ($self, $html, @param)=@_;
683 #debug("$self head, html:$html, attr:%s", Dumper(\@_));
684 991 0 && debug("$self head, param:%s", Dumper($_[2]));
685 991 my $r=$self->{'_r'};
686 991 ▶ my $no_head_insert=(ref($r) && $r->{'no_head_insert'});
Condition66%2/3
ref $r && $r->{'no_head_insert'}
!ll&&!rl&&r
09838
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 991 ▶ $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 34 957 991
Condition100%3/3
$WebDyne::HTML::Tiny::WEBDYNE_HEAD_INSERT and not $no_head_insert
!ll&&!rl&&r
949834
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 991 return $self->SUPER::head(grep {$_} ($html, @param));
689
690 }
691  
692  
693 586 ▶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 586 my $self=shift();
698 586 0 && debug("$self _start_html_bare param:%s", Dumper(\@_));
699 586 return $WEBDYNE_DTD . $self->SUPER::open('html', @_);
700 #return $WEBDYNE_DTD
701  
702 }
703  
704  
705 # Start_form shortcut
706 #
707 195 ▶sub _start_form {
Subroutine _start_form: called CC=2 SCAR=7.1
708  
709 195 my ($self, $attr_hr, @param)=@_;
710 195 0 && debug("$self _start_form, attr_hr:%s param:%s", Dumper($attr_hr, \@param));
711 195 my %default=(
712 method => 'post',
713 # Redundant
714 # enctype => +URL_ENCODED
715 );
716 195 ▶ map {$attr_hr->{$_} ||= $default{$_}}
Condition33%1/3
$attr_hr->{$_} ||= $default{$_}
l!l&&r!l&&!r
01950
MC/DC0%0/2
$attr_hr->{$_} ||= $default{$_}
$attr_hr->{$_} $default{$_}
Truth table33%1/3
A ||= B
A= $attr_hr->{$_}B= $default{$_}
ABresult
1X1
011
000
717 keys %default;
718 195 return $self->start('form', $attr_hr, @param);
719  
720 }
721  
722  
723 # Start multi-part form shortcut
724 #
725 45 ▶sub _start_multipart_form {
Subroutine _start_multipart_form: called CC=2 SCAR=7.1
726 45 0 && debug("$_[0] _start_multipart_form");
727 45 ▶ return shift()->start_form({enctype => +MULTIPART, %{$_[0] ? shift() : {}}}, @_);
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 45 0 45
728 }
729  
730  
731 15 ▶sub end_multipart_form {
Subroutine end_multipart_form: called CC=1 SCAR=0.0
Pod undocumented
732 15 0 && debug("$_[0] _end_multipart_form");
733 15 return shift()->end_form(@_);
734 }
735  
736  
737 # Support CGI comment syntax. See aliasing to ~comment in top section
738 #
739 182 ▶sub _comment {
Subroutine _comment: called CC=1 SCAR=0.0
740  
741 182 my ($self, $attr_hr)=@_;
742 182 0 && debug("$self comment, attr:%s", Dumper($attr_hr));
743 #return sprintf("\n<!-- %s -->\n", $attr_hr->{'text'});
744 182 my $html=sprintf('<!-- %s -->', $attr_hr->{'text'});
745 182 if (WEBDYNE_HTML_NEWLINE) {
746 $html="\n${html}\n";
747 }
748 182 return $html;
749  
750 }
751  
752  
753 # Meta tag
754 #
755 3550 ▶sub meta {
Subroutine meta: called CC=6 SCAR=17.9
Pod undocumented
756  
757 3550 my ($self, $attr_hr)=@_;
758 3550 0 && debug("$self in meta, attr %s", Dumper($attr_hr));
759 3550 my @html;
760 3550 ▶ if (ref(my $meta_hr=$attr_hr->{'content'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref(my $meta_hr = $attr_hr->{'content'}) eq 'HASH') { } 1576 1974 3550
761 1576 0 && debug('meta is HASH');
762
763 # Want to be determenistic so sort keys unless tied
764 #
765 1576 my @name=keys(%{$meta_hr});
766 1576 ▶ unless(my $or=tied(%{$meta_hr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $or = tied %{$meta_hr;}) { } 27 1549 1576
767 # Not tied hash to sort keys
768 #
769 1549 0 && debug('meta hash not tied, sorting');
770 1549 @name=sort { $a cmp $b } @name;
771 }
772 else {
773 27 0 && debug("meta_hr is tied to $or");
774 }
775
776 #while (my ($name, $content)=each %{$attr_hr->{'content'}}) {
777 1576 foreach my $name (@name) {
778 3195 my $content=$meta_hr->{$name};
779 3195 ▶ if ((my ($key, $value)=split(/=/, $name)) == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ((() = split(/=/, $name, 3)) == 2) { } 1602 1593 3195
780  
781 # Self contained
782 #
783 1602 0 && debug("split to $key: $value");
784 1602 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) { } 36 1566 1602
785 36 push @html, $self->SUPER::meta({$key => $value, content => $content});
786 }
787 else {
788 1566 push @html, $self->SUPER::meta({$key => $value});
789 }
790 }
791 else {
792 1593 push @html, $self->SUPER::meta({name => $name, content => $content});
793 }
794 }
795 }
796 else {
797 1974 0 && debug('meta is plain');
798 1974 push @html, $self->SUPER::meta($attr_hr)
799 }
800 3550 return join($/, @html);
801  
802 }
803  
804  
805 # Link tag - expand array into multiple if needed
806 #
807 45 ▶sub link {
Subroutine link: called CC=2 SCAR=7.0
Pod undocumented
808  
809 45 my ($self, $attr_hr)=@_;
810 45 0 && debug("$self link, attr %s", Dumper($attr_hr));
811 45 my @html;
812 45 ▶ if (ref($attr_hr->{'href'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr_hr->{'href'} eq 'ARRAY') { } 45 0 45
813 45 my %attr=%{$attr_hr};
814 45 my $href_ar=delete $attr{'href'};
815 45 map {push @html, $self->SUPER::link({%attr, href => $_})} @{$href_ar}
816 }
817 else {
818 0 push @html, $self->SUPER::link($attr_hr)
819 }
820 45 return join($/, @html);
821  
822 }
823  
824  
825 # Script tag - same deal
826 #
827 150 ▶sub script {
Subroutine script: called CC=8 SCAR=20.8
Pod undocumented
828  
829 150 my ($self, $attr_hr, @param)=@_;
830 150 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 150 my @html;
836 150 my %attr=%{$attr_hr};
837 150 ▶ if ($attr{'src'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr{'src'}) { } 63 87 150
838
839
840 # Convert to array
841 #
842 63 my $script_ar;
843 63 ▶ unless (ref($script_ar=$attr{'src'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($script_ar = $attr{"src"}) eq "ARRAY") 45 18 63
844 45 $script_ar=[$script_ar]
845 }
846 63 0 && debug('attr_hr: %s, script_ar: %s', Dumper($attr_hr, $script_ar));
847
848 # Iterate over each one
849 #
850 63 foreach my $src (@{$script_ar}) {
851 72 0 && debug("src: $src");
852 72 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 72 my @src=split(/#/, $src);
856 72 $src=$src[0];
857 72 0 && debug("src post split: $src");
858 72 ▶ if ($src[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src[1]) 9 63 72
859 9 0 && debug('split src: %s', Dumper(\@src));
860 9 foreach my $kv (split /&/, $src[1]) {
861 9 ▶ next unless length($kv);
Branch: 1 branch
BranchTrueFalseTotal
unless length $kv 0 9 9
862 9 ▶ if ( $kv =~ /^([^=]+)=(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kv =~ /^([^=]+)=(.*)$/) { } 0 9 9
863 0 $src_attr{$1}=$2;
864 }
865 else {
866 # no “=” means flag parameter
867 9 $src_attr{$kv} = [];
868 }
869 }
870 9 0 && debug("fragment attr: $src[1] decoded as %s from query_param: %s", Dumper(\%attr, \@src));
871 }
872 72 push @html, $self->SUPER::script({%src_attr, src => $src}, @param)
873 }
874 }
875 else {
876 87 push @html, $self->SUPER::script($attr_hr, @param)
877 }
878 150 0 && debug('html: %s', Dumper(\@html));
879 150 return join($/, @html);
880  
881 }
882  
883  
884 84 ▶sub _radio_checkbox {
Subroutine _radio_checkbox: called CC=2 SCAR=6.9
885  
886  
887 # Return a radio or checkboxinput field, adding label tags if needed
888 #
889 84 my ($self, $tag, $attr_hr, $html)=@_;
890 84 0 && debug("$self _radio_checkbox, tag:$tag attr_hr:%s", Dumper($attr_hr));
891 84 my %attr=%{$attr_hr};
892 84 ▶ if (my $label=delete $attr{'label'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $label = delete $attr{'label'}) { } 80 4 84
893 80 return $self->label($self->input({type => $tag, %attr}) . join('', grep {$_} $html, $label));
894 }
895 else {
896 4 return $self->input({type => $tag, %attr}) . $html;
897 }
898  
899 }
900  
901  
902 # Checkbox group
903 #
904 18 ▶sub _radio_checkbox_group {
Subroutine _radio_checkbox_group: called CC=24 SCAR=32.9
905  
906  
907 # Build a checkbox or radio group
908 #
909 18 my ($self, $tag, $attr_hr)=@_;
910 18 0 && debug("$self _radio_checbox_group tag:$tag attr: %s", Dumper($attr_hr));
911 18 my %attr=%{$attr_hr};
912  
913  
914 # Get hash ref of any existing CGI param
915 #
916 18 ▶ my $param_hr=($self->{'_Vars'} ||= $self->Vars()) ||
Condition60%3/5
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
l!l
180
$self->{"_Vars"} ||= $self->Vars
l!l&&r!l&&!r
1260
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 table50%1/2
A
A= ($self->{'_Vars'} ||= $self->Vars)
Aresult
11
00
Truth table66%2/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 18 ▶ my $cgi_or=$self->CGI() ||
Condition50%1/2
$self->CGI || (return err('unable to get CGI object'))
l!l
180
MC/DC0%0/1
$self->CGI || (return err('unable to get CGI object'))
$self->CGI
Truth table50%1/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 18 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 18 foreach my $attr (qw(default defaults checked disabled)) {
935 34 ▶ map {$attr_group{$attr}{$_}=1} @{(ref($attr{$attr}) eq 'ARRAY') ? $attr{$attr} : [$attr{$attr}]}
Branch: 1 branch
BranchTrueFalseTotal
ref $attr{$attr} eq 'ARRAY' ? : 14 6 20
936 72 ▶ if $attr{$attr};
Branch: 1 branch
BranchTrueFalseTotal
if $attr{$attr} 20 52 72
937 }
938 18 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 18 ▶ if (ref($attr{'values'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr{"values"} eq "HASH") 8 10 18
944  
945  
946 # It's a hash - use as labels, and push keys to values
947 #
948 8 $attr{'labels'}=(my $hr=delete $attr{'values'});
949 8 $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 18 ▶ 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'}) { } 2 16 18
Condition66%4/6
$attr_hr->{"name"} and my(@checked) = $cgi_or->param($attr_hr->{"name"}) and not $attr_hr->{"force"}
!ll&&!rl&&r
1602
$attr_hr->{"name"} and my(@checked) = $cgi_or->param($attr_hr->{"name"})
!ll&&!rl&&r
0162
MC/DC33%1/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 table50%2/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 2 my @checked=$cgi_or->param($attr_hr->{'name'});
965 2 0 && debug('checked: %s', Dumper(\@checked));
966 #$attr_group{'checked'} = { map { $_=>1 } (split(/\0/, $checked)) }
967 2 $attr_group{'checked'} = { map { $_=>1 } @checked }
968  
969 }
970 else {
971  
972 # Convert 'defaults' key to 'selected'
973 #
974 14 ▶ do {$attr_group{'checked'} ||= (delete($attr_group{'default'}) || delete($attr_group{'defaults'}))}
Condition33%2/6
$attr_group{"checked"} ||= delete $attr_group{"default"} || delete $attr_group{"defaults"}
l!l&&r!l&&!r
0140
delete $attr_group{'default'} || delete $attr_group{'defaults'}
l!l&&r!l&&!r
0140
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 16 ▶ if ($attr_group{'default'} || $attr_group{'defaults'});
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_group{"default"} or $attr_group{"defaults"}) 14 2 16
Condition66%2/3
$attr_group{"default"} or $attr_group{"defaults"}
l!l&&r!l&&!r
0142
MC/DC50%1/2
$attr_group{"default"} or $attr_group{"defaults"}
$attr_group{"default"} $attr_group{"defaults"}
Truth table66%2/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 18 ▶ if ($tag eq 'radio') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "radio") 2 16 18
983 #%{$attr_group{'defaults'}}=map {$_ => $attr_group{'defaults'}{$_}} ([sort keys %{$attr_group{'defaults'}}]->[0])
984 # if $attr_group{'defaults'};
985 2 %{$attr_group{'checked'}}=map {$_ => $attr_group{'checked'}{$_}} ([sort keys %{$attr_group{'checked'}}]->[0])
986 2 ▶ if $attr_group{'checked'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_group{"checked"} 2 0 2
987 }
988  
989  
990 # Now iterate and build actual tag, push onto HTML array
991 #
992 18 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 80 80
996 :
997 ();
998 80 ▶ $attr_tag{'name'}=$attr{'name'} if $attr{'name'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr{"name"} 80 0 80
999 80 $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 80 ▶ $attr_tag{'checked'}=[] if $attr_group{'checked'}{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_group{"checked"}{$value} 26 54 80
1004 80 ▶ $attr_tag{'disabled'}=[] if $attr_group{'disabled'}{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_group{"disabled"}{$value} 4 76 80
1005 80 ▶ $attr_tag{'label'}=$attr{'labels'}{$value} ? $attr{'labels'}{$value} : $value;
Branch: 1 branch
BranchTrueFalseTotal
$attr{'labels'}{$value} ? : 40 40 80
1006 80 push @html, $self->_radio_checkbox($tag, \%attr_tag);
1007 }
1008  
1009  
1010 # Return, separating with linebreaks if that is what is wanted.
1011 #
1012 18 ▶ return join($attr{'linebreak'} ? $self->br() : '', @html);
Branch: 1 branch
BranchTrueFalseTotal
$attr{'linebreak'} ? : 0 18 18
1013  
1014 }
1015  
1016  
1017 16 ▶sub checkbox_group {
Subroutine checkbox_group: called CC=1 SCAR=0.0
Pod undocumented
1018 16 0 && debug("$_[0] checkbox_group");
1019 16 return shift()->_radio_checkbox_group('checkbox', @_)
1020 }
1021  
1022  
1023 2 ▶sub radio_group {
Subroutine radio_group: called CC=1 SCAR=0.0
Pod undocumented
1024 2 0 && debug("$_[0] radio_group");
1025 2 return shift()->_radio_checkbox_group('radio', @_)
1026 }
1027  
1028  
1029 4 ▶sub checkbox {
Subroutine checkbox: called CC=11 SCAR=30.2
Pod undocumented
1030
1031  
1032 # Bit more complex
1033 #
1034 4 my ($self, $attr_hr, @html)=@_;
1035 4 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 4 my %attr=%{$attr_hr};
1041  
1042  
1043 # Get hash ref of any existing CGI param
1044 #
1045 4 ▶ my $param_hr=($self->{'_Vars'} ||= $self->Vars()) ||
Condition40%2/5
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
l!l
40
$self->{"_Vars"} ||= $self->Vars
l!l&&r!l&&!r
400
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 table50%1/2
A
A= ($self->{'_Vars'} ||= $self->Vars)
Aresult
11
00
Truth table33%1/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 4 ▶ my $cgi_or=$self->CGI() ||
Condition50%1/2
$self->CGI || (return err('unable to get CGI object'))
l!l
40
MC/DC0%0/1
$self->CGI || (return err('unable to get CGI object'))
$self->CGI
Truth table50%1/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 4 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 4 ▶ unless (my $value=$attr_hr->{'value'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $attr_hr->{'value'}) { } 0 4 4
1064 4 ▶ if (my $name=$attr_hr->{'name'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $attr_hr->{'name'}) { } 4 0 4
1065
1066 # Add hidden field with same name but 0 value
1067 #
1068 4 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 4 $hidden=$self->hidden({ name=>$name, value=>0, force=>1 });
1071
1072
1073 # Set value of this checkbox (if checked) to 1
1074 #
1075 4 $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 4 my $checked;
1083 #if (my $value=$param_hr->{$name}) {
1084 # map { $checked+=int($_) } split(/\0/, $value);
1085 #}
1086 4 ▶ if (my @value=$cgi_or->param($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@value) = $cgi_or->param($name)) 0 4 4
1087 0 map { $checked+=int($_) } @value;
1088 }
1089
1090
1091 # Run checkbox logic
1092 #
1093 4 ▶ if(exists($param_hr->{$name}) && $checked) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $param_hr->{$name} and $checked) { } 0 4 4
elsif (exists $param_hr->{$name} and not $checked) { } 0 4 4
Condition33%1/3
exists $param_hr->{$name} and $checked
!ll&&!rl&&r
400
MC/DC0%0/2
exists $param_hr->{$name} and $checked
exists $param_hr->{$name} $checked
Truth table33%1/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) {
Condition33%1/3
exists $param_hr->{$name} and not $checked
!ll&&!rl&&r
400
MC/DC0%0/2
exists $param_hr->{$name} and not $checked
exists $param_hr->{$name} not $checked
Truth table33%1/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 4 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 4 0 && debug('calling radio_checkbox');
1131 4 return $hidden.$self->_radio_checkbox('checkbox', \%attr, join('', @html))
1132 }
1133  
1134  
1135 # Popup menu or scrolling list
1136 #
1137 56 ▶sub popup_menu {
Subroutine popup_menu: called CC=26 SCAR=32.9
Pod undocumented
1138  
1139  
1140 # Build a checkbox or radio group
1141 #
1142 56 my ($self, $attr_hr)=@_;
1143 56 my %attr_select=%{$attr_hr};
1144 56 0 && debug("$self popup_menu, attr_hr:%s", Dumper($attr_hr));
1145
1146
1147 # Get hash ref of any existing CGI param
1148 #
1149 56 ▶ my $param_hr=($self->{'_Vars'} ||= $self->Vars()) ||
Condition60%3/5
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
l!l
560
$self->{"_Vars"} ||= $self->Vars
l!l&&r!l&&!r
40160
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 table50%1/2
A
A= ($self->{'_Vars'} ||= $self->Vars)
Aresult
11
00
Truth table66%2/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 56 ▶ my $cgi_or=$self->CGI() ||
Condition50%1/2
$self->CGI || (return err('unable to get CGI object'))
l!l
560
MC/DC0%0/1
$self->CGI || (return err('unable to get CGI object'))
$self->CGI
Truth table50%1/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 56 my @html;
1162
1163
1164 # Pull off any label
1165 #
1166 56 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 56 ▶ if (ref($attr_select{'values'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr_select{"values"} eq "HASH") 26 30 56
1172  
1173  
1174 # It's a hash - use as labels, and push keys to values
1175 #
1176 26 $attr_select{'labels'}=(my $hr=delete $attr_select{'values'});
1177 26 $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 56 labels => delete $attr_select{'labels'}
1187 );
1188  
1189  
1190 # Carefully handle options
1191 #
1192 56 foreach my $attr (qw(default defaults selected disabled)) {
1193  
1194 224 ▶ next unless exists $attr_select{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attr_select{$attr} 202 22 224
1195 22 my @values;
1196 22 ▶ if (ref($attr_select{$attr}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr_select{$attr} eq 'ARRAY') { } 10 12 22
1197 10 @values=@{$attr_select{$attr}}
1198 }
1199 else {
1200 # Single value
1201 12 @values=(grep {$_} $attr_select{$attr})
1202 }
1203  
1204 22 ▶ unless ($attr eq 'disabled') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr eq 'disabled') { } 12 10 22
1205 10 foreach my $value (@values) {
1206 14 0 && debug("value $value");
1207 14 $attr_option{$attr}{$value}=1;
1208 }
1209 10 delete $attr_select{$attr};
1210 }
1211 else { # handle disabled attr carefully
1212 12 ▶ if (@values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values) { } 10 2 12
1213 10 foreach my $value (@values) {
1214 12 $attr_option{$attr}{$value}=1;
1215 }
1216 10 delete $attr_select{$attr};
1217 }
1218 else {
1219 2 $attr_select{$attr}=[];
1220 }
1221 }
1222 }
1223  
1224  
1225 # Debug
1226 #
1227 56 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 56 ▶ 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'}) { } 2 54 56
Condition83%5/6
$attr_hr->{"name"} and my(@selected) = $cgi_or->param($attr_hr->{"name"}) and not $attr_hr->{"force"}
!ll&&!rl&&r
5402
$attr_hr->{"name"} and my(@selected) = $cgi_or->param($attr_hr->{"name"})
!ll&&!rl&&r
24302
MC/DC66%2/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 table75%3/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 2 $attr_option{'selected'} = { map { $_=>1 } @selected }
1242  
1243 }
1244 else {
1245  
1246 # Convert 'defaults' key to 'selected'
1247 #
1248 6 ▶ do {$attr_option{'selected'} ||= (delete($attr_option{'default'}) || delete($attr_option{'defaults'}))}
Condition33%2/6
$attr_option{"selected"} ||= delete $attr_option{"default"} || delete $attr_option{"defaults"}
l!l&&r!l&&!r
060
delete $attr_option{'default'} || delete $attr_option{'defaults'}
l!l&&r!l&&!r
600
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 54 ▶ if ($attr_option{'default'} || $attr_option{'defaults'});
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_option{"default"} or $attr_option{"defaults"}) 6 48 54
Condition66%2/3
$attr_option{"default"} or $attr_option{"defaults"}
l!l&&r!l&&!r
6048
MC/DC50%1/2
$attr_option{"default"} or $attr_option{"defaults"}
$attr_option{"default"} $attr_option{"defaults"}
Truth table66%2/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 56 ▶ $attr_select{'multiple'}=[] if $attr_select{'multiple'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_select{"multiple"} 4 52 56
1278 #map { delete $attr_select{$_} } (qw(default selected disabled));
1279 56 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 56 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 164 164
1288 :
1289 ();
1290 164 $attr_tag{'value'}=$value;
1291  
1292 # Note use of empty array for checked and disabled values as per HTML::Tiny specs
1293 164 ▶ $attr_tag{'selected'}=[] if $attr_option{'selected'}{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_option{"selected"}{$value} 16 148 164
1294 164 ▶ $attr_tag{'disabled'}=[] if $attr_option{'disabled'}{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $attr_option{"disabled"}{$value} 12 152 164
1295 164 ▶ my $label=$attr_option{'labels'}{$value} ? $attr_option{'labels'}{$value} : $value;
Branch: 1 branch
BranchTrueFalseTotal
$attr_option{'labels'}{$value} ? : 98 66 164
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 164 0 && debug("pushing option tag with label: $label, attr_tag: %s", Dumper(\%attr_tag));
1303 164 push @html, $self->option(\%attr_tag, $label)
1304  
1305 #}
1306 }
1307
1308
1309 # Now wrap in label if needed
1310 #
1311 56 0 && debug('creating select group with attr: %s, options:%s, label: %s', Dumper(\%attr_select, \@html), $label);
1312 56 ▶ if ($label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label) { } 2 54 56
1313 2 return $self->label($label . $self->select(\%attr_select, join($/, @html)));
1314 }
1315 else {
1316 54 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 2 ▶sub scrolling_list {
Subroutine scrolling_list: called CC=2 SCAR=7.1
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 2 my ($self, $attr_hr, @param)=@_;
1333 2 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 2 2
1335 #return shift()->popup_menu({size => scalar @{$_[0]->{'values'}}, %{shift()}}, @_);
1336 2 return $self->popup_menu({size => $size, %{$attr_hr}}, @param);
1337  
1338 }
1339  
1340  
1341 4 ▶sub textarea {
Subroutine textarea: called CC=7 SCAR=21.4
Pod undocumented
1342  
1343 # Slightly different handling for textarea
1344 #
1345 4 my ($self, $attr_hr, @param)=@_;
1346 4 0 && debug("self $self textarea, attr_hr: %s", Dumper($attr_hr));
1347  
1348  
1349 # Get hash ref of any existing CGI param
1350 #
1351 4 ▶ my $param_hr=($self->{'_Vars'} ||= $self->Vars()) ||
Condition40%2/5
($self->{'_Vars'} ||= $self->Vars) || (return err('unable able to CGI::Simple Vars'))
l!l
40
$self->{"_Vars"} ||= $self->Vars
l!l&&r!l&&!r
040
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 table50%1/2
A
A= ($self->{'_Vars'} ||= $self->Vars)
Aresult
11
00
Truth table33%1/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 4 my %attr=%{$attr_hr};
1358
1359
1360 # Label ?
1361 #
1362 4 my $label=delete $attr{'label'};
1363
1364  
1365 # Make sure entered text persists unless force in effect
1366 #
1367 4 my $content=delete($attr{'default'});
1368 4 ▶ 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 4 4
Condition33%2/6
$attr{"name"} and my $entered = $$param_hr{$attr{"name"}} and not $attr{"force"}
!ll&&!rl&&r
400
$attr{"name"} and my $entered = $$param_hr{$attr{"name"}}
!ll&&!rl&&r
040
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 table25%1/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 4 ▶ if ($label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label) { } 2 2 4
1380 2 return $self->label( $label . $self->SUPER::textarea(grep {$_} \%attr, $content));
1381 }
1382 else {
1383 # Have enough to build now
1384 #
1385 2 return $self->SUPER::textarea(grep {$_} \%attr, $content);
1386 }
1387
1388 }
1389  
1390  
1391 701 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=2 SCAR=6.9
1392 701 0 && debug("AUTOLOAD: $AUTOLOAD");
1393 701 ▶ if (my ($action, $tag)=($AUTOLOAD=~/\:\:(start|end|open|close)_([^:]+)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $WebDyne::HTML::Tiny::AUTOLOAD =~ /\:\:(start|end|open|close)_([^:]+)$/) 140 561 701
1394 140 0 && debug("action: $action, tag: $tag");
1395 140 ▶ *{$AUTOLOAD}=sub {shift()->$action($tag, @_)};
Subroutine __ANON__: called CC=1 SCAR=0.0
1396 140 return &{$AUTOLOAD}(@_);
1397 }
1398 }
1399 __END__
« lib/WebDyne/CGI/Simple.pm ↑ Summary lib/WebDyne/Request/Fake.pm »