blib/lib/HTML/Formulate.pm

filter: Statementstmt 96.4% 428 / 444 Branchbran 82.8% 227 / 274 Conditioncond 72.5% 156 / 215 MC/DCmcdc 49.1% 59 / 120 Subroutinesub 100% 32 / 32 Podpod 12.5% 3 / 24 totaltotal 81.6% 905 / 1109 CC 228 SCAR 37.7
CC
228
Cov
87%
cell_content
124.0
prerender_munge
30.7
cell_split_out_tx_attr
17.3
CRAP 43.5
↑ Summary
1 package HTML::Formulate;
2  
3 16 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use HTML::Tabulate 0.39;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use HTML::Entities qw(encode_entities);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 16 require Exporter;
10 16 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 @ISA = qw(HTML::Tabulate Exporter);
12 16 @EXPORT = qw(&render);
13 16 @EXPORT_OK = qw(&render);
14 16 %EXPORT_TAGS = ();
15  
16 16 $VERSION = '0.20';
17  
18 # Additional valid arguments, fields, and field attributes to those of
19 # HTML::Tabulate
20 16 my %VALID_ARG = (
21 # form: form tag attribute/value hash, or boolean scalar
22 form => 'HASH/SCALAR',
23 # formtype: form/table
24 formtype => 'SCALAR',
25 # primkey: primary key field, or list of primary key fields (for composites)
26 # primkey => 'SCALAR/ARRAY',
27 # submit: list of submit/button/reset elements for form
28 submit => 'SCALAR/ARRAY',
29 # submit_location: location of submit elements - top/bottom/both, default: bottom
30 submit_location => 'SCALAR',
31 # hidden: list of fields to render as hiddens, or hashref of field/value
32 # pairs; default: none
33 hidden => 'ARRAY/HASH',
34 # required: list of required/mandatory fields, or tokens 'ALL' or 'NONE'
35 required => 'ARRAY/SCALAR',
36 # use_name_as_id: add 'name' as 'id' field to input-type fields if none set
37 use_name_as_id => 'SCALAR',
38 # errors: hashref of field => (scalar/array of) validation-error-messages
39 errors => 'HASH',
40 # errors_where: where to display validation error messages:
41 # top: above form table (default)
42 # column: within form table, in a third table column
43 errors_where => 'SCALAR',
44 # errors_format: subroutine to format/render 'top' style error messages
45 errors_format => 'SCALAR/CODE',
46 );
47 16 my %VALID_FIELDS = (
48 # primary key defaults (deprecated?)
49 # -primkey => 'HASH',
50 # select defaults
51 '-select' => 'HASH',
52 # submit button defaults
53 -submit => 'HASH',
54 # required fields defaults
55 -required => 'HASH',
56 # error field defaults
57 -errors => 'HASH',
58 );
59 16 my %FIELD_ATTR = (
60 # type: how this field is rendered on the form (roughly an <input /> type)
61 # type => [ qw(text textarea password select hidden display static omit)],
62 type => [ qw(text textarea password file image button select checkbox radio hidden display static omit)],
63 # datatype: the validation datatype for this field (deprecated?)
64 # datatype => 'SCALAR/ARRAY',
65 # required: boolean
66 required => 'SCALAR',
67 # values: a list of possible values (scalars) for selects or radio buttons
68 'values' => 'ARRAY/CODE',
69 # vlabels: a list (or hashref keyed by values entries) of labels for use
70 # with selects or radio buttons
71 vlabels => 'ARRAY/HASH/CODE',
72 );
73 # Attributes applicable to the various input-type fields
74 16 my %TEXT_ATTR = map { $_ => 1 } qw(accesskey disabled id maxlength name notab onblur onchange onclick onfocus onselect readonly selected size tabindex taborder value vlabel);
75 16 my %INPUT_ATTR = map { $_ => 1 } qw(accesskey checked disabled id name notab onblur onchange onclick onfocus onselect readonly selected size tabindex taborder value vlabel);
76 16 my %SELECT_ATTR = map { $_ => 1 } qw(disabled id multiple name onblur onchange onfocus size tabindex vlabel);
77 16 my %TEXTAREA_ATTR = map { $_ => 1 } qw(accesskey cols disabled id name onblur onchange onfocus onselect readonly rows tabindex vlabel wrap);
78 16 my %TABLE_ATTR = map { $_ => 1 } qw(tr th td);
79 16 my %EMPTY_TAGS = map { $_ => 1 } qw(input br);
80  
81 sub get_valid_arg
82 119 ▶{
Subroutine get_valid_arg: called CC=2 SCAR=7.1
Pod undocumented
83 119 my $self = shift;
84 119 my %arg = $self->SUPER::get_valid_arg();
85 119 ▶ return wantarray ? ( %arg, %VALID_ARG ) : { %arg, %VALID_ARG };
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 119 0 119
86 }
87 sub get_valid_fields
88 117 ▶{
Subroutine get_valid_fields: called CC=2 SCAR=7.1
Pod undocumented
89 117 my $self = shift;
90 117 my %arg = $self->SUPER::get_valid_fields();
91 117 ▶ return wantarray ? ( %arg, %VALID_FIELDS ) : { %arg, %VALID_FIELDS };
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 117 0 117
92 }
93 sub get_field_attributes
94 25 ▶{
Subroutine get_field_attributes: called CC=2 SCAR=7.0
Pod undocumented
95 25 my $self = shift;
96 25 my %attr = $self->SUPER::get_field_attributes();
97 25 @attr{ keys %FIELD_ATTR } = values %FIELD_ATTR;
98 25 ▶ return wantarray ? %attr : \%attr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 25 25
99 }
100  
101  
102 # -------------------------------------------------------------------------
103 # Merge in form base defaults
104 #
105 sub init
106 25 ▶{
Subroutine init: called CC=5 SCAR=16.8
Pod undocumented
107 25 my $self = shift;
108 25 my $defn = shift;
109  
110 # Munge form => 1 to form => {} for cleaner merging
111 25 ▶ $defn->{form} = {} if $defn->{form} && ! ref $defn->{form};
Branch: 1 branch
BranchTrueFalseTotal
if $defn->{"form"} and not ref $defn->{"form"} 0 25 25
Condition33%1/3
$defn->{"form"} and not ref $defn->{"form"}
!ll&&!rl&&r
2500
MC/DC0%0/2
$defn->{"form"} and not ref $defn->{"form"}
$defn->{"form"} not ref $defn->{"form"}
Truth table33%1/3
A and not(B)
A= $defn->{"form"}B= not ref $defn->{"form"}
ABresult
0X0
100
111
112  
113 $defn = $self->merge({
114 form => { method => 'post' },
115 formtype => 'form',
116 table => { cellpadding => '2' },
117 style => 'across',
118 labels => 1,
119 hidden => {},
120 xhtml => 1,
121 use_name_as_id => 0,
122 null => '&nbsp;',
123 errors_where => 'top',
124 4 ▶ errors_format => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
125 4 return qq(<p style="color:red;font-weight:bold">\n<span class="error">) .
126 join(qq(</span><br />\n<span class="error">), @_) .
127 qq(</span>\n</p>\n);
128 },
129 # errors_format => sub {
130 # return qq(<p style="color:red;font-weight:bold">\n<span class="error">) .
131 # join(qq(</span><br />\n<span class="error">), @_) .
132 # qq(</span>\n</p>\n);
133 # },
134 field_attr => {
135 -select => { size => undef },
136 -submit => { maxlength => undef, size => undef },
137 -required => {
138 th => { style => 'color:blue' },
139 label_format => '<span class="required">%s</span>'
140 },
141 # -required => { label_format => '%s [*]' },
142 -errors => {
143 th => { style => 'color:red' },
144 label_format => '<span class="error_field">%s</span>',
145 # td_error => { style => 'color:red;font-weight:bold' },
146 td_error => { class => 'error' },
147 },
148 },
149 25 ▶ }, $defn) unless $defn->{formtype} && $defn->{formtype} eq 'table';
Branch: 1 branch
BranchTrueFalseTotal
unless $defn->{"formtype"} and $defn->{"formtype"} eq "table" 24 1 25
Condition66%2/3
$defn->{"formtype"} and $defn->{"formtype"} eq "table"
!ll&&!rl&&r
2401
MC/DC50%1/2
$defn->{"formtype"} and $defn->{"formtype"} eq "table"
$defn->{"formtype"} $defn->{"formtype"} eq "table"
Truth table66%2/3
A and B
A= $defn->{"formtype"}B= $defn->{"formtype"} eq "table"
ABresult
0X0
100
111
150  
151 25 return $self->SUPER::init($defn);
152 }
153  
154 #
155 # Further split tx_attr into tx_attr and input_attr
156 sub cell_split_out_tx_attr
157 397 ▶{
Subroutine cell_split_out_tx_attr: called CC=17 SCAR=28.5
Pod undocumented
158 397 my $self = shift;
159 397 my ($field) = @_;
160  
161 397 $self->SUPER::cell_split_out_tx_attr(@_);
162  
163 397 for my $attr (qw(label_attr tfoot_attr data_attr)) {
164 1191 ▶ my $type = $self->{defn_t}->{$attr}->{$field}->{type} || '';
Condition100%2/2
$self->{'defn_t'}{$attr}{$field}{'type'} || ''
l!l
1221069
MC/DC100%1/1
$self->{'defn_t'}{$attr}{$field}{'type'} || ''
$self->{'defn_t'}{$attr}{$field}{'type'}
Truth table100%2/2
A
A= $self->{'defn_t'}{$attr}{$field}{'type'}
Aresult
11
00
165 1191 $self->{defn_t}->{$attr}->{$field}->{input_attr} = {};
166  
167 1191 for (keys %{ $self->{defn_t}->{$attr}->{$field}->{tx_attr} }) {
168 # Attributes like input_class will be mapped as input.class
169 457 ▶ if (m/^input_/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^input_/) { } 1 456 457
elsif ($TEXT_ATTR{$_} or $TEXTAREA_ATTR{$_} or $SELECT_ATTR{$_}) { } 361 95 456
170 1 my $val = delete $self->{defn_t}->{$attr}->{$field}->{tx_attr}->{$_};
171 1 s/^input_//;
172 1 $self->{defn_t}->{$attr}->{$field}->{input_attr}->{$_} = $val;
173 }
174 ▶ elsif ($TEXT_ATTR{$_} || $TEXTAREA_ATTR{$_} || $SELECT_ATTR{$_}) {
Condition83%5/6
$TEXT_ATTR{$_} or $TEXTAREA_ATTR{$_} or $SELECT_ATTR{$_}
l!l&&r!l&&!r
361095
$TEXT_ATTR{$_} or $TEXTAREA_ATTR{$_}
l!l&&r!l&&!r
358395
MC/DC66%2/3
$TEXT_ATTR{$_} or $TEXTAREA_ATTR{$_} or $SELECT_ATTR{$_}
$TEXT_ATTR{$_} $TEXTAREA_ATTR{$_} $SELECT_ATTR{$_}
Truth table75%3/4
A or B or C
A= $TEXT_ATTR{$_}B= $TEXTAREA_ATTR{$_}C= $SELECT_ATTR{$_}
ABCresult
1XX1
01X1
0011
0000
175 361 my $val = delete $self->{defn_t}->{$attr}->{$field}->{tx_attr}->{$_};
176  
177 361 ▶ if ($type eq 'select') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'select') { } 20 341 361
elsif ($type eq 'textarea') { } 3 338 341
elsif (not $type or $type eq 'text' or $type eq 'password') { } 266 72 338
178 $self->{defn_t}->{$attr}->{$field}->{input_attr}->{$_} = $val
179 20 ▶ if $SELECT_ATTR{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $SELECT_ATTR{$_} 11 9 20
180 }
181 elsif ($type eq 'textarea') {
182 $self->{defn_t}->{$attr}->{$field}->{input_attr}->{$_} = $val
183 3 ▶ if $TEXTAREA_ATTR{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $TEXTAREA_ATTR{$_} 3 0 3
184 }
185 ▶ elsif (! $type ||
Condition66%4/6
not $type or $type eq "text" or $type eq "password"
l!l&&r!l&&!r
266072
not $type or $type eq "text"
l!l&&r!l&&!r
266072
MC/DC33%1/3
not $type or $type eq "text" or $type eq "password"
not $type $type eq "text" $type eq "password"
Truth table50%2/4
not(A) or B or C
A= not $typeB= $type eq "text"C= $type eq "password"
ABCresult
1XX1
01X1
0011
0000
186 $type eq 'text' ||
187 $type eq 'password') {
188 $self->{defn_t}->{$attr}->{$field}->{input_attr}->{$_} = $val
189 266 ▶ if $TEXT_ATTR{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $TEXT_ATTR{$_} 266 0 266
190 }
191 else {
192 $self->{defn_t}->{$attr}->{$field}->{input_attr}->{$_} = $val
193 72 ▶ if $INPUT_ATTR{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $INPUT_ATTR{$_} 37 35 72
194 }
195 }
196 }
197 }
198 }
199  
200 # One-off or dataset-specific presentation definition munging
201 sub prerender_munge
202 88 ▶{
Subroutine prerender_munge: called CC=30 SCAR=34.2
Pod undocumented
203 88 my $self = shift;
204  
205 # Call SUPER version first
206 88 $self->SUPER::prerender_munge(@_);
207  
208 88 my $defn_t = $self->{defn_t};
209 88 ▶ if ($defn_t->{formtype} eq 'table') {
Branch: 1 branch
BranchTrueFalseTotal
if ($defn_t->{"formtype"} eq "table") 7 81 88
210 7 delete $defn_t->{form};
211 7 return;
212 }
213  
214 # Map top-level 'hidden' arrayref/hashref into fields
215 81 ▶ if (ref $defn_t->{hidden} eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $defn_t->{'hidden'} eq 'HASH') { } 80 1 81
elsif (ref $defn_t->{'hidden'} eq 'ARRAY') { } 1 0 1
216 80 for my $hidden (keys %{$defn_t->{hidden}}) {
217 5 ▶ $defn_t->{field_attr}->{$hidden} ||= {};
Condition50%1/2
$defn_t->{"field_attr"}{$hidden} ||= {}
l!l
05
MC/DC0%0/1
$defn_t->{"field_attr"}{$hidden} ||= {}
$defn_t->{"field_attr"}{$hidden}
Truth table50%1/2
A
A= $defn_t->{"field_attr"}{$hidden}
Aresult
11
00
218 5 $defn_t->{field_attr}->{$hidden}->{type} = 'hidden';
219 4 push @{$defn_t->{fields}}, $hidden
220 5 ▶ unless grep /^$hidden$/, @{$defn_t->{fields}};
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$hidden$/, @{$$defn_t{"fields"};} 4 1 5
221 }
222 }
223 elsif (ref $defn_t->{hidden} eq 'ARRAY') {
224 1 for my $hidden (@{$defn_t->{hidden}}) {
225 4 ▶ $defn_t->{field_attr}->{$hidden} ||= {};
Condition100%2/2
$defn_t->{"field_attr"}{$hidden} ||= {}
l!l
13
MC/DC100%1/1
$defn_t->{"field_attr"}{$hidden} ||= {}
$defn_t->{"field_attr"}{$hidden}
Truth table100%2/2
A
A= $defn_t->{"field_attr"}{$hidden}
Aresult
11
00
226 4 $defn_t->{field_attr}->{$hidden}->{type} = 'hidden';
227 3 push @{$defn_t->{fields}}, $hidden
228 4 ▶ unless grep /^$hidden$/, @{$defn_t->{fields}};
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$hidden$/, @{$$defn_t{"fields"};} 3 1 4
229 }
230 # Reset to hashref
231 1 $defn_t->{hidden} = {};
232 }
233 # Map top-level 'required' array into fields
234 81 my $required = $defn_t->{required};
235 81 ▶ if ($required && ! ref $required && $required =~ m/^(ALL|NONE)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($required and not ref $required and $required =~ /^(ALL|NONE)$/) { } 7 74 81
elsif ($required and not ref $required) { } 1 140 141
Condition100%6/6
$required and not ref $required and $required =~ /^(ALL|NONE)$/
!ll&&!rl&&r
7317
$required and not ref $required
!ll&&!rl&&r
6768
MC/DC100%3/3
$required and not ref $required and $required =~ /^(ALL|NONE)$/
$required not ref $required $required =~ /^(ALL|NONE)$/
Truth table100%4/4
A and not(B) and C
A= $requiredB= not ref $requiredC= $required =~ /^(ALL|NONE)$/
ABCresult
0XX0
10X0
1100
1111
236 7 ▶ if ($required eq 'NONE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($required eq 'NONE') { } 1 6 7
elsif ($defn_t->{'fields'} and ref $defn_t->{'fields'} eq 'ARRAY') { } 6 0 6
237 1 $defn_t->{required} = $required = [];
238 }
239 ▶ elsif ($defn_t->{fields} && ref $defn_t->{fields} eq 'ARRAY') {
Condition33%1/3
$defn_t->{"fields"} and ref $defn_t->{"fields"} eq "ARRAY"
!ll&&!rl&&r
006
MC/DC0%0/2
$defn_t->{"fields"} and ref $defn_t->{"fields"} eq "ARRAY"
$defn_t->{"fields"} ref $defn_t->{"fields"} eq "ARRAY"
Truth table33%1/3
A and B
A= $defn_t->{"fields"}B= ref $defn_t->{"fields"} eq "ARRAY"
ABresult
0X0
100
111
240 6 $defn_t->{required} = $required = [ @{$defn_t->{fields}} ];
241 }
242 }
243 ▶ elsif ($required && ! ref $required) {
Condition100%3/3
$required and not ref $required
!ll&&!rl&&r
6761
MC/DC100%2/2
$required and not ref $required
$required not ref $required
Truth table100%3/3
A and not(B)
A= $requiredB= not ref $required
ABresult
0X0
100
111
244 1 $defn_t->{required} = $required = [ $required ];
245 }
246 81 ▶ if ($required && ref $required eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($required and ref $required eq "ARRAY") 14 67 81
Condition66%2/3
$required and ref $required eq "ARRAY"
!ll&&!rl&&r
67014
MC/DC50%1/2
$required and ref $required eq "ARRAY"
$required ref $required eq "ARRAY"
Truth table66%2/3
A and B
A= $requiredB= ref $required eq "ARRAY"
ABresult
0X0
100
111
247 14 for (@$required) {
248 34 ▶ $defn_t->{field_attr}->{$_} ||= {};
Condition100%2/2
$defn_t->{"field_attr"}{$_} ||= {}
l!l
529
MC/DC100%1/1
$defn_t->{"field_attr"}{$_} ||= {}
$defn_t->{"field_attr"}{$_}
Truth table100%2/2
A
A= $defn_t->{"field_attr"}{$_}
Aresult
11
00
249 34 $defn_t->{field_attr}->{$_}->{required} = 1;
250 }
251 }
252  
253 # Add default submit if fields
254 $defn_t->{submit} = [ 'submit' ]
255 81 ▶ if exists $defn_t->{fields} && ! exists $defn_t->{submit};
Branch: 1 branch
BranchTrueFalseTotal
if exists $defn_t->{"fields"} and not exists $defn_t->{"submit"} 57 24 81
Condition100%3/3
exists $defn_t->{"fields"} and not exists $defn_t->{"submit"}
!ll&&!rl&&r
42057
MC/DC100%2/2
exists $defn_t->{"fields"} and not exists $defn_t->{"submit"}
exists $defn_t->{"fields"} not exists $defn_t->{"submit"}
Truth table100%3/3
A and not(B)
A= exists $defn_t->{"fields"}B= not exists $defn_t->{"submit"}
ABresult
0X0
100
111
256  
257 # Reset errors_where unless we have error_messages
258 81 my $error_messages = 0;
259 81 ▶ if ($self->{defn_t}->{errors}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"defn_t"}{"errors"}) 12 69 81
260 12 for (keys %{$self->{defn_t}->{errors}}) {
261 $error_messages = 1, last
262 11 ▶ if $self->{defn_t}->{errors}->{$_} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"errors"}{$_} ne "" 11 0 11
263 }
264 $self->{defn_t}->{errors_where} = 'column'
265 if $error_messages &&
266 12 ▶ $self->{defn_t}->{errors_where} !~ m/^(column|top)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $error_messages and not $self->{"defn_t"}{"errors_where"} =~ /^(column|top)$/ 0 12 12
Condition66%2/3
$error_messages and not $self->{"defn_t"}{"errors_where"} =~ /^(column|top)$/
!ll&&!rl&&r
1110
MC/DC0%0/2
$error_messages and not $self->{"defn_t"}{"errors_where"} =~ /^(column|top)$/
$error_messages not $self->{"defn_t"}{"errors_where"} =~ /^(column|top)$/
Truth table66%2/3
A and not(B)
A= $error_messagesB= not $self->{"defn_t"}{"errors_where"} =~ /^(column|top)$/
ABresult
0X0
100
111
267 }
268 81 ▶ $self->{defn_t}->{errors_where} = '' unless $error_messages;
Branch: 1 branch
BranchTrueFalseTotal
unless $error_messages 70 11 81
269  
270 # Default primkey to first field if not set
271 # $defn->{primkey} = $defn->{fields}->[0]
272 # if ! $defn->{primkey} &&
273 # $defn->{fields} && ref $defn->{fields} eq 'ARRAY';
274  
275 # Default primkey type to 'static' if not set
276 # my $primkey = $defn->{primkey};
277 # if ($primkey) {
278 # $defn->{field_attr}->{$primkey} ||= {};
279 # $defn->{field_attr}->{$primkey}->{type} = 'static'
280 # if $primkey && ! $defn->{field_attr}->{$primkey}->{type};
281 # }
282 }
283  
284  
285 # -------------------------------------------------------------------------
286 # Override start_tag to add explicit 'id' fields if use_name_as_id is set
287 #
288 sub start_tag
289 1899 ▶{
Subroutine start_tag: called CC=6 SCAR=18.0
Pod undocumented
290 1899 my ($self, $tag, $attr, $close, $extra) = @_;
291 1899 ▶ if ($self->{defn_t}->{use_name_as_id} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"defn_t"}{"use_name_as_id"} and $tag =~ qr/^(input|select|textarea)$/ and exists $attr->{"name"}) 31 1868 1899
Condition83%5/6
$self->{"defn_t"}{"use_name_as_id"} and $tag =~ qr/^(input|select|textarea)$/ and exists $attr->{"name"}
!ll&&!rl&&r
1868031
$self->{"defn_t"}{"use_name_as_id"} and $tag =~ qr/^(input|select|textarea)$/
!ll&&!rl&&r
18264231
MC/DC66%2/3
$self->{"defn_t"}{"use_name_as_id"} and $tag =~ qr/^(input|select|textarea)$/ and exists $attr->{"name"}
$self->{"defn_t"}{"use_name_as_id"} $tag =~ qr/^(input|select|textarea)$/ exists $attr->{"name"}
Truth table75%3/4
A and B and C
A= $self->{"defn_t"}{"use_name_as_id"}B= $tag =~ qr/^(input|select|textarea)$/C= exists $attr->{"name"}
ABCresult
0XX0
10X0
1100
1111
292 $tag =~ qr/^(input|select|textarea)$/ &&
293 exists $attr->{name}) {
294 31 ▶ $attr->{id} ||= $attr->{name};
Condition66%2/3
$attr->{"id"} ||= $attr->{"name"}
l!l&&r!l&&!r
13180
MC/DC0%0/2
$attr->{"id"} ||= $attr->{"name"}
$attr->{"id"} $attr->{"name"}
Truth table66%2/3
A ||= B
A= $attr->{"id"}B= $attr->{"name"}
ABresult
1X1
011
000
295 }
296 1899 ▶ if ($attr->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"value"}) 689 1210 1899
297 689 $attr->{value} = $self->_escape_value($attr->{value}, $extra->{escape});
298 }
299 1899 return $self->SUPER::start_tag($tag, $attr, $close, $extra);
300 }
301  
302 # -------------------------------------------------------------------------
303 # Render cells as appropriate input type etc.
304 #
305 sub cell_content
306 1007 ▶{
Subroutine cell_content: called CC=71 SCAR=48.2
Pod undocumented
307 1007 my $self = shift;
308 1007 my ($row, $field, $fattr) = @_;
309 1007 ▶ $fattr ||= $self->{defn_t}->{field}->{$field} || {};
Condition20%1/5
$fattr ||= $self->{"defn_t"}{"field"}{$field} || {}
l!l&&r!l&&!r
100700
$self->{'defn_t'}{'field'}{$field} || {}
l!l
00
MC/DC0%0/2
$fattr ||= $self->{"defn_t"}{"field"}{$field} || {}
$fattr $self->{'defn_t'}{'field'}{$field}
Truth table33%1/3
A ||= B
A= $fattrB= $self->{'defn_t'}{'field'}{$field}
ABresult
1X1
011
000
310 1007 ▶ $fattr->{type} ||= 'text' if $row;
Branch: 1 branch
BranchTrueFalseTotal
if $row 529 478 1007
Condition100%2/2
$fattr->{"type"} ||= "text"
l!l
348181
MC/DC100%1/1
$fattr->{"type"} ||= "text"
$fattr->{"type"}
Truth table100%2/2
A
A= $fattr->{"type"}
Aresult
11
00
311 1007 my $extra = { escape => $fattr->{escape} };
312  
313 # No special handling required for labels or 'table' forms or composites
314 1007 ▶ if (! defined $row or
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $row or $self->{"defn_t"}{"formtype"} eq "table" or $fattr->{"composite"}) 523 484 1007
Condition83%5/6
not defined $row or $self->{"defn_t"}{"formtype"} eq "table" or $fattr->{"composite"}
l!l&&r!l&&!r
5230484
not defined $row or $self->{"defn_t"}{"formtype"} eq "table"
l!l&&r!l&&!r
47845484
MC/DC66%2/3
not defined $row or $self->{"defn_t"}{"formtype"} eq "table" or $fattr->{"composite"}
not defined $row $self->{"defn_t"}{"formtype"} eq "table" $fattr->{"composite"}
Truth table75%3/4
not(A) or B or C
A= not defined $rowB= $self->{"defn_t"}{"formtype"} eq "table"C= $fattr->{"composite"}
ABCresult
1XX1
01X1
0011
0000
315 $self->{defn_t}->{formtype} eq 'table' or
316 $fattr->{composite}) {
317 523 my ($fvalue, $value) = $self->SUPER::cell_content(@_);
318 # Cache label values for later e.g. error_messages
319 523 ▶ $self->{defn_t}->{_labels}->{$field} = $value if ! defined $row;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $row 478 45 523
320 523 ▶ return wantarray ? ($fvalue, $value) : $fvalue;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 523 0 523
321 }
322  
323 # Call the parent cell_value to get the data value to use
324 484 my $value = $self->SUPER::cell_value(@_);
325 undef $value
326 484 ▶ if defined $self->{defn_t}->{null} && $value eq $self->{defn_t}->{null};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"defn_t"}{"null"} and $value eq $self->{"defn_t"}{"null"} 0 484 484
Condition33%1/3
defined $self->{"defn_t"}{"null"} and $value eq $self->{"defn_t"}{"null"}
!ll&&!rl&&r
04840
MC/DC0%0/2
defined $self->{"defn_t"}{"null"} and $value eq $self->{"defn_t"}{"null"}
defined $self->{"defn_t"}{"null"} $value eq $self->{"defn_t"}{"null"}
Truth table33%1/3
A and B
A= defined $self->{"defn_t"}{"null"}B= $value eq $self->{"defn_t"}{"null"}
ABresult
0X0
100
111
327 484 ▶ undef $value if defined $value && $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and $value eq "" 78 406 484
Condition66%2/3
defined $value and $value eq ""
!ll&&!rl&&r
040678
MC/DC50%1/2
defined $value and $value eq ""
defined $value $value eq ""
Truth table66%2/3
A and B
A= defined $valueB= $value eq ""
ABresult
0X0
100
111
328  
329 # Create <input> (etc.) fields
330 484 my $out = '';
331 484 ▶ my $selected_value = $self->{defn_t}->{xhtml} ? 'selected' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'defn_t'}{'xhtml'} ? : 478 6 484
332 delete $fattr->{value}
333 if defined $self->{defn_t}->{null} && defined $fattr->{value} &&
334 484 ▶ $fattr->{value} eq $self->{defn_t}->{null};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"defn_t"}{"null"} and defined $fattr->{"value"} and $fattr->{"value"} eq $self->{"defn_t"}{"null"} 0 484 484
Condition66%4/6
defined $self->{"defn_t"}{"null"} and defined $fattr->{"value"} and $fattr->{"value"} eq $self->{"defn_t"}{"null"}
!ll&&!rl&&r
48220
defined $self->{"defn_t"}{"null"} and defined $fattr->{"value"}
!ll&&!rl&&r
04822
MC/DC0%0/3
defined $self->{"defn_t"}{"null"} and defined $fattr->{"value"} and $fattr->{"value"} eq $self->{"defn_t"}{"null"}
defined $self->{"defn_t"}{"null"} defined $fattr->{"value"} $fattr->{"value"} eq $self->{"defn_t"}{"null"}
Truth table50%2/4
A and B and C
A= defined $self->{"defn_t"}{"null"}B= defined $fattr->{"value"}C= $fattr->{"value"} eq $self->{"defn_t"}{"null"}
ABCresult
0XX0
10X0
1100
1111
335 484 ▶ if ($fattr->{type} eq 'static' || $fattr->{type} eq 'display') {
Branch: 5 branches
BranchTrueFalseTotal
if ($fattr->{'type'} eq 'static' or $fattr->{'type'} eq 'display') { } 106 378 484
elsif ($fattr->{'type'} eq 'select') { } 22 356 378
elsif ($fattr->{'type'} eq 'radio') { } 14 342 356
elsif ($fattr->{'type'} eq 'hidden') { } 0 342 342
elsif ($fattr->{'type'} eq 'textarea') { } 2 340 342
Condition100%3/3
$fattr->{"type"} eq "static" or $fattr->{"type"} eq "display"
l!l&&r!l&&!r
9610378
MC/DC100%2/2
$fattr->{"type"} eq "static" or $fattr->{"type"} eq "display"
$fattr->{"type"} eq "static" $fattr->{"type"} eq "display"
Truth table100%3/3
A or B
A= $fattr->{"type"} eq "static"B= $fattr->{"type"} eq "display"
ABresult
1X1
011
000
336 106 ▶ if ($fattr->{vlabel}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fattr->{'vlabel'}) { } 2 104 106
337 2 ▶ if (ref $fattr->{vlabel}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fattr->{'vlabel'}) { } 1 1 2
338 1 ▶ if (ref $fattr->{vlabel} eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fattr->{"vlabel"} eq "CODE") 1 0 1
339 1 $out .= $fattr->{vlabel}->($value, $row, $field);
340 }
341 }
342 else {
343 1 $out .= sprintf $fattr->{vlabel}, $value;
344 }
345 }
346 else {
347 104 $out .= $self->_escape_value($value, $fattr->{escape});
348 }
349 106 delete $fattr->{vlabel};
350 $out .= $self->start_tag('input',
351 { type => 'hidden', name => $field, value => $value }, 'close', $extra)
352 106 ▶ if $fattr->{type} eq 'static';
Branch: 1 branch
BranchTrueFalseTotal
if $fattr->{"type"} eq "static" 96 10 106
353 }
354 # Select fields
355 elsif ($fattr->{type} eq 'select') {
356 22 my $values = $fattr->{values};
357 # Allow code on values
358 22 ▶ if (ref $values eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $values eq "CODE") 8 14 22
359 8 my @values = $values->($field, $row);
360 8 ▶ $values = @values == 1 && ref $values[0] ? $values[0] : \@values;
Branch: 1 branch
BranchTrueFalseTotal
@values == 1 && ref $values[0] ? : 4 4 8
Condition66%2/3
@values == 1 and ref $values[0]
!ll&&!rl&&r
404
MC/DC50%1/2
@values == 1 and ref $values[0]
@values == 1 ref $values[0]
Truth table66%2/3
A and B
A= @values == 1B= ref $values[0]
ABresult
0X0
100
111
361 }
362 22 ▶ if (ref $values eq 'ARRAY' && @$values) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $values eq "ARRAY" and @$values) 22 0 22
Condition33%1/3
ref $values eq "ARRAY" and @$values
!ll&&!rl&&r
0022
MC/DC0%0/2
ref $values eq "ARRAY" and @$values
ref $values eq "ARRAY" @$values
Truth table33%1/3
A and B
A= ref $values eq "ARRAY"B= @$values
ABresult
0X0
100
111
363 $out .= $self->start_tag('select',
364 22 { %{$fattr->{input_attr}}, name => $field }, 0, $extra);
365 22 ▶ my $vlabels = $fattr->{vlabels} || {};
Condition50%1/2
$fattr->{'vlabels'} || {}
l!l
220
MC/DC0%0/1
$fattr->{'vlabels'} || {}
$fattr->{'vlabels'}
Truth table50%1/2
A
A= $fattr->{'vlabels'}
Aresult
11
00
366 # Iterate over values, creating options
367 22 ▶ for (my $i = 0; $i <= $#$values; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $values->$#*) 120 22 142
368 120 my $v = $values->[$i];
369 120 my $oattr = {};
370 120 ▶ $oattr->{value} = $v if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 120 0 120
371 120 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 20 100 120
372 # Multi-values make sense in select contexts
373 20 ▶ if (ref $value eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 20 20
374 0 ▶ $oattr->{selected} = $selected_value if grep { $v eq $_ } @$value;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$v eq $_;} @$value 0 0 0
375 } else {
376 20 ▶ $oattr->{selected} = $selected_value if $v eq $value;
Branch: 1 branch
BranchTrueFalseTotal
if $v eq $value 4 16 20
377 }
378 }
379 120 $out .= $self->start_tag('option', $oattr, 0, $extra);
380 120 my $vlabel = '';
381 120 ▶ if (ref $vlabels eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $vlabels eq "CODE") 16 104 120
382 # Two styles are supported for vlabel subroutines - the sub
383 # can either just return a single label based on the given
384 # value, or the first invocation can return an arrayref or
385 # hashref containing the whole set of labels
386 16 my @vlabels = $vlabels->($v, $field, $row);
387 16 ▶ $vlabel = @vlabels == 1 ? $vlabels[0] : \@vlabels;
Branch: 1 branch
BranchTrueFalseTotal
@vlabels == 1 ? : 14 2 16
388 # Replace vlabels if arrayref or hashref returned
389 16 ▶ if (ref $vlabel) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $vlabel) 6 10 16
390 6 $vlabels = $vlabel;
391 6 $vlabel = '';
392 }
393 }
394 120 ▶ if (ref $vlabels eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $vlabels eq 'HASH') { } 36 84 120
elsif (ref $vlabels eq 'ARRAY') { } 74 10 84
395 36 $vlabel = $vlabels->{$v};
396 }
397 elsif (ref $vlabels eq 'ARRAY') {
398 74 $vlabel = $vlabels->[$i];
399 }
400 120 ▶ $vlabel = $v if ! defined $vlabel;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vlabel 12 108 120
401  
402 120 $out .= $vlabel;
403 120 $out .= $self->end_tag('option');
404 }
405 22 $out .= $self->end_tag('select');
406 }
407 }
408 # Radio fields
409 elsif ($fattr->{type} eq 'radio') {
410 14 my $values = $fattr->{values};
411 # Allow code on values
412 14 ▶ if (ref $values eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $values eq "CODE") 10 4 14
413 10 my @values = $values->($field, $row);
414 10 ▶ $values = @values == 1 && ref $values[0] ? $values[0] : \@values;
Branch: 1 branch
BranchTrueFalseTotal
@values == 1 && ref $values[0] ? : 6 4 10
Condition66%2/3
@values == 1 and ref $values[0]
!ll&&!rl&&r
406
MC/DC50%1/2
@values == 1 and ref $values[0]
@values == 1 ref $values[0]
Truth table66%2/3
A and B
A= @values == 1B= ref $values[0]
ABresult
0X0
100
111
415 }
416 14 ▶ if (ref $values eq 'ARRAY' && @$values) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $values eq "ARRAY" and @$values) 14 0 14
Condition33%1/3
ref $values eq "ARRAY" and @$values
!ll&&!rl&&r
0014
MC/DC0%0/2
ref $values eq "ARRAY" and @$values
ref $values eq "ARRAY" @$values
Truth table33%1/3
A and B
A= ref $values eq "ARRAY"B= @$values
ABresult
0X0
100
111
417 # $out .= $self->start_tag('select',
418 # { %{$fattr->{input_attr}}, name => $field });
419 14 ▶ my $vlabels = $fattr->{vlabels} || {};
Condition50%1/2
$fattr->{'vlabels'} || {}
l!l
140
MC/DC0%0/1
$fattr->{'vlabels'} || {}
$fattr->{'vlabels'}
Truth table50%1/2
A
A= $fattr->{'vlabels'}
Aresult
11
00
420 # Iterate over values
421 14 my @out = ();
422 14 ▶ for (my $i = 0; $i <= $#$values; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $values->$#*) 66 14 80
423 66 my $v = $values->[$i];
424 66 my $oattr = {};
425 66 ▶ $oattr->{value} = $v if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 66 0 66
426 66 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 66 66
427 # Multi-values make sense in select contexts
428 0 ▶ if (ref $value eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 0 0
429 0 ▶ $oattr->{selected} = $selected_value if grep { $v eq $_ } @$value;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$v eq $_;} @$value 0 0 0
430 } else {
431 0 ▶ $oattr->{selected} = $selected_value if $v eq $value;
Branch: 1 branch
BranchTrueFalseTotal
if $v eq $value 0 0 0
432 }
433 }
434 my $input = $self->start_tag('input', {
435 66 ▶ %{$fattr->{input_attr}}, name => $field, type => 'radio',
Branch: 3 branches
BranchTrueFalseTotal
$self->{'defn_t'}{'use_name_as_id'} ? : 10 56 66
defined $v ? : 66 0 66
defined $value && !ref($value) && defined $v && $v eq $value ? : 0 66 66
Condition33%3/9
defined $value and not ref $value and defined $v and $v eq $value
!ll&&!rl&&r
6600
defined $value and not ref $value and defined $v
!ll&&!rl&&r
6600
defined $value and not ref $value
!ll&&!rl&&r
6600
MC/DC0%0/4
defined $value and not ref $value and defined $v and $v eq $value
defined $value not ref $value defined $v $v eq $value
Truth table20%1/5
A and not(B) and C and D
A= defined $valueB= not ref $valueC= defined $vD= $v eq $value
ABCDresult
0XXX0
10XX0
110X0
11100
11111
436 66 ($self->{defn_t}->{use_name_as_id} ? (id => "${field}_$i") : ()),
437 (defined $v ? (value => $v) : ()),
438 (defined $value && ! ref $value && defined $v && $v eq $value
439 ? (checked => 'checked')
440 : ()),
441 }, 'close', $extra);
442 66 my $vlabel = '';
443 66 ▶ if (ref $vlabels eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $vlabels eq "CODE") 18 48 66
444 # Two styles are supported for vlabel subroutines - the sub
445 # can either just return a single label based on the given
446 # value, or the first invocation can return an arrayref or
447 # hashref containing the whole set of labels
448 18 my @vlabels = $vlabels->($v, $field, $row);
449 18 ▶ $vlabel = @vlabels == 1 ? $vlabels[0] : \@vlabels;
Branch: 1 branch
BranchTrueFalseTotal
@vlabels == 1 ? : 16 2 18
450 # Replace vlabels if arrayref or hashref returned
451 18 ▶ if (ref $vlabel) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $vlabel) 8 10 18
452 8 $vlabels = $vlabel;
453 8 $vlabel = '';
454 }
455 }
456 66 ▶ if (ref $vlabels eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $vlabels eq 'HASH') { } 28 38 66
elsif (ref $vlabels eq 'ARRAY') { } 28 10 38
457 28 $vlabel = $vlabels->{$v};
458 }
459 elsif (ref $vlabels eq 'ARRAY') {
460 28 $vlabel = $vlabels->[$i];
461 }
462 66 ▶ $vlabel = $v if ! defined $vlabel or $vlabel eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $vlabel or $vlabel eq "" 0 66 66
Condition33%1/3
not defined $vlabel or $vlabel eq ""
l!l&&r!l&&!r
0066
MC/DC0%0/2
not defined $vlabel or $vlabel eq ""
not defined $vlabel $vlabel eq ""
Truth table33%1/3
not(A) or B
A= not defined $vlabelB= $vlabel eq ""
ABresult
1X1
011
000
463  
464 # TODO: need a way of controlling the format used here
465 66 push @out, "$vlabel&nbsp;$input";
466 }
467 # TODO: need a way of designating the join here too
468 14 $out .= join(' ', @out);
469 }
470 }
471 # Hidden fields
472 elsif ($fattr->{type} eq 'hidden') {
473 0 $out .= $self->start_tag('input',
474 { type => 'hidden', name => $field, value => $value }, 'close', $extra);
475 }
476 # Textareas
477 elsif ($fattr->{type} eq 'textarea') {
478 $out .= $self->start_tag('textarea',
479 2 { %{$fattr->{input_attr}}, name => $field, }, 0, $extra);
480 2 $out .= $self->_escape_value($value, $fattr->{escape});
481 2 $out .= $self->end_tag('textarea');
482 }
483 # Input fields
484 else {
485 $out .= $self->start_tag('input',
486 340 { %{$fattr->{input_attr}}, name => $field,
487 340 type => $fattr->{type}, value => $value }, 'close', $extra);
488 }
489  
490 # Now format using $out as value
491 484 return $self->SUPER::cell_format($out, $fattr, $row, $field);
492 }
493  
494 sub _escape_value
495 795 ▶{
Subroutine _escape_value: called CC=4 SCAR=13.9
496 795 my ($self, $data, $escape) = @_;
497 795 ▶ $escape = 1 if ! defined $escape;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $escape 793 2 795
498 795 ▶ if ($data && $escape) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data and $escape) 793 2 795
Condition66%2/3
$data and $escape
!ll&&!rl&&r
02793
MC/DC50%1/2
$data and $escape
$data $escape
Truth table66%2/3
A and B
A= $dataB= $escape
ABresult
0X0
100
111
499 793 $data = encode_entities($data);
500 }
501 795 return $data;
502 }
503  
504 # Derived cell_format_escape - noop here
505 # We escape values in start_tag, and tag body value in cell_content
506 sub cell_format_escape
507 1025 ▶{
Subroutine cell_format_escape: called CC=1 SCAR=0.0
Pod undocumented
508 1025 my ($self, $data) = @_;
509 1025 return $data;
510 }
511  
512 # Derived cell_format_link - ignore links except for display fields
513 sub cell_format_link
514 6 ▶{
Subroutine cell_format_link: called CC=3 SCAR=11.0
Pod undocumented
515 6 my $self = shift;
516 6 my ($data, $fattr, $row, $field, $data_unformatted) = @_;
517 6 ▶ return $data if $fattr->{type} && $fattr->{type} ne 'display';
Branch: 1 branch
BranchTrueFalseTotal
if $fattr->{"type"} and $fattr->{"type"} ne "display" 2 4 6
Condition100%3/3
$fattr->{"type"} and $fattr->{"type"} ne "display"
!ll&&!rl&&r
222
MC/DC100%2/2
$fattr->{"type"} and $fattr->{"type"} ne "display"
$fattr->{"type"} $fattr->{"type"} ne "display"
Truth table100%3/3
A and B
A= $fattr->{"type"}B= $fattr->{"type"} ne "display"
ABresult
0X0
100
111
518 4 return $self->SUPER::cell_format_link(@_);
519 }
520  
521 # Derived cell_tags, for special handling of hiddens
522 sub cell_tags
523 541 ▶{
Subroutine cell_tags: called CC=4 SCAR=14.3
Pod undocumented
524 541 my $self = shift;
525 541 my ($data, $row, $field, $tx_attr) = @_;
526  
527 # Default handling for 'table' forms
528 return $self->SUPER::cell_tags(@_)
529 541 ▶ if $self->{defn_t}->{formtype} eq 'table';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"formtype"} eq "table" 45 496 541
530  
531 # Default handling if not a 'hidden'
532 496 my $type = $self->{defn_t}->{field_attr}->{$field}->{type};
533 496 ▶ return $self->SUPER::cell_tags(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless $type and $type eq "hidden" 496 0 496
Condition66%2/3
$type and $type eq "hidden"
!ll&&!rl&&r
3481480
MC/DC0%0/2
$type and $type eq "hidden"
$type $type eq "hidden"
Truth table66%2/3
A and B
A= $typeB= $type eq "hidden"
ABresult
0X0
100
111
534 unless $type && $type eq 'hidden';
535  
536 0 return $data;
537 }
538  
539 # Merge in extra default sets: -submit for submit fields, -required for
540 # required fields, -errors for fields with errors
541 sub cell_merge_extras
542 397 ▶{
Subroutine cell_merge_extras: called CC=14 SCAR=26.4
Pod undocumented
543 397 my $self = shift;
544 397 my ($row, $field) = @_;
545 397 my %extra = ();
546
547 # Hack: -submit => { table => 0 } is used to signal external submits
548 397 ▶ if (ref $self->{defn_t}->{field_attr}->{-submit} eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH" and exists $self->{"defn_t"}{"field_attr"}{"-submit"}{"table"}) 4 393 397
Condition100%3/3
ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH" and exists $self->{"defn_t"}{"field_attr"}{"-submit"}{"table"}
!ll&&!rl&&r
213724
MC/DC100%2/2
ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH" and exists $self->{"defn_t"}{"field_attr"}{"-submit"}{"table"}
ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH" exists $self->{"defn_t"}{"field_attr"}{"-submit"}{"table"}
Truth table100%3/3
A and B
A= ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH"B= exists $self->{"defn_t"}{"field_attr"}{"-submit"}{"table"}
ABresult
0X0
100
111
549 exists $self->{defn_t}->{field_attr}->{-submit}->{table}) {
550 4 $self->{defn_t}->{submit_table} = $self->{defn_t}->{field_attr}->{-submit}->{table};
551 4 delete $self->{defn_t}->{field_attr}->{-submit}->{table};
552 }
553  
554 # -select fields
555 11 @extra{keys %{$self->{defn_t}->{field_attr}->{-select}}} =
556 11 values %{$self->{defn_t}->{field_attr}->{-select}}
557 if $self->{defn_t}->{field_attr}->{-select} &&
558 ref $self->{defn_t}->{field_attr}->{-select} eq 'HASH' &&
559 $self->{defn_t}->{field_attr}->{$field}->{type} &&
560 397 ▶ $self->{defn_t}->{field_attr}->{$field}->{type} eq 'select';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"field_attr"}{"-select"} and ref $self->{"defn_t"}{"field_attr"}{"-select"} eq "HASH" and $self->{"defn_t"}{"field_attr"}{$field}{"type"} and $self->{"defn_t"}{"field_attr"}{$field}{"type"} eq "select" 11 386 397
Condition88%8/9
$self->{"defn_t"}{"field_attr"}{"-select"} and ref $self->{"defn_t"}{"field_attr"}{"-select"} eq "HASH" and $self->{"defn_t"}{"field_attr"}{$field}{"type"} and $self->{"defn_t"}{"field_attr"}{$field}{"type"} eq "select"
!ll&&!rl&&r
2909611
$self->{"defn_t"}{"field_attr"}{"-select"} and ref $self->{"defn_t"}{"field_attr"}{"-select"} eq "HASH" and $self->{"defn_t"}{"field_attr"}{$field}{"type"}
!ll&&!rl&&r
21269107
$self->{"defn_t"}{"field_attr"}{"-select"} and ref $self->{"defn_t"}{"field_attr"}{"-select"} eq "HASH"
!ll&&!rl&&r
210376
MC/DC75%3/4
$self->{"defn_t"}{"field_attr"}{"-select"} and ref $self->{"defn_t"}{"field_attr"}{"-select"} eq "HASH" and $self->{"defn_t"}{"field_attr"}{$field}{"type"} and $self->{"defn_t"}{"field_attr"}{$field}{"type"} eq "select"
$self->{"defn_t"}{"field_attr"}{"-select"} ref $self->{"defn_t"}{"field_attr"}{"-select"} eq "HASH" $self->{"defn_t"}{"field_attr"}{$field}{"type"} $self->{"defn_t"}{"field_attr"}{$field}{"type"} eq "select"
Truth table80%4/5
A and B and C and D
A= $self->{"defn_t"}{"field_attr"}{"-select"}B= ref $self->{"defn_t"}{"field_attr"}{"-select"} eq "HASH"C= $self->{"defn_t"}{"field_attr"}{$field}{"type"}D= $self->{"defn_t"}{"field_attr"}{$field}{"type"} eq "select"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
561  
562 # -submit fields
563 95 @extra{keys %{$self->{defn_t}->{field_attr}->{-submit}}} =
564 95 values %{$self->{defn_t}->{field_attr}->{-submit}}
565 if $self->{defn_t}->{field_attr}->{-submit} &&
566 ref $self->{defn_t}->{field_attr}->{-submit} eq 'HASH' &&
567 397 ▶ $self->{defn_t}->{submit_hash}->{$field};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"field_attr"}{"-submit"} and ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH" and $self->{"defn_t"}{"submit_hash"}{$field} 95 302 397
Condition83%5/6
$self->{"defn_t"}{"field_attr"}{"-submit"} and ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH" and $self->{"defn_t"}{"submit_hash"}{$field}
!ll&&!rl&&r
2128195
$self->{"defn_t"}{"field_attr"}{"-submit"} and ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH"
!ll&&!rl&&r
210376
MC/DC66%2/3
$self->{"defn_t"}{"field_attr"}{"-submit"} and ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH" and $self->{"defn_t"}{"submit_hash"}{$field}
$self->{"defn_t"}{"field_attr"}{"-submit"} ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH" $self->{"defn_t"}{"submit_hash"}{$field}
Truth table75%3/4
A and B and C
A= $self->{"defn_t"}{"field_attr"}{"-submit"}B= ref $self->{"defn_t"}{"field_attr"}{"-submit"} eq "HASH"C= $self->{"defn_t"}{"submit_hash"}{$field}
ABCresult
0XX0
10X0
1100
1111
568  
569 # -required fields
570 34 @extra{keys %{$self->{defn_t}->{field_attr}->{-required}}} =
571 34 values %{$self->{defn_t}->{field_attr}->{-required}}
572 if $self->{defn_t}->{field_attr}->{-required} &&
573 397 ▶ $self->{defn_t}->{field_attr}->{$field}->{required};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"field_attr"}{"-required"} and $self->{"defn_t"}{"field_attr"}{$field}{"required"} 34 363 397
Condition100%3/3
$self->{"defn_t"}{"field_attr"}{"-required"} and $self->{"defn_t"}{"field_attr"}{$field}{"required"}
!ll&&!rl&&r
2134234
MC/DC100%2/2
$self->{"defn_t"}{"field_attr"}{"-required"} and $self->{"defn_t"}{"field_attr"}{$field}{"required"}
$self->{"defn_t"}{"field_attr"}{"-required"} $self->{"defn_t"}{"field_attr"}{$field}{"required"}
Truth table100%3/3
A and B
A= $self->{"defn_t"}{"field_attr"}{"-required"}B= $self->{"defn_t"}{"field_attr"}{$field}{"required"}
ABresult
0X0
100
111
574  
575 # -errors fields
576 22 @extra{keys %{$self->{defn_t}->{field_attr}->{-errors}}} =
577 22 values %{$self->{defn_t}->{field_attr}->{-errors}}
578 if $self->{defn_t}->{field_attr}->{-errors} &&
579 397 ▶ exists $self->{defn_t}->{errors}->{$field};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"field_attr"}{"-errors"} and exists $self->{"defn_t"}{"errors"}{$field} 22 375 397
Condition100%3/3
$self->{"defn_t"}{"field_attr"}{"-errors"} and exists $self->{"defn_t"}{"errors"}{$field}
!ll&&!rl&&r
2135422
MC/DC100%2/2
$self->{"defn_t"}{"field_attr"}{"-errors"} and exists $self->{"defn_t"}{"errors"}{$field}
$self->{"defn_t"}{"field_attr"}{"-errors"} exists $self->{"defn_t"}{"errors"}{$field}
Truth table100%3/3
A and B
A= $self->{"defn_t"}{"field_attr"}{"-errors"}B= exists $self->{"defn_t"}{"errors"}{$field}
ABresult
0X0
100
111
580  
581 397 return %extra;
582 }
583  
584 # Extract per-field table attribute definitions (tr, th, td, td_error)
585 sub extract_field_table_attr
586 341 ▶{
Subroutine extract_field_table_attr: called CC=13 SCAR=25.8
Pod undocumented
587 341 my $self = shift;
588 341 my ($td_attr, $th_attr) = @_;
589 341 ▶ $td_attr ||= {};
Condition50%1/2
$td_attr ||= {}
l!l
3410
MC/DC0%0/1
$td_attr ||= {}
$td_attr
Truth table50%1/2
A
A= $td_attr
Aresult
11
00
590 341 ▶ $th_attr ||= {};
Condition100%2/2
$th_attr ||= {}
l!l
24299
MC/DC100%1/1
$th_attr ||= {}
$th_attr
Truth table100%2/2
A
A= $th_attr
Aresult
11
00
591  
592 341 ▶ my $tr_attr = $self->{defn_t}->{tr} || {};
Condition100%2/2
$self->{'defn_t'}{'tr'} || {}
l!l
26477
MC/DC100%1/1
$self->{'defn_t'}{'tr'} || {}
$self->{'defn_t'}{'tr'}
Truth table100%2/2
A
A= $self->{'defn_t'}{'tr'}
Aresult
11
00
593 341 ▶ if ($td_attr->{tr} && ref $td_attr->{tr} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($td_attr->{"tr"} and ref $td_attr->{"tr"} eq "HASH") 3 338 341
Condition66%2/3
$td_attr->{"tr"} and ref $td_attr->{"tr"} eq "HASH"
!ll&&!rl&&r
33803
MC/DC50%1/2
$td_attr->{"tr"} and ref $td_attr->{"tr"} eq "HASH"
$td_attr->{"tr"} ref $td_attr->{"tr"} eq "HASH"
Truth table66%2/3
A and B
A= $td_attr->{"tr"}B= ref $td_attr->{"tr"} eq "HASH"
ABresult
0X0
100
111
594 3 $tr_attr = { %$tr_attr, %{$td_attr->{tr}} };
595 3 delete $td_attr->{tr};
596 }
597 341 ▶ if ($td_attr->{th} && ref $td_attr->{th} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($td_attr->{"th"} and ref $td_attr->{"th"} eq "HASH") 56 285 341
Condition66%2/3
$td_attr->{"th"} and ref $td_attr->{"th"} eq "HASH"
!ll&&!rl&&r
285056
MC/DC50%1/2
$td_attr->{"th"} and ref $td_attr->{"th"} eq "HASH"
$td_attr->{"th"} ref $td_attr->{"th"} eq "HASH"
Truth table66%2/3
A and B
A= $td_attr->{"th"}B= ref $td_attr->{"th"} eq "HASH"
ABresult
0X0
100
111
598 56 $th_attr = { %$th_attr, %{$td_attr->{th}} };
599 56 delete $td_attr->{th};
600 }
601 341 ▶ if ($td_attr->{td} && ref $td_attr->{td} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($td_attr->{"td"} and ref $td_attr->{"td"} eq "HASH") 3 338 341
Condition66%2/3
$td_attr->{"td"} and ref $td_attr->{"td"} eq "HASH"
!ll&&!rl&&r
33803
MC/DC50%1/2
$td_attr->{"td"} and ref $td_attr->{"td"} eq "HASH"
$td_attr->{"td"} ref $td_attr->{"td"} eq "HASH"
Truth table66%2/3
A and B
A= $td_attr->{"td"}B= ref $td_attr->{"td"} eq "HASH"
ABresult
0X0
100
111
602 3 $td_attr = { %$td_attr, %{$td_attr->{td}} };
603 3 delete $td_attr->{td};
604 }
605 # 'td_error' components are only applied to (column) error messages
606 341 my $error_td_attr;
607 341 ▶ if ($td_attr->{td_error} && ref $td_attr->{td_error} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($td_attr->{"td_error"} and ref $td_attr->{"td_error"} eq "HASH") 24 317 341
Condition66%2/3
$td_attr->{"td_error"} and ref $td_attr->{"td_error"} eq "HASH"
!ll&&!rl&&r
317024
MC/DC50%1/2
$td_attr->{"td_error"} and ref $td_attr->{"td_error"} eq "HASH"
$td_attr->{"td_error"} ref $td_attr->{"td_error"} eq "HASH"
Truth table66%2/3
A and B
A= $td_attr->{"td_error"}B= ref $td_attr->{"td_error"} eq "HASH"
ABresult
0X0
100
111
608 24 my $td = $td_attr->{td_error};
609 24 delete $td_attr->{td_error};
610 $error_td_attr = { %$td_attr, %$td }
611 24 ▶ if $self->{defn_t}->{errors_where} eq 'column';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"errors_where"} eq "column" 10 14 24
612 }
613  
614 341 return $tr_attr, $td_attr, $th_attr, $error_td_attr;
615 }
616  
617 # Derived row_across, for special handling of hiddens
618 sub row_across
619 281 ▶{
Subroutine row_across: called CC=13 SCAR=25.7
Pod undocumented
620 281 my $self = shift;
621 281 my ($data, $rownum, $field) = @_;
622  
623 # Default handling for 'table' forms
624 return $self->SUPER::row_across(@_)
625 281 ▶ if $self->{defn_t}->{formtype} eq 'table';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"formtype"} eq "table" 0 281 281
626  
627 # Need to call cell_merge_defaults early, since there may be
628 # settings that affect the whole row (single row table assumed)
629 281 $self->cell_merge_defaults($rownum, $field);
630 281 my $lattr = $self->{defn_t}->{label_attr}->{$field};
631 281 my $th_attr = $lattr->{tx_attr};
632 281 my $fattr = $self->{defn_t}->{data_attr}->{$field};
633 281 my $td_attr = $fattr->{tx_attr};
634  
635 # Special handling for 'hidden' and 'omit' fields
636 281 ▶ my $type = $fattr->{type} || '';
Condition100%2/2
$fattr->{'type'} || ''
l!l
121160
MC/DC100%1/1
$fattr->{'type'} || ''
$fattr->{'type'}
Truth table100%2/2
A
A= $fattr->{'type'}
Aresult
11
00
637 281 ▶ if ($type eq 'hidden') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'hidden') { } 34 247 281
elsif ($type eq 'omit') { } 5 242 247
638 # Don't render - just update top-level hidden hashref
639 34 my $value = $self->{defn_t}->{hidden}->{$field};
640 34 ▶ $self->{defn_t}->{hidden}->{$field} = $self->SUPER::cell_content(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 29 5 34
641 $data->[0], $field, $fattr)
642 unless defined $value;
643 # Reset null-ified values
644 $self->{defn_t}->{hidden}->{$field} = ''
645 34 ▶ if $self->{defn_t}->{hidden}->{$field} eq $self->{defn_t}->{null};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"hidden"}{$field} eq $self->{"defn_t"}{"null"} 3 31 34
646 34 return '';
647 }
648 elsif ($type eq 'omit') {
649 5 return '';
650 }
651  
652 242 my ($tr_attr, $error_td_attr);
653 242 ($tr_attr, $td_attr, $th_attr, $error_td_attr) =
654 $self->extract_field_table_attr($td_attr, $th_attr);
655  
656 242 my @format = ();
657 242 my @value = ();
658 242 my $th_colspan = 1;
659 242 ▶ if ($self->{defn_t}->{labels}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"defn_t"}{"labels"}) 239 3 242
660 239 push @format, $self->cell(undef, $field, $lattr, $th_attr);
661 239 push @value, $self->cell(undef, $field, $lattr, $th_attr, tags => 0);
662 239 ▶ $th_colspan = $th_attr->{colspan} || 1;
Condition50%1/2
$th_attr->{'colspan'} || 1
l!l
0239
MC/DC0%0/1
$th_attr->{'colspan'} || 1
$th_attr->{'colspan'}
Truth table50%1/2
A
A= $th_attr->{'colspan'}
Aresult
11
00
663 }
664 # Omit data field if th_colspan >= 2
665 242 ▶ if ($th_colspan < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($th_colspan < 2) 242 0 242
666 242 push @format, $self->cell($data->[0], $field, $fattr, $td_attr);
667 242 push @value, $self->cell($data->[0], $field, $fattr, $td_attr, tags => 0);
668 }
669 # Column errors
670 242 ▶ if ($self->{defn_t}->{errors_where} eq 'column') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"defn_t"}{"errors_where"} eq "column") 15 227 242
671 my $error = ref $self->{defn_t}->{errors}->{$field} eq 'ARRAY' ?
672 join ("<br />",
673 3 map { sprintf $_, $self->{defn_t}->{_labels}->{$field} }
674 2 ▶ @{$self->{defn_t}->{errors}->{$field}}) :
Condition100%2/2
$self->{'defn_t'}{'errors'}{$field} || '&nbsp;'
l!l
85
MC/DC100%1/1
$self->{'defn_t'}{'errors'}{$field} || '&nbsp;'
$self->{'defn_t'}{'errors'}{$field}
Truth table100%2/2
A
A= $self->{'defn_t'}{'errors'}{$field}
Aresult
11
00
675 sprintf($self->{defn_t}->{errors}->{$field} || '&nbsp;',
676 15 ▶ $self->{defn_t}->{_labels}->{$field});
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'defn_t'}{'errors'}{$field} eq 'ARRAY' ? : 2 13 15
677 15 push @format, $self->cell_tags($error, 1, $field, $error_td_attr);
678 }
679  
680 # Generate output
681 242 $tr_attr = { %$tr_attr, %{ $self->tr_attr($rownum, \@value, $data) } };
682 242 my $row = $self->start_tag('tr', $tr_attr);
683 242 $row .= join '', @format;
684 242 $row .= $self->end_tag('tr', $tr_attr) . "\n";
685  
686 242 return $row;
687 }
688  
689 # Override body_across to avoid automatic field derivation
690 sub body_across
691 78 ▶{
Subroutine body_across: called CC=4 SCAR=14.0
Pod undocumented
692 78 my $self = shift;
693 78 my $fields = $self->{defn_t}->{fields};
694 78 ▶ return '' unless $fields && ref $fields eq 'ARRAY' && @$fields;
Branch: 1 branch
BranchTrueFalseTotal
unless $fields and ref $fields eq "ARRAY" and @$fields 1 77 78
Condition66%4/6
$fields and ref $fields eq "ARRAY" and @$fields
!ll&&!rl&&r
1077
$fields and ref $fields eq "ARRAY"
!ll&&!rl&&r
1077
MC/DC33%1/3
$fields and ref $fields eq "ARRAY" and @$fields
$fields ref $fields eq "ARRAY" @$fields
Truth table50%2/4
A and B and C
A= $fieldsB= ref $fields eq "ARRAY"C= @$fields
ABCresult
0XX0
10X0
1100
1111
695 77 $self->SUPER::body_across(@_);
696 }
697  
698 # Output hidden fields
699 sub hidden
700 78 ▶{
Subroutine hidden: called CC=3 SCAR=11.0
Pod documented
701 78 my $self = shift;
702 78 my $out = '';
703 78 ▶ if (ref $self->{defn_t}->{hidden} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"defn_t"}{"hidden"} eq "HASH") 78 0 78
704 78 for my $name (sort keys %{$self->{defn_t}->{hidden}}) {
705 $out .= $self->start_tag('input', {
706 type => 'hidden', name => $name,
707 34 value => $self->{defn_t}->{hidden}->{$name},
708 }, 'close');
709 34 $out .= "\n";
710 }
711 }
712 78 return $out;
713 }
714  
715 # Display submit etc. buttons
716 sub submit
717 87 ▶{
Subroutine submit: called CC=13 SCAR=25.7
Pod documented
718 87 my $self = shift;
719 87 my %arg = @_;
720  
721 87 my $out = '';
722 87 my $defn = $self->{defn_t};
723 87 ▶ return '' unless $defn->{submit};
Branch: 1 branch
BranchTrueFalseTotal
unless $defn->{"submit"} 7 80 87
724  
725 # Map scalars to array (and submit => 1 == submit => 'submit')
726 $defn->{submit} = [ $defn->{submit} == 1 ? 'submit' : $defn->{submit} ]
727 80 ▶ if ! ref $defn->{submit};
Branch: 2 branches
BranchTrueFalseTotal
unless ref $defn->{"submit"} 0 80 80
$defn->{'submit'} == 1 ? : 0 0 0
728 80 $defn->{submit_hash} = { map { $_ => 1 } @{$defn->{submit}} };
729  
730 # Build submit buttons input fields
731 80 my ($tr_attr, $td_attr);
732 80 for my $field (@{$defn->{submit}}) {
733 99 $self->cell_merge_defaults(1, $field);
734 99 my $fattr = $self->{defn_t}->{data_attr}->{$field};
735 99 my $td = $fattr->{tx_attr};
736 99 my $tr;
737 99 ($tr, $td) = $self->extract_field_table_attr($td);
738 # Save tr/td attributes from first submit
739 99 ▶ if (! $defn->{submit_attr}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($defn->{"submit_attr"}) 78 21 99
740 $defn->{submit_attr} = {
741 78 tr_attr => $tr,
742 td_attr => $td,
743 };
744 }
745 99 $tr_attr = $defn->{submit_attr}->{tr_attr};
746 99 $td_attr = $defn->{submit_attr}->{td_attr};
747 99 my $field_id = lc $field;
748 99 $field_id =~ s/\s+/_/g;
749 my $field_value = $fattr->{value} || $fattr->{label} ||
750 99 ▶ join(' ', map { ucfirst } split /\s+/, $field);
Condition83%5/6
$fattr->{'value'} || $fattr->{'label'} || join(' ', map({ucfirst $_;} split(/\s+/, $field, 0)))
l!l&&r!l&&!r
3960
$fattr->{"value"} or $fattr->{"label"}
l!l&&r!l&&!r
1296
MC/DC0%0/3
$fattr->{'value'} || $fattr->{'label'} || join(' ', map({ucfirst $_;} split(/\s+/, $field, 0)))
$fattr->{"value"} $fattr->{"label"} join(' ', map({ucfirst $_;} split(/\s+/, $field, 0)))
Truth table75%3/4
A or B || C
A= $fattr->{"value"}B= $fattr->{"label"}C= join(' ', map({ucfirst $_;} split(/\s+/, $field, 0)))
ABCresult
1XX1
01X1
0011
0000
751 $out .= $self->start_tag('input', {
752 type => 'submit', name => $field_id, id => $field_id, value => $field_value,
753 99 %{$fattr->{input_attr}}
754 }, 'close');
755 99 $out .= "\n";
756 }
757  
758 # Build submit line
759 80 ▶ if ($arg{table}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg{'table'}) { } 75 5 80
760 75 my $cols = 2;
761 75 ▶ $cols++ if $defn->{errors_where} && $defn->{errors_where} eq 'column';
Branch: 1 branch
BranchTrueFalseTotal
if $defn->{"errors_where"} and $defn->{"errors_where"} eq "column" 5 70 75
Condition100%3/3
$defn->{"errors_where"} and $defn->{"errors_where"} eq "column"
!ll&&!rl&&r
6465
MC/DC100%2/2
$defn->{"errors_where"} and $defn->{"errors_where"} eq "column"
$defn->{"errors_where"} $defn->{"errors_where"} eq "column"
Truth table100%3/3
A and B
A= $defn->{"errors_where"}B= $defn->{"errors_where"} eq "column"
ABresult
0X0
100
111
762 75 ▶ $cols-- if ! $self->{defn_t}->{labels};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"defn_t"}{"labels"} 1 74 75
763 75 ▶ my %colspan = $cols > 1 ? ( colspan => $cols ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$cols > 1 ? : 74 1 75
764 75 $tr_attr = { %$tr_attr, %{$self->tr_attr(1, [ 'Submit', $out ])} };
765 75 return $self->start_tag('tr', $tr_attr) .
766 $self->start_tag('td', { %colspan, align => 'center', %$td_attr }) . "\n" .
767 $out .
768 $self->end_tag('td') .
769 $self->end_tag('tr') . "\n";
770 }
771 else {
772 5 return $self->start_tag('p', $td_attr) . "\n" .
773 $out .
774 $self->end_tag('p') . "\n";
775 }
776 }
777  
778 # Format error messages using errors_format
779 sub top_errors
780 6 ▶{
Subroutine top_errors: called CC=13 SCAR=26.9
Pod undocumented
781 6 my $self = shift;
782 6 my $defn_t = $self->{defn_t};
783  
784 6 ▶ return '' unless $defn_t->{errors_format};
Branch: 1 branch
BranchTrueFalseTotal
unless $defn_t->{"errors_format"} 0 6 6
785  
786 # Fields and labels should always be defined by this point
787 6 my %errors = %{$defn_t->{errors}};
788 6 my @errors;
789 # Report errors in field order
790 6 for my $field (@{$defn_t->{fields}}) {
791 24 ▶ if ($errors{$field}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errors{$field}) 12 12 24
792 12 ▶ if (ref $errors{$field} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $errors{$field} eq 'ARRAY') { } 2 10 12
793 2 for my $err (@{$errors{$field}}) {
794 3 push @errors, sprintf($err, $defn_t->{_labels}->{$field});
795 }
796 }
797 else {
798 10 push @errors, sprintf($errors{$field}, $defn_t->{_labels}->{$field});
799 }
800 12 delete $errors{$field};
801 }
802 }
803 # Report any remaining (presumably non-field-specific) errors
804 6 for my $extra (sort keys %errors) {
805 0 ▶ if (ref $errors{$extra} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $errors{$extra} eq 'ARRAY') { } 0 0 0
806 0 push @errors, sprintf($_, $extra) foreach @{$errors{$extra}};
807 }
808 else {
809 0 push @errors, sprintf($errors{$extra}, $extra);
810 }
811 }
812 6 ▶ return '' unless @errors;
Branch: 1 branch
BranchTrueFalseTotal
unless @errors 0 6 6
813  
814 # If sub, simply invoke, passing all errors
815 6 ▶ if (ref $defn_t->{errors_format}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $defn_t->{'errors_format'}) { } 5 1 6
816 5 return $defn_t->{errors_format}->(@errors);
817 }
818 else {
819 1 my $out = '';
820 1 for my $err (@errors) {
821 2 $out .= sprintf $defn_t->{errors_format}, $err;
822 2 ▶ $out .= "\n" unless substr($out,-1) eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
unless substr($out, -1) eq "\n" 0 2 2
823 }
824 1 return $out;
825 }
826 }
827  
828 # Derived pre_table to include top-style error messages
829 sub pre_table
830 88 ▶{
Subroutine pre_table: called CC=5 SCAR=16.2
Pod undocumented
831 88 my $self = shift;
832 88 my ($set) = @_;
833 88 my $content = '';
834 88 ▶ $content .= $self->title($set) if $self->{defn_t}->{title};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"title"} 88 0 88
835 $content .= $self->top_errors
836 if $self->{defn_t}->{errors_where} &&
837 88 ▶ $self->{defn_t}->{errors_where} eq 'top';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"errors_where"} and $self->{"defn_t"}{"errors_where"} eq "top" 6 82 88
Condition100%3/3
$self->{"defn_t"}{"errors_where"} and $self->{"defn_t"}{"errors_where"} eq "top"
!ll&&!rl&&r
7756
MC/DC100%2/2
$self->{"defn_t"}{"errors_where"} and $self->{"defn_t"}{"errors_where"} eq "top"
$self->{"defn_t"}{"errors_where"} $self->{"defn_t"}{"errors_where"} eq "top"
Truth table100%3/3
A and B
A= $self->{"defn_t"}{"errors_where"}B= $self->{"defn_t"}{"errors_where"} eq "top"
ABresult
0X0
100
111
838 88 ▶ $content .= $self->text($set) if $self->{defn_t}->{text};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"text"} 88 0 88
839 88 return $content;
840 }
841  
842 #
843 # Derived start_table to include form tags
844 #
845 sub start_table
846 85 ▶{
Subroutine start_table: called CC=6 SCAR=17.9
Pod undocumented
847 85 my ($self) = @_;
848 85 my $out = '';
849 $out .= $self->start_tag('form',$self->{defn_t}->{form}) . "\n"
850 85 ▶ if $self->{defn_t}->{form};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"form"} 78 7 85
851 85 ▶ my $submit_location = $self->{defn_t}->{submit_location} || 'bottom';
Condition100%2/2
$self->{'defn_t'}{'submit_location'} || 'bottom'
l!l
481
MC/DC100%1/1
$self->{'defn_t'}{'submit_location'} || 'bottom'
$self->{'defn_t'}{'submit_location'}
Truth table100%2/2
A
A= $self->{'defn_t'}{'submit_location'}
Aresult
11
00
852 85 ▶ if ($submit_location eq 'bottom') {
Branch: 2 branches
BranchTrueFalseTotal
if ($submit_location eq 'bottom') { } 81 4 85
elsif (exists $self->{'defn_t'}{'submit_table'} and $self->{'defn_t'}{'submit_table'} == 0) { } 2 2 4
853 81 $out .= $self->SUPER::start_table();
854 }
855 ▶ elsif (exists $self->{defn_t}->{submit_table} &&
Condition66%2/3
exists $self->{"defn_t"}{"submit_table"} and $self->{"defn_t"}{"submit_table"} == 0
!ll&&!rl&&r
202
MC/DC50%1/2
exists $self->{"defn_t"}{"submit_table"} and $self->{"defn_t"}{"submit_table"} == 0
exists $self->{"defn_t"}{"submit_table"} $self->{"defn_t"}{"submit_table"} == 0
Truth table66%2/3
A and B
A= exists $self->{"defn_t"}{"submit_table"}B= $self->{"defn_t"}{"submit_table"} == 0
ABresult
0X0
100
111
856 $self->{defn_t}->{submit_table} == 0) {
857 2 $out .= $self->submit();
858 2 $out .= $self->SUPER::start_table();
859 }
860 else {
861 2 $out .= $self->SUPER::start_table();
862 2 $out .= $self->submit(table => 1);
863 }
864 85 return $out;
865 }
866  
867 #
868 # Derived end_table to include form tags and submits
869 #
870 sub end_table
871 85 ▶{
Subroutine end_table: called CC=7 SCAR=19.5
Pod undocumented
872 85 my ($self) = @_;
873 85 my $out = '';
874 85 ▶ my $submit_location = $self->{defn_t}->{submit_location} || 'bottom';
Condition100%2/2
$self->{'defn_t'}{'submit_location'} || 'bottom'
l!l
481
MC/DC100%1/1
$self->{'defn_t'}{'submit_location'} || 'bottom'
$self->{'defn_t'}{'submit_location'}
Truth table100%2/2
A
A= $self->{'defn_t'}{'submit_location'}
Aresult
11
00
875 85 ▶ if ($submit_location eq 'top') {
Branch: 2 branches
BranchTrueFalseTotal
if ($submit_location eq 'top') { } 2 83 85
elsif (exists $self->{'defn_t'}{'submit_table'} and $self->{'defn_t'}{'submit_table'} == 0) { } 3 80 83
876 2 $out .= $self->SUPER::end_table();
877 }
878 ▶ elsif (exists $self->{defn_t}->{submit_table} &&
Condition66%2/3
exists $self->{"defn_t"}{"submit_table"} and $self->{"defn_t"}{"submit_table"} == 0
!ll&&!rl&&r
8003
MC/DC50%1/2
exists $self->{"defn_t"}{"submit_table"} and $self->{"defn_t"}{"submit_table"} == 0
exists $self->{"defn_t"}{"submit_table"} $self->{"defn_t"}{"submit_table"} == 0
Truth table66%2/3
A and B
A= exists $self->{"defn_t"}{"submit_table"}B= $self->{"defn_t"}{"submit_table"} == 0
ABresult
0X0
100
111
879 $self->{defn_t}->{submit_table} == 0) {
880 3 $out .= $self->SUPER::end_table();
881 3 $out .= $self->submit();
882 }
883 else {
884 80 $out .= $self->submit(table => 1);
885 80 $out .= $self->SUPER::end_table();
886 }
887 85 ▶ $out .= $self->hidden() if $self->{defn_t}->{hidden};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"hidden"} 78 7 85
888 85 ▶ $out .= $self->end_tag('form') . "\n" if $self->{defn_t}->{form};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"form"} 78 7 85
889 85 return $out;
890 }
891  
892 # -------------------------------------------------------------------------
893 # Derived check_fields - unlike Tabulate, don't derive from data if undefined
894 88 ▶sub check_fields {
Subroutine check_fields: called CC=2 SCAR=6.9
Pod undocumented
895 88 my $self = shift;
896 # Default handling for 'table' forms
897 88 ▶ $self->SUPER::check_fields(@_) if $self->{defn_t}->{formtype} eq 'table';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"formtype"} eq "table" 7 81 88
898 }
899  
900 # Derived render_table - skip form altogether unless 'fields' or 'submit'
901 sub render_table
902 88 ▶{
Subroutine render_table: called CC=9 SCAR=22.0
Pod undocumented
903 88 my $self = shift;
904 88 my ($set) = @_;
905  
906 # Default handling for 'table' forms
907 return $self->SUPER::render_table(@_)
908 88 ▶ if $self->{defn_t}->{formtype} eq 'table';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"defn_t"}{"formtype"} eq "table" 7 81 88
909  
910 # Decide whether we need a form
911 81 my $fields = $self->{defn_t}->{fields};
912 81 my $submit = $self->{defn_t}->{submit};
913 81 ▶ my $do_form = ($fields && ref $fields eq 'ARRAY' && @$fields) ||
Condition80%12/15
$fields && ref $fields eq 'ARRAY' && @$fields || $submit && ref $submit eq 'ARRAY' && @$submit
l!l&&r!l&&!r
7713
$fields and ref $fields eq "ARRAY" and @$fields
!ll&&!rl&&r
4077
$fields and ref $fields eq "ARRAY"
!ll&&!rl&&r
4077
$submit and ref $submit eq "ARRAY" and @$submit
!ll&&!rl&&r
211
$submit and ref $submit eq "ARRAY"
!ll&&!rl&&r
202
MC/DC50%3/6
$fields && ref $fields eq 'ARRAY' && @$fields || $submit && ref $submit eq 'ARRAY' && @$submit
$fields ref $fields eq "ARRAY" @$fields $submit ref $submit eq "ARRAY" @$submit
Truth table30%4/13
A and B and C || D and E and F
A= $fieldsB= ref $fields eq "ARRAY"C= @$fieldsD= $submitE= ref $submit eq "ARRAY"F= @$submit
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
914 ($submit && ref $submit eq 'ARRAY' && @$submit);
915  
916 # Ignore 'style' - we just always use 'across'
917 81 ▶ my $body = $self->body_across($set) if $do_form;
Branch: 1 branch
BranchTrueFalseTotal
if $do_form 78 3 81
918
919 # Build table
920 81 my $table = '';
921 81 $table .= $self->pre_table($set);
922 81 ▶ if ($do_form) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_form) 78 3 81
923 78 $table .= $self->start_table();
924 78 $table .= $body;
925 78 $table .= $self->end_table();
926 }
927 81 $table .= $self->post_table($set);
928  
929 81 return $table;
930 }
931  
932 # -------------------------------------------------------------------------
933 # Derived render to setup procedural call if necessary
934 sub render
935 90 ▶{
Subroutine render: called CC=3 SCAR=14.8
Pod documented
936 90 my $self = shift;
937 90 my ($set, $defn) = @_;
938  
939 # If $self is not blessed, this is a procedural call, $self is $set
940 90 ▶ if (ref $self eq 'HASH' || ref $self eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq "HASH" or ref $self eq "ARRAY") 0 90 90
Condition33%1/3
ref $self eq "HASH" or ref $self eq "ARRAY"
l!l&&r!l&&!r
0090
MC/DC0%0/2
ref $self eq "HASH" or ref $self eq "ARRAY"
ref $self eq "HASH" ref $self eq "ARRAY"
Truth table33%1/3
A or B
A= ref $self eq "HASH"B= ref $self eq "ARRAY"
ABresult
1X1
011
000
941 0 $defn = $set;
942 0 $set = $self;
943 0 $self = __PACKAGE__->new($defn);
944 0 undef $defn;
945 }
946  
947 # Call super version
948 90 $self->SUPER::render(@_);
949 }
950  
951 16 1;
952  
953 __END__
↑ Summary