blib/lib/HTML/Formulate.pm

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