blib/lib/Rose/HTML/Form.pm

filter: Statementstmt 86.0% 738 / 858 Branchbran 67.1% 345 / 514 Conditioncond 55.5% 65 / 117 MC/DCmcdc 35.2% 24 / 68 Subroutinesub 87.2% 103 / 118 Podpod 72.7% 64 / 88 totaltotal 75.9% 1339 / 1763 CC 337 SCAR 28.9
CC
337
Cov
77%
_init_field
69.3
object_from_form
64.1
_html_table
58.7
CRAP 18.1
« blib/lib/Rose/HTML/Object/MakeMethods/Generic.pm ↑ Summary blib/lib/Rose/HTML/Form/Field/Time/Minutes.pm »
1 package Rose::HTML::Form;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use Clone::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Rose::URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Scalar::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use URI::Escape qw(uri_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 8 ▶use Rose::HTML::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Rose::HTML::Object::Errors qw(:form);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 8 our @ISA = qw(Rose::HTML::Object::WithWrapAroundChildren
16 Rose::HTML::Form::Field Rose::HTML::Form::Field::Collection);
17  
18 8 our $VERSION = '0.624';
19  
20 # Avoid problems caused by circular dependencies by loading these
21 # modules at runtime. XXX: This whole hierarchy needs an overhaul.
22 8 require Rose::HTML::Form::Field;
23 8 require Rose::HTML::Form::Field::Collection;
24 8 require Rose::HTML::Object::WithWrapAroundChildren;
25  
26 # Multiple inheritence never quite works out the way I want it to...
27 8 Rose::HTML::Form::Field::Collection->import_methods
28 (
29 'xhtml',
30 'html',
31 'prepare',
32 'hidden_field',
33 'hidden_fields',
34 'html_hidden_field',
35 'xhtml_hidden_field',
36 'html_hidden_fields',
37 'xhtml_hidden_fields',
38 );
39  
40 8 __PACKAGE__->add_valid_html_attrs
41 (
42 'action', # %URI; #REQUIRED -- server-side form handler --
43 'method', # (GET|POST) GET -- HTTP method used to submit the form--
44 'enctype', # %ContentType; "application/x-www-form-urlencoded"
45 'accept', # %ContentTypes; #IMPLIED -- list of MIME types for file upload --
46 'name', # CDATA #IMPLIED -- name of form for scripting --
47 'onsubmit', # %Script; #IMPLIED -- the form was submitted --
48 'onreset', # %Script; #IMPLIED -- the form was reset --
49 'accept-charset', # %Charsets; #IMPLIED -- list of supported charsets --
50 'target', # http://www.w3.org/TR/xhtml-modularization/abstract_modules.html#s_targetmodule
51 'novalidate',
52 );
53  
54 8 __PACKAGE__->add_required_html_attrs(
55 {
56 action => '',
57 method => 'get',
58 enctype => 'application/x-www-form-urlencoded',
59 });
60  
61 8 ▶use constant UNSAFE_URI_CHARS => '^\w\d?\057=.:-';
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 8 ▶use Rose::HTML::Form::Constants qw(FF_SEPARATOR);
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 # Variable for use in regexes
66 8 our $FF_SEPARATOR_RE = quotemeta FF_SEPARATOR;
67  
68 8 our $Debug = 0;
69  
70 use Rose::Object::MakeMethods::Generic
71 8 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
72 8 scalar =>
73 [
74 'uri_base',
75 'rank',
76 ],
77  
78 'scalar --get_set_init' =>
79 [
80 'uri_separator',
81 'form_rank_counter',
82 'recursive_init_fields',
83 ],
84  
85 boolean =>
86 [
87 'coalesce_query_string_params' => { default => 1 },
88 'build_on_init' => { default => 1 },
89 ],
90 8 );
91  
92 #
93 # Class data
94 #
95  
96 use Rose::Class::MakeMethods::Generic
97 8 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
98 8 inheritable_scalar =>
99 [
100 '_delegate_to_subforms',
101 ],
102  
103 inheritable_boolean =>
104 [
105 'default_recursive_init_fields',
106 'default_trim_xy_params',
107 ],
108 8 );
109  
110 8 __PACKAGE__->delegate_to_subforms('compile');
111 8 __PACKAGE__->default_recursive_init_fields(0);
112 8 __PACKAGE__->default_trim_xy_params(1);
113  
114 #
115 # Class methods
116 #
117  
118 sub new
119 91 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
120 91 my($class) = shift;
121  
122 91 my $self =
123 {
124 params => {},
125 fields => {},
126 validate_field_html_attrs => 1,
127 };
128  
129 91 bless $self, $class;
130  
131 91 $self->init(@_);
132  
133 91 return $self;
134 }
135  
136 70 ▶sub init_recursive_init_fields { shift->default_recursive_init_fields }
Subroutine init_recursive_init_fields: called CC=1 SCAR=0.0
Pod undocumented
137  
138 sub trim_xy_params
139 160 ▶{
Subroutine trim_xy_params: called CC=5 SCAR=16.1
Pod documented
140 160 my($self) = shift;
141  
142 160 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 156 160
143 {
144 4 ▶ my $val = $self->{'trim_xy_params'} = $_[0] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 4 4
145  
146 4 foreach my $form ($self->forms)
147 {
148 2 $form->trim_xy_params($val);
149 }
150  
151 4 return $val;
152 }
153  
154 return defined $self->{'trim_xy_params'} ?
155 156 ▶ $self->{'trim_xy_params'} : ref($self)->default_trim_xy_params;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'trim_xy_params'} ? : 4 152 156
156 }
157  
158 sub delegate_to_subforms
159 11 ▶{
Subroutine delegate_to_subforms: called CC=8 SCAR=24.5
Pod documented
160 11 my($class) = shift;
161  
162 11 ▶ $class = ref $class if(ref $class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 11 11
163  
164 11 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 3 11
165 {
166 8 my $value = shift;
167  
168 # Dumb regex to avoid non-numeric comparison warning
169 8 ▶ $value = 'runtime' if($value =~ /\d/ && $value == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\d/ and $value == 1 0 8 8
Condition33%1/3
$value =~ /\d/ and $value == 1
!ll&&!rl&&r
800
MC/DC0%0/2
$value =~ /\d/ and $value == 1
$value =~ /\d/ $value == 1
Truth table33%1/3
A and B
A= $value =~ /\d/B= $value == 1
ABresult
0X0
100
111
170  
171 8 ▶ unless(!$value || $value eq 'compile' || $value eq 'runtime')
Branch: 1 branch
BranchTrueFalseTotal
unless (not $value or $value eq "compile" or $value eq "runtime") 0 8 8
Condition33%2/6
not $value or $value eq "compile" or $value eq "runtime"
l!l&&r!l&&!r
800
not $value or $value eq "compile"
l!l&&r!l&&!r
080
MC/DC0%0/3
not $value or $value eq "compile" or $value eq "runtime"
not $value $value eq "compile" $value eq "runtime"
Truth table25%1/4
not(A) or B or C
A= not $valueB= $value eq "compile"C= $value eq "runtime"
ABCresult
1XX1
01X1
0011
0000
172 {
173 0 croak "Invalid delegate_to_subforms() value: '$value'";
174 }
175  
176 8 return $class->_delegate_to_subforms($value);
177 }
178  
179 3 return $class->_delegate_to_subforms;
180 }
181  
182 #
183 # Object methods
184 #
185  
186 1 ▶sub init_uri_separator { '&' }
Subroutine init_uri_separator: called CC=1 SCAR=0.0
Pod undocumented
187  
188 sub init
189 91 ▶{
Subroutine init: called CC=2 SCAR=6.9
Pod documented
190 91 my($self) = shift;
191  
192 91 $self->SUPER::init(@_);
193  
194 91 ▶ $self->build_form() if($self->build_on_init);
Branch: 1 branch
BranchTrueFalseTotal
if $self->build_on_init 90 1 91
195 }
196  
197 13 ▶sub html_element { 'form' }
Subroutine html_element: called CC=1 SCAR=0.0
Pod documented
198 2 ▶sub xhtml_element { 'form' }
Subroutine xhtml_element: called CC=1 SCAR=0.0
Pod documented
199  
200 1 ▶sub action { shift->html_attr('action', @_) }
Subroutine action: called CC=1 SCAR=0.0
Pod undocumented
201 1 ▶sub method { shift->html_attr('method', @_) }
Subroutine method: called CC=1 SCAR=0.0
Pod undocumented
202  
203 49 ▶sub build_form { }
Subroutine build_form: called CC=1 SCAR=0.0
Pod documented
204  
205 sub name
206 37 ▶{
Subroutine name: called CC=3 SCAR=11.0
Pod documented
207 37 my($self) = shift;
208  
209 37 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 35 37
210 {
211 2 return $self->html_attr('name', shift);
212 }
213 else
214 {
215 35 ▶ unless(defined $self->html_attr('name'))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->html_attr("name")) 2 33 35
216 {
217 2 return $self->form_name;
218 }
219  
220 33 return $self->html_attr('name');
221 }
222 }
223  
224 sub validate_field_html_attrs
225 0 ▶{
Subroutine validate_field_html_attrs: not called CC=4 SCAR=30.0
Pod documented
226 0 my($self) = shift;
227  
228 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
229 {
230 0 foreach my $field ($self->fields)
231 {
232 0 $field->validate_html_attrs(@_);
233 }
234  
235 0 ▶ return $self->{'validate_field_html_attrs'} = $_[0] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
236 }
237  
238 0 return $self->{'validate_field_html_attrs'};
239 }
240  
241 # Override inherited, non-public methods with fast-returning
242 # "don't care" versions.
243 0 ▶sub _is_full { 0 }
Subroutine _is_full: not called CC=1 SCAR=6.9
244 0 ▶sub _set_input_value { }
Subroutine _set_input_value: not called CC=1 SCAR=0.0
245 0 ▶sub is_full { 0 }
Subroutine is_full: not called CC=1 SCAR=6.9
Pod documented
246  
247 0 ▶sub is_repeatable { $_[0]->is_repeatable_form || $_[0]->is_repeatable_field ? 1 : 0 }
Subroutine is_repeatable: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_repeatable_form || $_[0]->is_repeatable_field ? : 0 0 0
Condition0%0/3
$_[0]->is_repeatable_form or $_[0]->is_repeatable_field
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]->is_repeatable_form or $_[0]->is_repeatable_field
$_[0]->is_repeatable_form $_[0]->is_repeatable_field
Truth table0%0/3
A or B
A= $_[0]->is_repeatable_formB= $_[0]->is_repeatable_field
ABresult
1X1
011
000
248 3 ▶sub is_repeatable_field { 0 }
Subroutine is_repeatable_field: called CC=1 SCAR=0.0
Pod undocumented
249 0 ▶sub is_repeatable_form { 0 }
Subroutine is_repeatable_form: not called CC=1 SCAR=6.9
Pod undocumented
250  
251 sub is_empty
252 98 ▶{
Subroutine is_empty: called CC=5 SCAR=16.1
Pod documented
253 98 my($self) = shift;
254  
255 98 foreach my $field ($self->fields)
256 {
257 172 ▶ return 0 unless($field->is_empty);
Branch: 1 branch
BranchTrueFalseTotal
unless $field->is_empty 65 107 172
258 }
259  
260 33 foreach my $form ($self->forms)
261 {
262 11 ▶ return 0 unless($form->is_empty);
Branch: 1 branch
BranchTrueFalseTotal
unless $form->is_empty 0 11 11
263 }
264  
265 33 return 1;
266 }
267  
268 sub empty_is_ok
269 95 ▶{
Subroutine empty_is_ok: called CC=6 SCAR=17.9
Pod documented
270 95 my($self) = shift;
271  
272 95 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 87 95
273 {
274 8 foreach my $form ($self->forms)
275 {
276 2 $form->empty_is_ok(@_);
277 }
278  
279 8 return $self->SUPER::empty_is_ok(@_);
280 }
281  
282 87 my $ok = $self->SUPER::empty_is_ok(@_);
283 87 ▶ return $ok unless($ok);
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 77 10 87
284  
285 10 foreach my $form ($self->forms)
286 {
287 2 ▶ return 0 unless($form->empty_is_ok);
Branch: 1 branch
BranchTrueFalseTotal
unless $form->empty_is_ok 0 2 2
288 }
289  
290 10 return $ok;
291 }
292  
293 # Empty contents instead of replacing ref
294 2 ▶sub delete_params { %{shift->{'params'}} = () }
Subroutine delete_params: called CC=1 SCAR=0.0
Pod documented
295  
296 sub params_from_cgi
297 2 ▶{
Subroutine params_from_cgi: called CC=6 SCAR=19.0
Pod documented
298 2 my($self, $cgi) = @_;
299  
300 2 ▶ croak "Missing CGI argument to params_from_cgi" unless(@_ > 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 0 2 2
301  
302 2 ▶ unless(UNIVERSAL::isa($cgi, 'CGI') || UNIVERSAL::can($cgi, 'param'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($cgi, "CGI") or UNIVERSAL::can($cgi, "param")) 0 2 2
Condition33%1/3
UNIVERSAL::isa($cgi, "CGI") or UNIVERSAL::can($cgi, "param")
l!l&&r!l&&!r
020
MC/DC0%0/2
UNIVERSAL::isa($cgi, "CGI") or UNIVERSAL::can($cgi, "param")
UNIVERSAL::isa($cgi, "CGI") UNIVERSAL::can($cgi, "param")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($cgi, "CGI")B= UNIVERSAL::can($cgi, "param")
ABresult
1X1
011
000
303 {
304 0 croak "Argument to params_from_cgi() is not a CGI object and ",
305 "does not have a param() method";
306 }
307  
308 2 my %params;
309  
310 2 local $CGI::LIST_CONTEXT_WARN = 0;
311  
312 2 foreach my $param ($cgi->param)
313 {
314 5 my @values = $cgi->param($param);
315 5 ▶ $params{$param} = @values > 1 ? \@values : $values[0];
Branch: 1 branch
BranchTrueFalseTotal
@values > 1 ? : 2 3 5
316 }
317  
318 2 $self->params(\%params);
319 }
320  
321 # IIn a reasonably modern perl, the optimizer will eliminate the
322 # blocks of code that are conditional upon these constants when the
323 # value is zero.
324 8 ▶use constant MP2 => exists $ENV{'MOD_PERL_API_VERSION'} &&
Subroutine BEGIN: called CC=3 SCAR=12.5
325 8 ▶ $ENV{'MOD_PERL_API_VERSION'} > 1 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{'MOD_PERL_API_VERSION'} && $ENV{'MOD_PERL_API_VERSION'} > 1 ? : 0 8 8
Condition33%1/3
exists $ENV{"MOD_PERL_API_VERSION"} and $ENV{"MOD_PERL_API_VERSION"} > 1
!ll&&!rl&&r
800
MC/DC0%0/2
exists $ENV{"MOD_PERL_API_VERSION"} and $ENV{"MOD_PERL_API_VERSION"} > 1
exists $ENV{"MOD_PERL_API_VERSION"} $ENV{"MOD_PERL_API_VERSION"} > 1
Truth table33%1/3
A and B
A= exists $ENV{"MOD_PERL_API_VERSION"}B= $ENV{"MOD_PERL_API_VERSION"} > 1
ABresult
0X0
100
111
326  
327 8 ▶use constant MP1 => # Special environment variable for the test suite
Subroutine BEGIN: called CC=5 SCAR=17.2
328 ($ENV{'MOD_PERL'} || $ENV{'RHTMLO_TEST_MOD_PERL'}) &&
329 8 ▶ (!exists $ENV{'MOD_PERL_API_VERSION'} || $ENV{'MOD_PERL_API_VERSION'} == 1) ?
Branch: 1 branch
BranchTrueFalseTotal
($ENV{'MOD_PERL'} || $ENV{'RHTMLO_TEST_MOD_PERL'}) && (!exists $ENV{'MOD_PERL_API_VERSION'} || $ENV{'MOD_PERL_API_VERSION'} == 1) ? : 1 7 8
Condition55%5/9
$ENV{"MOD_PERL"} || $ENV{"RHTMLO_TEST_MOD_PERL"} and !exists $ENV{"MOD_PERL_API_VERSION"} || $ENV{"MOD_PERL_API_VERSION"} == 1
!ll&&!rl&&r
701
$ENV{"MOD_PERL"} or $ENV{"RHTMLO_TEST_MOD_PERL"}
l!l&&r!l&&!r
017
not exists $ENV{"MOD_PERL_API_VERSION"} or $ENV{"MOD_PERL_API_VERSION"} == 1
l!l&&r!l&&!r
100
MC/DC25%1/4
$ENV{"MOD_PERL"} || $ENV{"RHTMLO_TEST_MOD_PERL"} and !exists $ENV{"MOD_PERL_API_VERSION"} || $ENV{"MOD_PERL_API_VERSION"} == 1
$ENV{"MOD_PERL"} $ENV{"RHTMLO_TEST_MOD_PERL"} not exists $ENV{"MOD_PERL_API_VERSION"} $ENV{"MOD_PERL_API_VERSION"} == 1
Truth table28%2/7
A or B and not(C) or D
A= $ENV{"MOD_PERL"}B= $ENV{"RHTMLO_TEST_MOD_PERL"}C= not exists $ENV{"MOD_PERL_API_VERSION"}D= $ENV{"MOD_PERL_API_VERSION"} == 1
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
330 8 1 : 0;
331  
332 8 ▶use constant MP0 => $ENV{'MOD_PERL'} ? 0 : 1;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'MOD_PERL'} ? : 0 8 8
333  
334 8 my $Loaded_APR1 = 0;
335 8 my $Loaded_APR2 = 0;
336  
337 sub params_from_apache
338 2 ▶{
Subroutine params_from_apache: called CC=5 SCAR=16.4
Pod documented
339 2 my($self, $apr) = @_;
340  
341 2 ▶ croak "Missing apache request argument to params_from_apache" unless(@_ > 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 0 2 2
342  
343 2 if(MP0)
344 {
345 2 ▶ unless(UNIVERSAL::can($apr, 'param'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::can($apr, "param")) 0 2 2
346 {
347 0 croak "Argument to params_from_apache() does not have a param() method";
348 }
349 }
350 elsif(MP1)
351 {
352 if(UNIVERSAL::isa($apr, 'Apache'))
353 {
354 unless($Loaded_APR1) # cheaper than require (really!)
355 {
356 require Apache::Request;
357 $Loaded_APR1 = 1;
358 }
359  
360 $apr = Apache::Request->instance($apr);
361 }
362 elsif(!UNIVERSAL::isa($apr, 'Apache::Request') &&
363 !UNIVERSAL::can($apr, 'param'))
364 {
365 croak "Argument to params_from_apache() is not an Apache or ",
366 "Apache::Request object and does not have a param() method";
367 }
368 }
369 elsif(MP2)
370 {
371 if(UNIVERSAL::isa($apr, 'Apache2::RequestRec'))
372 {
373 unless($Loaded_APR2) # cheaper than require (really!)
374 {
375 require Apache2::Request;
376 $Loaded_APR2 = 1;
377 }
378  
379 $apr = Apache2::Request->new($apr);
380 }
381 elsif(!UNIVERSAL::isa($apr, 'Apache2::Request') &&
382 !UNIVERSAL::can($apr, 'param'))
383 {
384 croak "Argument to params_from_apache() is not an Apache2::RequestRec ",
385 "or Apache2::Request object and does not have a param() method";
386 }
387 }
388  
389 2 my %params;
390  
391 2 foreach my $param ($apr->param)
392 {
393 5 my @values = $apr->param($param);
394 5 ▶ $params{$param} = @values > 1 ? \@values : $values[0];
Branch: 1 branch
BranchTrueFalseTotal
@values > 1 ? : 2 3 5
395 }
396  
397 2 $self->params(\%params);
398 }
399  
400 sub params
401 190 ▶{
Subroutine params: called CC=11 SCAR=24.0
Pod documented
402 190 my($self) = shift;
403  
404 190 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 156 34 190
405 {
406 156 ▶ if(@_ == 1 && ref $_[0] eq 'HASH')
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 139 17 156
elsif (@_ % 2 == 0) { } 17 0 17
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
170139
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
407 {
408 139 $self->{'params'} = $_[0];
409 }
410 elsif(@_ % 2 == 0)
411 {
412 17 $self->{'params'} = Clone::PP::clone({ @_ });
413 }
414 else
415 {
416 0 croak(ref($self), '::params() - got odd number of arguments: ');
417 }
418  
419 156 ▶ if($self->trim_xy_params)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->trim_xy_params) 152 4 156
420 {
421 152 foreach my $param (keys %{$self->{'params'}})
422 {
423 702 ▶ if($param =~ /^(.+)\.[xy]$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($param =~ /^(.+)\.[xy]$/) 1 701 702
424 {
425 1 delete $self->{'params'}{$param};
426 1 $self->{'params'}{$1} = 1;
427 }
428 }
429 }
430  
431 156 foreach my $form ($self->forms)
432 {
433 87 $form->params($self->{'params'});
434 }
435 }
436  
437 190 my $want = wantarray;
438 190 ▶ return unless(defined $want);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $want 156 34 190
439  
440 34 ▶ return ($want) ? %{ Clone::PP::clone($self->{'params'}) } : $self->{'params'};
Branch: 1 branch
BranchTrueFalseTotal
$want ? : 1 33 34
441 }
442  
443 sub param_exists
444 1641 ▶{
Subroutine param_exists: called CC=1 SCAR=0.0
Pod documented
445 1641 my($self, $param) = @_;
446  
447 8 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
448  
449 1641 return exists $self->{'params'}{$param};
450 }
451  
452 0 ▶sub params_exist { (keys %{$_[0]->{'params'}}) ? 1 : 0 }
Subroutine params_exist: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
keys %{$_[0]{'params'};} ? : 0 0 0
453  
454 sub param_exists_for_field
455 36 ▶{
Subroutine param_exists_for_field: called CC=15 SCAR=27.1
Pod documented
456 36 my($self, $name) = @_;
457  
458 36 ▶ $name = $name->name if(UNIVERSAL::isa($name, 'Rose::HTML::Form::Field'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($name, "Rose::HTML::Form::Field") 8 28 36
459  
460 36 ▶ return 0 unless($self->field($name));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->field($name) 2 34 36
461  
462 34 my $nibble = $name;
463 34 my $found_form = 0;
464  
465 34 ▶ while(length $nibble)
Branch: 1 branch
BranchTrueFalseTotal
if (length $nibble) 62 0 62
466 {
467 62 ▶ if($self->form($nibble) && !$self->field($nibble))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form($nibble) and not $self->field($nibble)) 11 51 62
Condition66%2/3
$self->form($nibble) and not $self->field($nibble)
!ll&&!rl&&r
51011
MC/DC50%1/2
$self->form($nibble) and not $self->field($nibble)
$self->form($nibble) not $self->field($nibble)
Truth table66%2/3
A and not(B)
A= $self->form($nibble)B= not $self->field($nibble)
ABresult
0X0
100
111
468 {
469 11 $found_form = 1;
470 11 last;
471 }
472  
473 51 ▶ return 1 if($self->param_exists($nibble));
Branch: 1 branch
BranchTrueFalseTotal
if $self->param_exists($nibble) 11 40 51
474 40 ▶ $nibble =~ s/\.[^.]+$// || last;
Branch: 1 branch
BranchTrueFalseTotal
$nibble =~ s/\.[^.]+$// or last 28 12 40
475 }
476  
477 23 ▶ foreach my $field ($found_form ? $self->form($nibble)->fields :
Branch: 1 branch
BranchTrueFalseTotal
$found_form ? : 11 12 23
478 $self->field($name))
479 {
480 23 ▶ if($field->can('subfield_names'))
Branch: 1 branch
BranchTrueFalseTotal
if ($field->can("subfield_names")) 20 3 23
481 {
482 20 foreach my $subname ($field->subfield_names)
483 {
484 # Skip unrelated subfields
485 102 ▶ next unless(index($name, $subname) == 0 ||
Branch: 1 branch
BranchTrueFalseTotal
unless index($name, $subname) == 0 or index($subname, $name) == 0 19 83 102
Condition100%3/3
index($name, $subname) == 0 or index($subname, $name) == 0
l!l&&r!l&&!r
57819
MC/DC100%2/2
index($name, $subname) == 0 or index($subname, $name) == 0
index($name, $subname) == 0 index($subname, $name) == 0
Truth table100%3/3
A or B
A= index($name, $subname) == 0B= index($subname, $name) == 0
ABresult
1X1
011
000
486 index($subname, $name) == 0);
487  
488 83 ▶ return 1 if($self->param_exists($subname));
Branch: 1 branch
BranchTrueFalseTotal
if $self->param_exists($subname) 10 73 83
489 }
490 }
491 }
492  
493 13 return 0;
494 }
495  
496 sub param_value_exists
497 3 ▶{
Subroutine param_value_exists: called CC=6 SCAR=18.4
Pod documented
498 3 my($self, $param, $value) = @_;
499  
500 3 ▶ croak(ref($self), '::param_value_exists() requires a param name plus a value')
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 3 3
501 unless(@_ == 3);
502  
503 3 $param = $self->param($param);
504  
505 3 ▶ return 0 unless($param);
Branch: 1 branch
BranchTrueFalseTotal
unless $param 0 3 3
506  
507 3 ▶ foreach my $existing_value ((ref $param) ? @$param : $param)
Branch: 1 branch
BranchTrueFalseTotal
ref $param ? : 3 0 3
508 {
509 9 ▶ return 1 if($existing_value eq $value);
Branch: 1 branch
BranchTrueFalseTotal
if $existing_value eq $value 2 7 9
510 }
511  
512 1 return 0;
513 }
514  
515 sub param
516 244 ▶{
Subroutine param: called CC=6 SCAR=18.0
Pod documented
517 244 my($self, $param, $value) = @_;
518  
519 244 ▶ if(@_ == 2)
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 2) { } 243 1 244
elsif (@_ == 3) { } 1 0 1
520 {
521 243 ▶ if(exists $self->{'params'}{$param})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"params"}{$param}) 240 3 243
522 {
523 240 ▶ if(wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 214 26 240
524 {
525 214 ▶ if(ref $self->{'params'}{$param})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"params"}{$param}) 9 205 214
526 {
527 9 return @{$self->{'params'}{$param}};
528 }
529  
530 205 return ($self->{'params'}{$param});
531 }
532  
533 26 return $self->{'params'}{$param};
534 }
535  
536 3 return;
537 }
538 elsif(@_ == 3)
539 {
540 1 return $self->{'params'}{$param} = $value;
541 }
542  
543 0 croak(ref($self), '::param() requires a param name plus an optional value');
544 }
545  
546 sub delete_param
547 4 ▶{
Subroutine delete_param: called CC=11 SCAR=24.1
Pod documented
548 4 my($self, $param, @values) = @_;
549  
550 4 ▶ croak(ref($self), '::delete_param() requires a param name')
Branch: 1 branch
BranchTrueFalseTotal
unless @_ >= 2 0 4 4
551 unless(@_ >= 2);
552  
553 4 ▶ @values = @{$values[0]} if(@values == 1 && ref $values[0] eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if @values == 1 and ref $values[0] eq "ARRAY" 1 3 4
Condition100%3/3
@values == 1 and ref $values[0] eq "ARRAY"
!ll&&!rl&&r
121
MC/DC100%2/2
@values == 1 and ref $values[0] eq "ARRAY"
@values == 1 ref $values[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @values == 1B= ref $values[0] eq "ARRAY"
ABresult
0X0
100
111
554  
555 4 ▶ if(@values)
Branch: 1 branch
BranchTrueFalseTotal
if (@values) { } 3 1 4
556 {
557 3 my %values = map { $_ => 1 } @values;
558  
559 3 my $current = $self->{'params'}{$param};
560  
561 3 ▶ if(ref $current)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $current) { } 2 1 3
elsif (exists $values{$self->{'params'}{$param}}) { } 1 0 1
562 {
563 2 my @new;
564  
565 2 foreach my $val (@$current)
566 {
567 7 ▶ push(@new, $val) unless(exists $values{$val});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $values{$val} 4 3 7
568 }
569  
570 2 ▶ if(@new)
Branch: 1 branch
BranchTrueFalseTotal
if (@new) { } 2 0 2
571 {
572 2 ▶ $self->{'params'}{$param} = @new > 1 ? \@new : $new[0];
Branch: 1 branch
BranchTrueFalseTotal
@new > 1 ? : 1 1 2
573 }
574 else
575 {
576 0 delete $self->{'params'}{$param};
577 }
578 }
579 elsif(exists $values{$self->{'params'}{$param}})
580 {
581 1 delete $self->{'params'}{$param};
582 }
583 }
584 else
585 {
586 1 delete $self->{'params'}{$param};
587 }
588 }
589  
590 sub add_param_value
591 1 ▶{
Subroutine add_param_value: called CC=7 SCAR=27.2
Pod documented
592 1 my($self, $param, $value) = @_;
593  
594 1 ▶ croak(ref($self), '::add_param() requires a param name plus a value')
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 1 1
595 unless(@_ == 3);
596  
597 1 my $current = $self->{'params'}{$param};
598  
599 1 ▶ if(ref $current)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $current) { } 1 0 1
elsif (defined $current) { } 0 0 0
600 {
601 1 ▶ push(@$current, ((ref $value) ? @$value : $value));
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 0 1 1
602 }
603 elsif(defined $current)
604 {
605 0 ▶ $current = [ $current, ((ref $value) ? @$value : $value) ];
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 0 0 0
606 }
607 else
608 {
609 0 ▶ $current = [ ((ref $value) ? @$value : $value) ];
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 0 0 0
610 }
611  
612 1 $self->{'params'}{$param} = $current;
613 }
614  
615 sub self_uri
616 1 ▶{
Subroutine self_uri: called CC=3 SCAR=13.0
Pod documented
617 1 my($self) = shift;
618  
619 1 my $uri_root = $self->uri_base . $self->html_attr('action');
620  
621 1 my $self_uri = $uri_root;
622  
623 1 ▶ if(keys %{$self->{'params'}})
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$self{"params"};}) 0 1 1
624 {
625 0 ▶ $self_uri .= '?' unless($self_uri =~ /\?$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $self_uri =~ /\?$/ 0 0 0
626 0 $self_uri .= $self->query_string;
627 }
628  
629 1 return Rose::URI->new($self_uri);
630 }
631  
632 # XXX: To document or not to document, that is the question...
633 0 ▶sub query_hash { Rose::URI->new(query => shift->query_string)->query_hash }
Subroutine query_hash: not called CC=1 SCAR=6.9
Pod undocumented
634  
635 sub query_string
636 4 ▶{
Subroutine query_string: called CC=8 SCAR=20.8
Pod documented
637 4 my($self) = shift;
638  
639 4 my $coalesce = $self->coalesce_query_string_params;
640  
641 4 my %params;
642  
643 4 my @fields = $self->fields;
644  
645 4 ▶ while(my $field = shift(@fields))
Branch: 1 branch
BranchTrueFalseTotal
if (my $field = shift @fields) 19 4 23
646 {
647 19 ▶ unless($coalesce)
Branch: 1 branch
BranchTrueFalseTotal
unless ($coalesce) 9 10 19
648 {
649 9 ▶ if($field->isa('Rose::HTML::Form::Field::Compound'))
Branch: 1 branch
BranchTrueFalseTotal
if ($field->isa("Rose::HTML::Form::Field::Compound")) 1 8 9
650 {
651 1 unshift(@fields, $field->fields);
652 1 next;
653 }
654 }
655  
656 18 my $value = $field->output_value;
657 18 ▶ next unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 16 18
658 16 ▶ push(@{$params{$field->name}}, ref $value ? @$value : $value);
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 6 10 16
659 }
660  
661 4 my $qs = '';
662 4 my $sep = $self->uri_separator;
663  
664 8 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
665  
666 4 foreach my $param (sort keys(%params))
667 {
668 16 my $values = $params{$param};
669  
670 16 ▶ $qs .= $sep if($qs);
Branch: 1 branch
BranchTrueFalseTotal
if $qs 13 3 16
671 16 $qs .= join($sep, map { $param . '=' . uri_escape($_, UNSAFE_URI_CHARS) } @$values);
672 }
673  
674 4 return $qs;
675 }
676  
677 sub validate
678 55 ▶{
Subroutine validate: called CC=19 SCAR=29.5
Pod documented
679 55 my($self, %args) = @_;
680  
681 55 ▶ $args{'cascade'} = 1 unless(exists $args{'cascade'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"cascade"} 23 32 55
682  
683 55 my $fail = 0;
684  
685 55 my $cascade = $args{'cascade'};
686  
687 55 ▶ if($cascade)
Branch: 1 branch
BranchTrueFalseTotal
if ($cascade) 51 4 55
688 {
689 51 foreach my $form ($self->forms)
690 {
691 32 ▶ next if($form->is_empty && $form->empty_is_ok);
Branch: 1 branch
BranchTrueFalseTotal
if $form->is_empty and $form->empty_is_ok 2 30 32
Condition100%3/3
$form->is_empty and $form->empty_is_ok
!ll&&!rl&&r
2462
MC/DC100%2/2
$form->is_empty and $form->empty_is_ok
$form->is_empty $form->empty_is_ok
Truth table100%3/3
A and B
A= $form->is_emptyB= $form->empty_is_ok
ABresult
0X0
100
111
692  
693 30 ▶ $Debug && warn "Validating sub-form ", $form->form_name, "\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "Validating sub-form ", $form->form_name, "\n" 0 30 30
694  
695 30 ▶ unless($form->validate(%args))
Branch: 1 branch
BranchTrueFalseTotal
unless ($form->validate(%args)) 5 25 30
696 {
697 5 ▶ $self->add_error($form->error) if($form->error);
Branch: 1 branch
BranchTrueFalseTotal
if $form->error 4 1 5
698 5 $fail++;
699 }
700 }
701 }
702  
703 55 ▶ unless($args{'form_only'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"form_only"}) 52 3 55
704 {
705 52 ▶ return 1 if($self->is_empty && $self->empty_is_ok);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_empty and $self->empty_is_ok 2 50 52
Condition100%3/3
$self->is_empty and $self->empty_is_ok
!ll&&!rl&&r
40102
MC/DC100%2/2
$self->is_empty and $self->empty_is_ok
$self->is_empty $self->empty_is_ok
Truth table100%3/3
A and B
A= $self->is_emptyB= $self->empty_is_ok
ABresult
0X0
100
111
706  
707 50 foreach my $field ($self->fields)
708 {
709 254 ▶ if($field->parent_form ne $self)
Branch: 1 branch
BranchTrueFalseTotal
if ($field->parent_form ne $self) { } 136 118 254
710 {
711 136 ▶ $Debug && warn "Skipping validation of field ", $field->name, " in child form\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "Skipping validation of field ", $field->name, " in child form\n" 0 136 136
712 }
713 else
714 {
715 118 ▶ $Debug && warn "Validating ", $field->name, "\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "Validating ", $field->name, "\n" 0 118 118
716 118 ▶ $fail++ unless($field->validate);
Branch: 1 branch
BranchTrueFalseTotal
unless $field->validate 10 108 118
717 }
718 }
719 }
720  
721 53 ▶ if($fail)
Branch: 1 branch
BranchTrueFalseTotal
if ($fail) 13 40 53
722 {
723 13 ▶ unless($self->has_errors)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_errors) 9 4 13
724 {
725 9 $self->add_error_id(FORM_HAS_ERRORS);
726 }
727  
728 13 return 0;
729 }
730  
731 40 return 1;
732 }
733  
734 sub init_fields_with_cgi
735 1 ▶{
Subroutine init_fields_with_cgi: called CC=1 SCAR=0.0
Pod documented
736 1 my($self) = shift;
737  
738 1 $self->params_from_cgi(shift);
739 1 $self->init_fields(@_);
740 }
741  
742 sub init_fields_with_apache
743 1 ▶{
Subroutine init_fields_with_apache: called CC=1 SCAR=0.0
Pod documented
744 1 my($self) = shift;
745  
746 1 $self->params_from_apache(shift);
747 1 $self->init_fields(@_);
748 }
749  
750 sub init_fields
751 116 ▶{
Subroutine init_fields: called CC=7 SCAR=19.5
Pod documented
752 116 my($self, %args) = @_;
753  
754 116 ▶ $self->clear() unless($args{'no_clear'});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"no_clear"} 114 2 116
755  
756 116 ▶ if(exists $args{'recursive'} ? $args{'recursive'} : $self->recursive_init_fields)
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args{'recursive'} ? $args{'recursive'} : $self->recursive_init_fields) { } 56 60 116
exists $args{'recursive'} ? : 0 116 116
757 {
758 56 foreach my $field ($self->local_fields)
759 {
760 111 $self->_init_field($field);
761 }
762  
763 56 foreach my $form ($self->forms)
764 {
765 60 $form->init_fields;
766 }
767 }
768 else
769 {
770 60 foreach my $field ($self->fields)
771 {
772 246 $self->_init_field($field);
773 }
774 }
775 }
776  
777 sub _init_field
778 501 ▶{
Subroutine _init_field: called CC=26 SCAR=42.4
779 501 my($self, $field) = @_;
780  
781 501 my $on_off = $field->isa('Rose::HTML::Form::Field::OnOff');
782  
783 501 my $name = $field->name;
784 501 my $moniker = $field->moniker;
785 501 my $name_attr = $field->html_attr('name');
786  
787 501 ▶ $Debug && warn "INIT FIELD $name ($name_attr)\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "INIT FIELD $name ($name_attr)\n" 0 501 501
788  
789 501 my $name_exists = $self->param_exists($name);
790 501 my $moniker_exists = $self->param_exists($moniker);
791 501 my $name_attr_exists = $self->param_exists($name_attr);
792  
793 501 ▶ if(!$name_exists && $field->isa('Rose::HTML::Form::Field::Compound'))
Branch: 1 branch
BranchTrueFalseTotal
if (not $name_exists and $field->isa('Rose::HTML::Form::Field::Compound')) { } 48 453 501
Condition100%3/3
not $name_exists and $field->isa("Rose::HTML::Form::Field::Compound")
!ll&&!rl&&r
21324048
MC/DC100%2/2
not $name_exists and $field->isa("Rose::HTML::Form::Field::Compound")
not $name_exists $field->isa("Rose::HTML::Form::Field::Compound")
Truth table100%3/3
not(A) and B
A= not $name_existsB= $field->isa("Rose::HTML::Form::Field::Compound")
ABresult
0X0
100
111
794 {
795 48 foreach my $moniker ($field->field_monikers)
796 {
797 144 $self->_init_field($field->field($moniker));
798 }
799 }
800 else
801 {
802 453 ▶ return unless($name_exists || $name_attr_exists || $moniker_exists || $on_off);
Branch: 1 branch
BranchTrueFalseTotal
unless $name_exists or $name_attr_exists or $moniker_exists or $on_off 239 214 453
Condition77%7/9
$name_exists or $name_attr_exists or $moniker_exists or $on_off
l!l&&r!l&&!r
2140239
$name_exists or $name_attr_exists or $moniker_exists
l!l&&r!l&&!r
2131239
$name_exists or $name_attr_exists
l!l&&r!l&&!r
2130240
MC/DC50%2/4
$name_exists or $name_attr_exists or $moniker_exists or $on_off
$name_exists $name_attr_exists $moniker_exists $on_off
Truth table60%3/5
A or B or C or D
A= $name_existsB= $name_attr_existsC= $moniker_existsD= $on_off
ABCDresult
1XXX1
01XX1
001X1
00011
00000
803  
804 214 ▶ if($field->isa('Rose::HTML::Form::Field::Group'))
Branch: 1 branch
BranchTrueFalseTotal
if ($field->isa('Rose::HTML::Form::Field::Group')) { } 41 173 214
805 {
806 41 ▶ if($name_exists)
Branch: 2 branches
BranchTrueFalseTotal
if ($name_exists) { } 41 0 41
elsif ($moniker_exists) { } 0 0 0
807 {
808 41 ▶ $Debug && warn "$field->input_value(", $self->param($name), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "$field->input_value(", $self->param($name), ")\n" 0 41 41
809 41 $field->input_value($self->param($name));
810 }
811 elsif($moniker_exists)
812 {
813 0 ▶ $Debug && warn "$field->input_value(", $self->param($moniker), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "$field->input_value(", $self->param($moniker), ")\n" 0 0 0
814 0 $field->input_value($self->param($moniker));
815 }
816 else
817 {
818 0 ▶ $Debug && warn "$field->input_value(", $self->param($name_attr), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "$field->input_value(", $self->param($name_attr), ")\n" 0 0 0
819 0 $field->input_value($self->param($name_attr));
820 }
821 }
822 else
823 {
824 # Must handle lone checkboxes and radio buttons here
825 173 ▶ if($on_off)
Branch: 1 branch
BranchTrueFalseTotal
if ($on_off) { } 0 173 173
826 {
827 8 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
828 0 ▶ if($name_exists && $self->param($name) eq $field->html_attr('value'))
Branch: 1 branch
BranchTrueFalseTotal
if ($name_exists and $self->param($name) eq $field->html_attr('value')) { } 0 0 0
Condition0%0/3
$name_exists and $self->param($name) eq $field->html_attr("value")
!ll&&!rl&&r
000
MC/DC0%0/2
$name_exists and $self->param($name) eq $field->html_attr("value")
$name_exists $self->param($name) eq $field->html_attr("value")
Truth table0%0/3
A and B
A= $name_existsB= $self->param($name) eq $field->html_attr("value")
ABresult
0X0
100
111
829 {
830 0 ▶ $Debug && warn "$self->param($name) = checked\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "$self->param($name) = checked\n" 0 0 0
831 0 $field->checked(1);
832 }
833 else
834 {
835 0 ▶ if($self->params_exist)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->params_exist) { } 0 0 0
836 {
837 0 $field->checked(0);
838 }
839 else
840 {
841 # Didn't set anything, so avoid doing pareant un-clearing below
842 0 return;
843 }
844 }
845 }
846 else
847 {
848 173 ▶ if($name_exists)
Branch: 2 branches
BranchTrueFalseTotal
if ($name_exists) { } 172 1 173
elsif ($moniker_exists) { } 1 0 1
849 {
850 172 ▶ $Debug && warn "$field->input_value(", $self->param($name), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "$field->input_value(", $self->param($name), ")\n" 0 172 172
851 172 $field->input_value($self->param($name));
852 }
853 elsif($moniker_exists)
854 {
855 1 ▶ $Debug && warn "$field->input_value(", $self->param($moniker), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "$field->input_value(", $self->param($moniker), ")\n" 0 1 1
856 1 $field->input_value($self->param($moniker));
857 }
858 else
859 {
860 0 ▶ $Debug && warn "$field->input_value(", $self->param($name_attr), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Form::Debug and warn "$field->input_value(", $self->param($name_attr), ")\n" 0 0 0
861 0 $field->input_value($self->param($name_attr));
862 }
863 }
864 }
865 }
866  
867 262 my $parent = $field->parent_field;
868  
869 # Ensure that setting the value of a child field makes all its
870 # parent fields "not cleared"
871 262 ▶ while($parent)
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) 54 262 316
872 {
873 54 $parent->is_cleared(0);
874 54 $parent = $parent->parent_field;
875 }
876 }
877  
878 sub was_submitted
879 0 ▶{
Subroutine was_submitted: not called CC=3 SCAR=24.8
Pod documented
880 0 my($self) = shift;
881  
882 0 foreach my $field ($self->fields)
883 {
884 0 ▶ return 1 if($self->param_exists_for_field($field->name));
Branch: 1 branch
BranchTrueFalseTotal
if $self->param_exists_for_field($field->name) 0 0 0
885 }
886  
887 0 return 0;
888 }
889  
890 sub start_html
891 11 ▶{
Subroutine start_html: called CC=1 SCAR=0.0
Pod documented
892 11 my($self) = shift;
893 11 return '<' . ref($self)->html_element . $self->html_attrs_string() . '>';
894 }
895  
896 8 *start_xhtml = \&start_html;
897  
898 sub start_multipart_html
899 2 ▶{
Subroutine start_multipart_html: called CC=1 SCAR=0.0
Pod documented
900 2 my($self) = shift;
901 2 $self->html_attr(enctype => 'multipart/form-data');
902 2 return $self->start_html;
903 }
904  
905 8 *start_multipart_xhtml = \&start_multipart_html;
906  
907 8 ▶sub end_html { '</form>' }
Subroutine end_html: called CC=1 SCAR=0.0
Pod documented
908 2 ▶sub end_multipart_html { '</form>' }
Subroutine end_multipart_html: called CC=1 SCAR=0.0
Pod documented
909  
910 8 *end_xhtml = \&end_html;
911 8 *end_multipart_xhtml = \&end_multipart_html;
912  
913 sub object_from_form
914 19 ▶{
Subroutine object_from_form: called CC=21 SCAR=41.6
Pod documented
915 19 my($self) = shift;
916  
917 19 my($class, $object);
918  
919 19 ▶ if(@_ == 1)
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 16 3 19
elsif (@_) { } 3 0 3
920 {
921 16 $class = shift;
922  
923 16 ▶ if(ref $class)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 2 14 16
924 {
925 2 $object = $class;
926 2 $class = ref $object;
927 }
928 }
929 elsif(@_)
930 {
931 3 my %args = @_;
932  
933 3 $class = $args{'class'};
934 3 $object = $args{'object'};
935 }
936 else
937 {
938 0 croak "Missing required object class argument";
939 }
940  
941 19 ▶ $object ||= $class->new();
Condition66%2/3
$object ||= $class->new
l!l&&r!l&&!r
2170
MC/DC0%0/2
$object ||= $class->new
$object $class->new
Truth table66%2/3
A ||= B
A= $objectB= $class->new
ABresult
1X1
011
000
942  
943 # Special handling of boolean columns for RDBO
944 19 ▶ if($object->isa('Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
if ($object->isa('Rose::DB::Object')) { } 0 19 19
945 {
946 0 my $meta = $object->meta;
947  
948 0 FIELD: foreach my $field ($self->fields)
949 {
950 0 my $name = $field->local_name;
951  
952 # When more than one field has the same local_name(), fields closer
953 # to the parent form take precedence.
954 0 my $check_name = $field->name;
955  
956 # Remove the form name context, if any
957 0 ▶ if(defined(my $form_name_context = $self->form_name_context))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $form_name_context = $self->form_name_context)) 0 0 0
958 {
959 0 $check_name =~ s/^$form_name_context//;
960 }
961  
962 0 ▶ if($check_name ne $name)
Branch: 1 branch
BranchTrueFalseTotal
if ($check_name ne $name) 0 0 0
963 {
964 0 ▶ while($check_name =~ s/(^.+$FF_SEPARATOR_RE|^)[^$FF_SEPARATOR_RE]+$FF_SEPARATOR_RE([^$FF_SEPARATOR_RE]+)$/$1$2/)
Branch: 1 branch
BranchTrueFalseTotal
if ($check_name =~ s/(^.+$Rose::HTML::Form::FF_SEPARATOR_RE|^)[^$Rose::HTML::Form::FF_SEPARATOR_RE]+$Rose::HTML::Form::FF_SEPARATOR_RE([^$Rose::HTML::Form::FF_SEPARATOR_RE]+)$/$1$2/) 0 0 0
965 {
966 0 ▶ next FIELD if($self->field($check_name));
Branch: 1 branch
BranchTrueFalseTotal
if $self->field($check_name) 0 0 0
967 }
968 }
969  
970 0 ▶ if($object->can($name))
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can($name)) 0 0 0
971 {
972 # Checkboxes setting boolean columns
973 0 ▶ if($field->isa('Rose::HTML::Form::Field::Checkbox') &&
Branch: 1 branch
BranchTrueFalseTotal
if ($field->isa('Rose::HTML::Form::Field::Checkbox') and $meta->column($name) and $meta->column($name)->type eq 'boolean') { } 0 0 0
Condition0%0/6
$field->isa("Rose::HTML::Form::Field::Checkbox") and $meta->column($name) and $meta->column($name)->type eq "boolean"
!ll&&!rl&&r
000
$field->isa("Rose::HTML::Form::Field::Checkbox") and $meta->column($name)
!ll&&!rl&&r
000
MC/DC0%0/3
$field->isa("Rose::HTML::Form::Field::Checkbox") and $meta->column($name) and $meta->column($name)->type eq "boolean"
$field->isa("Rose::HTML::Form::Field::Checkbox") $meta->column($name) $meta->column($name)->type eq "boolean"
Truth table0%0/4
A and B and C
A= $field->isa("Rose::HTML::Form::Field::Checkbox")B= $meta->column($name)C= $meta->column($name)->type eq "boolean"
ABCresult
0XX0
10X0
1100
1111
974 $meta->column($name) && $meta->column($name)->type eq 'boolean')
975 {
976 #$Debug && warn "$class object $name(", $field->is_on, ")";
977 0 $object->$name($field->is_on);
978 }
979 else # everything else
980 {
981 #$Debug && warn "$class object $name(", $field->internal_value, ")";
982 0 $object->$name($field->internal_value);
983 }
984 }
985 }
986 }
987 else
988 {
989 19 FIELD: foreach my $field ($self->fields)
990 {
991 126 my $name = $field->local_name;
992  
993 # When more than one field has the same local_name(), fields closer
994 # to the parent form take precedence.
995 126 my $check_name = $field->name;
996  
997 # Remove the form name context, if any
998 126 ▶ if(defined(my $form_name_context = $self->form_name_context))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $form_name_context = $self->form_name_context)) 18 108 126
999 {
1000 18 $check_name =~ s/^$form_name_context//;
1001 }
1002  
1003 126 ▶ if($check_name ne $name)
Branch: 1 branch
BranchTrueFalseTotal
if ($check_name ne $name) 63 63 126
1004 {
1005 63 ▶ while($check_name =~ s/(^.+$FF_SEPARATOR_RE|^)[^$FF_SEPARATOR_RE]+$FF_SEPARATOR_RE([^$FF_SEPARATOR_RE]+)$/$1$2/)
Branch: 1 branch
BranchTrueFalseTotal
if ($check_name =~ s/(^.+$Rose::HTML::Form::FF_SEPARATOR_RE|^)[^$Rose::HTML::Form::FF_SEPARATOR_RE]+$Rose::HTML::Form::FF_SEPARATOR_RE([^$Rose::HTML::Form::FF_SEPARATOR_RE]+)$/$1$2/) 126 60 186
1006 {
1007 126 ▶ next FIELD if($self->field($check_name));
Branch: 1 branch
BranchTrueFalseTotal
if $self->field($check_name) 3 123 126
1008 }
1009 }
1010  
1011 123 ▶ if($object->can($name))
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can($name)) 69 54 123
1012 {
1013 #$Debug && warn "$class object $name(", $field->internal_value, ")";
1014 69 $object->$name($field->internal_value);
1015 }
1016 }
1017 }
1018  
1019 19 return $object;
1020 }
1021  
1022 8 *init_object_with_form = \&object_from_form;
1023  
1024 sub init_with_object
1025 4 ▶{
Subroutine init_with_object: called CC=4 SCAR=13.9
Pod documented
1026 4 my($self, $object) = @_;
1027  
1028 4 ▶ croak "Missing required object argument" unless($object);
Branch: 1 branch
BranchTrueFalseTotal
unless $object 0 4 4
1029  
1030 4 $self->clear();
1031  
1032 4 foreach my $field ($self->fields)
1033 {
1034 15 my $name = $field->local_name;
1035  
1036 15 ▶ if($object->can($name))
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can($name)) 5 10 15
1037 {
1038 #$Debug && warn "field($name) = $object->$name = ", $object->$name();
1039 5 $field->input_value(scalar $object->$name());
1040 }
1041 }
1042 }
1043  
1044 sub clear
1045 307 ▶{
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
1046 307 my($self) = shift;
1047 307 $self->clear_fields;
1048 307 $self->clear_forms;
1049 307 $self->error(undef);
1050 }
1051  
1052 sub reset
1053 4 ▶{
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
1054 4 my($self) = shift;
1055 4 $self->reset_fields;
1056 4 $self->reset_forms;
1057 4 $self->error(undef);
1058 }
1059  
1060 34 ▶sub init_form_rank_counter { 1 }
Subroutine init_form_rank_counter: called CC=1 SCAR=0.0
Pod undocumented
1061  
1062 sub next_form_rank
1063 71 ▶{
Subroutine next_form_rank: called CC=3 SCAR=11.1
Pod undocumented
1064 71 my($self) = shift;
1065  
1066 71 my $rank = 1;
1067  
1068 71 foreach my $form ($self->forms)
1069 {
1070 44 ▶ $rank = $form->rank + 1 if($form->rank >= $rank);
Branch: 1 branch
BranchTrueFalseTotal
if $form->rank >= $rank 44 0 44
1071 }
1072  
1073 71 return $rank;
1074 }
1075  
1076 # XXX: Remove when form_rank_counter is removed
1077 sub increment_form_rank_counter
1078 40 ▶{
Subroutine increment_form_rank_counter: called CC=1 SCAR=0.0
Pod undocumented
1079 40 my($self) = shift;
1080 40 my $rank = $self->form_rank_counter;
1081 40 $self->form_rank_counter($rank + 1);
1082 40 return $rank;
1083 }
1084  
1085 sub repeatable_form
1086 8 ▶{
Subroutine repeatable_form: called CC=4 SCAR=14.0
Pod documented
1087 8 my($self) = shift;
1088  
1089 # Set form
1090 8 ▶ if(@_ > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1 7 8
1091 {
1092 1 my($name, $form) = (shift, shift);
1093 1 $self->delete_repeatable_form($name);
1094 1 return $self->add_repeatable_form($name => $form);
1095 }
1096  
1097 7 ▶ my $form = $self->form(@_) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $form = $self->form(@_) or return undef 7 0 7
1098 7 ▶ return undef unless($form->is_repeatable);
Branch: 1 branch
BranchTrueFalseTotal
unless $form->is_repeatable 0 7 7
1099 7 return $form;
1100 }
1101  
1102 sub repeatable_forms
1103 0 ▶{
Subroutine repeatable_forms: not called CC=4 SCAR=30.0
Pod documented
1104 0 my($self) = shift;
1105  
1106 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1107 {
1108 0 $self->delete_repeatable_forms;
1109 0 $self->add_repeatable_forms(@_);
1110 0 ▶ return unless(defined wantarray);
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
1111 }
1112  
1113 return wantarray ?
1114 0 (grep { $_->is_repeatable_form } $self->forms(@_)) :
1115 0 ▶ [ grep { $_->is_repeatable_form } $self->forms(@_) ];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1116 }
1117  
1118 sub add_repeatable_forms
1119 6 ▶{
Subroutine add_repeatable_forms: called CC=7 SCAR=20.6
Pod documented
1120 6 my($self) = shift;
1121  
1122 6 my @form_args;
1123  
1124 6 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 6 12
1125 {
1126 6 my $arg = shift;
1127  
1128 6 ▶ if(UNIVERSAL::isa($arg, 'Rose::HTML::Form'))
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($arg, 'Rose::HTML::Form')) { } 0 6 6
elsif (not ref $arg) { } 6 0 6
1129 {
1130 0 push(@form_args,
1131 $arg->form_name =>
1132 {
1133 form => $arg,
1134 repeatable => undef,
1135 });
1136 }
1137 elsif(!ref $arg)
1138 {
1139 6 ▶ if(UNIVERSAL::isa($_[0], 'Rose::HTML::Form'))
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], 'Rose::HTML::Form')) { } 4 2 6
elsif (ref $_[0] eq 'HASH') { } 2 0 2
1140 {
1141 4 my $form = shift;
1142  
1143 4 push(@form_args,
1144 $arg =>
1145 {
1146 form => $form,
1147 repeatable => undef,
1148 });
1149 }
1150 elsif(ref $_[0] eq 'HASH')
1151 {
1152 2 my $spec = shift;
1153 2 ▶ $spec->{'repeatable'} = undef unless(exists $spec->{'repeatable'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $spec->{"repeatable"} 2 0 2
1154 2 push(@form_args, $arg => $spec);
1155 }
1156 else
1157 {
1158 0 croak "Invalid argument pair passed to add_repeatable_forms() - $arg, $_[0]";
1159 }
1160 }
1161 else
1162 {
1163 0 croak "Invalid argument passed to add_repeatable_forms() - $arg";
1164 }
1165 }
1166  
1167 6 return $self->add_forms(@form_args);
1168 }
1169  
1170 6 ▶sub add_repeatable_form { shift->add_repeatable_forms(@_) }
Subroutine add_repeatable_form: called CC=1 SCAR=0.0
Pod documented
1171  
1172 sub form_depth
1173 8188 ▶{
Subroutine form_depth: called CC=4 SCAR=13.9
Pod undocumented
1174 8188 my($self) = shift;
1175  
1176 8188 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 72 8116 8188
1177 {
1178 72 return $self->{'form_depth'} = shift;
1179 }
1180  
1181 8116 ▶ return $self->{'form_depth'} if(defined $self->{'form_depth'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"form_depth"} 8005 111 8116
1182  
1183 111 my $depth = 0;
1184 111 my $form = $self;
1185 111 ▶ $depth++ while($form = $form->parent_form);
Branch: 1 branch
BranchTrueFalseTotal
$form = $form->parent_form and do { ++$depth } 30 111 141
1186  
1187 111 return $self->{'form_depth'} = $depth;
1188 }
1189  
1190 sub add_forms
1191 68 ▶{
Subroutine add_forms: called CC=28 SCAR=35.3
Pod documented
1192 68 my($self) = shift;
1193  
1194 68 my @added_forms;
1195  
1196 68 my $next_rank = $self->next_form_rank;
1197  
1198 68 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 74 66 140
1199 {
1200 74 my $arg = shift;
1201  
1202 74 my($name, $form);
1203  
1204 74 ▶ if(UNIVERSAL::isa($arg, 'Rose::HTML::Form'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($arg, 'Rose::HTML::Form')) { } 1 73 74
1205 {
1206 1 $form = $arg;
1207  
1208 1 ▶ if(Scalar::Util::refaddr($form) eq Scalar::Util::refaddr($self))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($form) eq builtin::refaddr($self)) 1 0 1
1209 {
1210 1 croak "Cannot nest a form within itself";
1211 }
1212  
1213 0 $name = $form->form_name;
1214  
1215 0 ▶ croak "Cannot add form $form without a name" unless(defined $name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
1216 0 ▶ croak "Cannot add form with the same name as an existing field: $name"
Branch: 1 branch
BranchTrueFalseTotal
if $self->field($name) 0 0 0
1217 if($self->field($name));
1218  
1219 0 ▶ unless(defined $form->rank)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $form->rank) 0 0 0
1220 {
1221 0 $self->increment_form_rank_counter; # XXX: Remove when form_rank_counter is removed
1222 0 $form->rank($next_rank++);
1223 }
1224 }
1225 else
1226 {
1227 73 $name = $arg;
1228 73 $form = shift;
1229  
1230 73 ▶ croak "Cannot add form with the same name as an existing field: $name"
Branch: 1 branch
BranchTrueFalseTotal
if $self->field($name) 0 73 73
1231 if($self->field($name));
1232  
1233 73 ▶ if(UNIVERSAL::isa($form, 'Rose::HTML::Form'))
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($form, 'Rose::HTML::Form')) { } 59 14 73
elsif (ref $form eq 'HASH') { } 14 0 14
1234 {
1235 59 ▶ if(Scalar::Util::refaddr($form) eq Scalar::Util::refaddr($self))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($form) eq builtin::refaddr($self)) 1 58 59
1236 {
1237 1 croak "Cannot nest a form within itself";
1238 }
1239  
1240 # Manually propagate the empty_is_ok attribute to sub-forms, but only if it's set
1241 58 ▶ $form->empty_is_ok(1) if($self->empty_is_ok);
Branch: 1 branch
BranchTrueFalseTotal
if $self->empty_is_ok 3 55 58
1242 }
1243 elsif(ref $form eq 'HASH')
1244 {
1245 14 ▶ unless(exists $form->{'repeatable'})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $form->{"repeatable"}) 0 14 14
1246 {
1247 0 croak "Missing key 'repeatable' in hash reference specification for form named '$name'";
1248 }
1249  
1250 14 my $repeat_spec = $form;
1251  
1252 14 ▶ if(ref $form->{'repeatable'})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $form->{'repeatable'}) { } 1 13 14
1253 {
1254 1 @$repeat_spec{keys %{$form->{'repeatable'}}} = values %{$form->{'repeatable'}};
1255 }
1256 else
1257 {
1258 $repeat_spec->{'default_count'} = $form->{'repeatable'}
1259 13 ▶ unless(exists $repeat_spec->{'default_count'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $repeat_spec->{"default_count"} 8 5 13
1260 }
1261  
1262 14 delete $form->{'repeatable'};
1263  
1264 $repeat_spec->{'prototype_form_spec'} = delete $repeat_spec->{'spec'}
1265 14 ▶ if($repeat_spec->{'spec'});
Branch: 1 branch
BranchTrueFalseTotal
if $repeat_spec->{"spec"} 0 14 14
1266  
1267 $repeat_spec->{'prototype_form_spec'} = delete $repeat_spec->{'form_spec'}
1268 14 ▶ if($repeat_spec->{'form_spec'});
Branch: 1 branch
BranchTrueFalseTotal
if $repeat_spec->{"form_spec"} 3 11 14
1269  
1270 $repeat_spec->{'prototype_form_class'} = delete $repeat_spec->{'class'}
1271 14 ▶ if($repeat_spec->{'class'});
Branch: 1 branch
BranchTrueFalseTotal
if $repeat_spec->{"class"} 0 14 14
1272  
1273 $repeat_spec->{'prototype_form_class'} = delete $repeat_spec->{'form_class'}
1274 14 ▶ if($repeat_spec->{'form_class'});
Branch: 1 branch
BranchTrueFalseTotal
if $repeat_spec->{"form_class"} 4 10 14
1275  
1276 $repeat_spec->{'prototype_form'} = delete $repeat_spec->{'form'}
1277 14 ▶ if($repeat_spec->{'form'});
Branch: 1 branch
BranchTrueFalseTotal
if $repeat_spec->{"form"} 8 6 14
1278  
1279 14 $form = ref($self)->object_type_class_loaded('repeatable form')->new(%$repeat_spec);
1280  
1281 # Manually propagate the empty_is_ok attribute to sub-forms, but only if it's set
1282 14 ▶ if($repeat_spec->{'empty_is_ok'} || $self->empty_is_ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($repeat_spec->{"empty_is_ok"} or $self->empty_is_ok) 1 13 14
Condition66%2/3
$repeat_spec->{"empty_is_ok"} or $self->empty_is_ok
l!l&&r!l&&!r
1013
MC/DC50%1/2
$repeat_spec->{"empty_is_ok"} or $self->empty_is_ok
$repeat_spec->{"empty_is_ok"} $self->empty_is_ok
Truth table66%2/3
A or B
A= $repeat_spec->{"empty_is_ok"}B= $self->empty_is_ok
ABresult
1X1
011
000
1283 {
1284 1 $form->empty_is_ok(1);
1285 }
1286 }
1287 else
1288 {
1289 0 Carp::croak "Not a Rose::HTML::Form object: $form";
1290 }
1291  
1292 72 $form->form_name($name);
1293  
1294 72 ▶ unless(defined $form->rank)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $form->rank) 37 35 72
1295 {
1296 37 $self->increment_form_rank_counter; # XXX: Remove when form_rank_counter is removed
1297 37 $form->rank($next_rank++);
1298 }
1299 }
1300  
1301 72 ▶ if(index($name, FF_SEPARATOR) >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($name, '.') != -1) { } 2 70 72
1302 {
1303 2 my($parent_form, $local_name) = $self->choose_parent_form($name);
1304 2 $form->form_name($local_name);
1305 2 $form->parent_form($parent_form);
1306 2 $parent_form->add_form($local_name => $form);
1307 }
1308 else
1309 {
1310 70 $form->parent_form($self);
1311 70 $self->{'forms'}{$name} = $form;
1312 }
1313  
1314 72 push(@added_forms, $form);
1315 }
1316  
1317 66 my $depth = $self->form_depth + 1;
1318  
1319 66 foreach my $form (@added_forms)
1320 {
1321 72 ▶ if($form->recursive_init_fields || $form->isa('Rose::HTML::Form::Repeatable'))
Branch: 1 branch
BranchTrueFalseTotal
if ($form->recursive_init_fields or $form->isa("Rose::HTML::Form::Repeatable")) 42 30 72
Condition100%3/3
$form->recursive_init_fields or $form->isa("Rose::HTML::Form::Repeatable")
l!l&&r!l&&!r
281430
MC/DC100%2/2
$form->recursive_init_fields or $form->isa("Rose::HTML::Form::Repeatable")
$form->recursive_init_fields $form->isa("Rose::HTML::Form::Repeatable")
Truth table100%3/3
A or B
A= $form->recursive_init_fieldsB= $form->isa("Rose::HTML::Form::Repeatable")
ABresult
1X1
011
000
1322 {
1323 42 $self->recursive_init_fields(1);
1324 }
1325  
1326 72 $form->form_depth($depth);
1327 72 $form->resync_field_names;
1328 }
1329  
1330 66 $self->_clear_form_generated_values;
1331 66 $self->resync_fields_by_name;
1332  
1333 66 ▶ return unless(defined wantarray);
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 66 0 66
1334 0 return @added_forms;
1335 }
1336  
1337 8 *add_form = \&add_forms;
1338  
1339 sub resync_field_names
1340 225 ▶{
Subroutine resync_field_names: called CC=3 SCAR=11.0
Pod undocumented
1341 225 my($self) = shift;
1342  
1343 225 foreach my $field ($self->fields)
1344 {
1345 1246 $field->resync_name;
1346 }
1347  
1348 225 foreach my $form ($self->forms)
1349 {
1350 39 $form->resync_field_names;
1351 }
1352 }
1353  
1354 sub resync_fields_by_name
1355 66 ▶{
Subroutine resync_fields_by_name: called CC=2 SCAR=6.9
Pod undocumented
1356 66 my($self) = shift;
1357  
1358 66 $self->{'fields_by_name'} = {};
1359  
1360 66 foreach my $field ($self->fields)
1361 {
1362 362 $self->{'fields_by_name'}{$field->name} = $field;
1363 }
1364 }
1365  
1366 sub compare_forms
1367 4025 ▶{
Subroutine compare_forms: called CC=2 SCAR=6.9
Pod documented
1368 4025 my($self, $one, $two) = @_;
1369 8 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1370 4025 ▶ return $one->form_depth <=> $two->form_depth || $one->rank <=> $two->rank;
Condition100%3/3
$one->form_depth <=> $two->form_depth || $one->rank <=> $two->rank
l!l&&r!l&&!r
3313623332
MC/DC100%2/2
$one->form_depth <=> $two->form_depth || $one->rank <=> $two->rank
$one->form_depth <=> $two->form_depth $one->rank <=> $two->rank
Truth table100%3/3
A || B
A= $one->form_depth <=> $two->form_depthB= $one->rank <=> $two->rank
ABresult
1X1
011
000
1371 }
1372  
1373 sub forms
1374 1671 ▶{
Subroutine forms: called CC=6 SCAR=19.5
Pod documented
1375 1671 my($self) = shift;
1376  
1377 1671 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1671 1671
1378 {
1379 0 $self->delete_forms;
1380 0 $self->add_forms(@_);
1381 0 ▶ return unless(defined wantarray);
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
1382 }
1383  
1384 1671 ▶ if(my $forms = $self->{'form_list'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $forms = $self->{"form_list"}) 1490 181 1671
1385 {
1386 1490 ▶ return wantarray ? @$forms : $forms;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1453 37 1490
1387 }
1388  
1389 181 my $forms = $self->{'forms'};
1390  
1391 181 $self->{'form_list'} = [ grep { defined } map { $forms->{$_} } $self->form_names ];
1392  
1393 181 ▶ return wantarray ? @{$self->{'form_list'}} : $self->{'form_list'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 181 0 181
1394 }
1395  
1396 sub form_names
1397 183 ▶{
Subroutine form_names: called CC=5 SCAR=16.1
Pod documented
1398 183 my($self) = shift;
1399  
1400 183 ▶ if(my $names = $self->{'form_names'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $names = $self->{"form_names"}) 2 181 183
1401 {
1402 2 ▶ return wantarray ? @$names : $names;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
1403 }
1404  
1405 181 my @info;
1406  
1407 181 ▶ while(my($name, $form) = each %{$self->{'forms'}})
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"forms"};}) 119 181 300
1408 {
1409 119 push(@info, [ $name, $form ]);
1410 }
1411  
1412 $self->{'form_names'} =
1413 181 [ map { $_->[0] } sort { $self->compare_forms($a->[1], $b->[1]) } @info ];
1414  
1415 181 ▶ return wantarray ? @{$self->{'form_names'}} : $self->{'form_names'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 181 0 181
1416 }
1417  
1418 sub delete_repeatable_forms
1419 0 ▶{
Subroutine delete_repeatable_forms: not called CC=2 SCAR=17.9
Pod documented
1420 0 my($self) = shift;
1421  
1422 0 foreach my $form (grep { $_->is_repeatable_form } $self->forms)
1423 {
1424 0 delete $self->{'forms'}{$form->form_name};
1425 }
1426  
1427 0 $self->_clear_form_generated_values;
1428  
1429 0 return;
1430 }
1431  
1432 sub delete_repeatable_form
1433 4 ▶{
Subroutine delete_repeatable_form: called CC=4 SCAR=15.5
Pod documented
1434 4 my($self, $name) = @_;
1435  
1436 4 ▶ $name = $name->form_name if(UNIVERSAL::isa($name, 'Rose::HTML::Form'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($name, "Rose::HTML::Form") 0 4 4
1437  
1438 4 ▶ if(exists $self->{'forms'}{$name} && $self->{'forms'}{$name}->is_repeatable_form)
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"forms"}{$name} and $self->{"forms"}{$name}->is_repeatable_form) 4 0 4
Condition33%1/3
exists $self->{"forms"}{$name} and $self->{"forms"}{$name}->is_repeatable_form
!ll&&!rl&&r
004
MC/DC0%0/2
exists $self->{"forms"}{$name} and $self->{"forms"}{$name}->is_repeatable_form
exists $self->{"forms"}{$name} $self->{"forms"}{$name}->is_repeatable_form
Truth table33%1/3
A and B
A= exists $self->{"forms"}{$name}B= $self->{"forms"}{$name}->is_repeatable_form
ABresult
0X0
100
111
1439 {
1440 4 my $form = delete $self->{'forms'}{$name};
1441  
1442 4 $self->_clear_form_generated_values;
1443  
1444 4 return $form;
1445 }
1446  
1447 0 return undef;
1448 }
1449  
1450 sub delete_repeatable_fields
1451 8 ▶{
Subroutine delete_repeatable_fields: called CC=2 SCAR=7.6
Pod undocumented
1452 8 my($self) = shift;
1453  
1454 0 foreach my $form (grep { $_->is_repeatable_field } $self->forms)
1455 {
1456 0 delete $self->{'forms'}{$form->form_name};
1457 }
1458  
1459 8 $self->_clear_form_generated_values;
1460  
1461 8 return;
1462 }
1463  
1464 sub delete_repeatable_field
1465 0 ▶{
Subroutine delete_repeatable_field: not called CC=4 SCAR=30.0
Pod undocumented
1466 0 my($self, $name) = @_;
1467  
1468 0 ▶ $name = $name->form_name if(UNIVERSAL::isa($name, 'Rose::HTML::Form'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($name, "Rose::HTML::Form") 0 0 0
1469  
1470 0 ▶ if(exists $self->{'forms'}{$name} && $self->{'forms'}{$name}->is_repeatable_field)
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"forms"}{$name} and $self->{"forms"}{$name}->is_repeatable_field) 0 0 0
Condition0%0/3
exists $self->{"forms"}{$name} and $self->{"forms"}{$name}->is_repeatable_field
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"forms"}{$name} and $self->{"forms"}{$name}->is_repeatable_field
exists $self->{"forms"}{$name} $self->{"forms"}{$name}->is_repeatable_field
Truth table0%0/3
A and B
A= exists $self->{"forms"}{$name}B= $self->{"forms"}{$name}->is_repeatable_field
ABresult
0X0
100
111
1471 {
1472 0 $self->_clear_form_generated_values;
1473 0 return delete $self->{'forms'}{$name};
1474 }
1475  
1476 0 return undef;
1477 }
1478  
1479 sub delete_forms
1480 2 ▶{
Subroutine delete_forms: called CC=2 SCAR=6.9
Pod documented
1481 2 my($self) = shift;
1482  
1483 # Leave the repeatable fields which are implemented as a special case of repeatable forms
1484 2 foreach my $form (grep { !$_->is_repeatable_field } $self->forms)
1485 {
1486 3 delete $self->{'forms'}{$form->form_name};
1487 }
1488  
1489 2 $self->form_rank_counter(undef); # XXX: Remove when form_rank_counter is removed
1490 2 $self->_clear_form_generated_values;
1491 2 return;
1492 }
1493  
1494 sub delete_form
1495 15 ▶{
Subroutine delete_form: called CC=3 SCAR=11.0
Pod documented
1496 15 my($self, $name) = @_;
1497  
1498 15 ▶ $name = $name->form_name if(UNIVERSAL::isa($name, 'Rose::HTML::Form'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($name, "Rose::HTML::Form") 0 15 15
1499  
1500 15 ▶ if(exists $self->{'forms'}{$name})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"forms"}{$name}) 14 1 15
1501 {
1502 14 my $form = delete $self->{'forms'}{$name};
1503  
1504 14 $self->_clear_form_generated_values;
1505  
1506 14 return $form;
1507 }
1508  
1509 1 return undef;
1510 }
1511  
1512 sub clear_forms
1513 307 ▶{
Subroutine clear_forms: called CC=2 SCAR=6.9
Pod undocumented
1514 307 my($self) = shift;
1515  
1516 307 foreach my $form ($self->forms)
1517 {
1518 186 $form->clear();
1519 }
1520 }
1521  
1522 sub reset_forms
1523 4 ▶{
Subroutine reset_forms: called CC=2 SCAR=7.6
Pod undocumented
1524 4 my($self) = shift;
1525  
1526 4 foreach my $form ($self->forms)
1527 {
1528 0 $form->reset();
1529 }
1530 }
1531  
1532 sub _clear_form_generated_values
1533 94 ▶{
Subroutine _clear_form_generated_values: called CC=1 SCAR=0.0
1534 94 my($self) = shift;
1535 94 $self->{'form_list'} = undef;
1536 94 $self->{'form_names'} = undef;
1537 94 $self->{'form_depth'} = undef;
1538 94 $self->_clear_field_generated_values;
1539 }
1540  
1541 sub form_name
1542 8194 ▶{
Subroutine form_name: called CC=6 SCAR=18.1
Pod documented
1543 8194 my($self) = shift;
1544  
1545 8194 ▶ return $self->{'form_name'} unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 8117 77 8194
1546 77 my $old_name = $self->{'form_name'};
1547 77 my $name = $self->{'form_name'} = shift;
1548 77 my %forms;
1549  
1550 77 ▶ if(my $parent_form = $self->parent_form)
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent_form = $self->parent_form) 6 71 77
1551 {
1552 6 ▶ if(defined $old_name && defined $name && $name ne $old_name)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old_name and defined $name and $name ne $old_name) 2 4 6
Condition50%3/6
defined $old_name and defined $name and $name ne $old_name
!ll&&!rl&&r
042
defined $old_name and defined $name
!ll&&!rl&&r
006
MC/DC33%1/3
defined $old_name and defined $name and $name ne $old_name
defined $old_name defined $name $name ne $old_name
Truth table50%2/4
A and B and C
A= defined $old_nameB= defined $nameC= $name ne $old_name
ABCresult
0XX0
10X0
1100
1111
1553 {
1554 2 $parent_form->delete_form($old_name);
1555 2 $parent_form->add_form($name => $self);
1556 }
1557 }
1558  
1559 77 return $name;
1560 }
1561  
1562 sub local_field
1563 1609 ▶{
Subroutine local_field: called CC=4 SCAR=13.9
Pod documented
1564 1609 my($self, $name) = (shift, shift);
1565  
1566 1609 ▶ if(my $field = shift)
Branch: 1 branch
BranchTrueFalseTotal
if (my $field = shift()) 258 1351 1609
1567 {
1568 258 $field = $self->make_field($name, $field);
1569  
1570 258 $field->parent_form($self);
1571 8 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1572 258 ▶ $field->name($name) unless(length $field->name);
Branch: 1 branch
BranchTrueFalseTotal
unless length $field->name 34 224 258
1573 258 $field->moniker($name);
1574 258 $self->{'fields_by_name'}{$field->name} = $field;
1575 258 return $self->{'fields'}{$name} = $field;
1576 }
1577  
1578 1351 ▶ return $self->{'fields'}{$name} || $self->{'fields_by_name'}{$name};
Condition100%3/3
$self->{'fields'}{$name} || $self->{'fields_by_name'}{$name}
l!l&&r!l&&!r
24041107
MC/DC100%2/2
$self->{'fields'}{$name} || $self->{'fields_by_name'}{$name}
$self->{'fields'}{$name} $self->{'fields_by_name'}{$name}
Truth table100%3/3
A || B
A= $self->{'fields'}{$name}B= $self->{'fields_by_name'}{$name}
ABresult
1X1
011
000
1579 }
1580  
1581 sub local_fields
1582 113 ▶{
Subroutine local_fields: called CC=2 SCAR=7.1
Pod documented
1583 113 my($self) = shift;
1584 113 ▶ return values %{ $self->{'fields'} || {} };
Condition50%1/2
$self->{'fields'} || {}
l!l
1130
MC/DC0%0/1
$self->{'fields'} || {}
$self->{'fields'}
Truth table50%1/2
A
A= $self->{'fields'}
Aresult
11
00
1585 }
1586  
1587 sub delete_fields
1588 8 ▶{
Subroutine delete_fields: called CC=1 SCAR=0.0
Pod documented
1589 8 my($self) = shift;
1590 8 $self->_clear_field_generated_values;
1591 8 $self->{'fields'} = {};
1592 8 $self->{'fields_by_name'} = {};
1593 8 $self->delete_repeatable_fields;
1594 8 $self->field_rank_counter(undef);
1595 8 return;
1596 }
1597  
1598 sub delete_field
1599 2 ▶{
Subroutine delete_field: called CC=3 SCAR=11.6
Pod documented
1600 2 my($self, $name) = @_;
1601  
1602 2 ▶ $name = $name->name if(UNIVERSAL::isa($name, 'Rose::HTML::Form::Field'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($name, "Rose::HTML::Form::Field") 0 2 2
1603  
1604 2 $self->_clear_field_generated_values;
1605  
1606 2 my $field1 = delete $self->{'fields'}{$name};
1607 2 my $field2 = delete $self->{'fields_by_name'}{$name};
1608 2 ▶ return $field1 || $field2;
Condition33%1/3
$field1 || $field2
l!l&&r!l&&!r
200
MC/DC0%0/2
$field1 || $field2
$field1 $field2
Truth table33%1/3
A || B
A= $field1B= $field2
ABresult
1X1
011
000
1609 }
1610  
1611 sub field
1612 3085 ▶{
Subroutine field: called CC=6 SCAR=18.0
Pod documented
1613 3085 my($self, $name) = (shift, shift);
1614  
1615 3085 ▶ return $self->{'field_cache'}{$name} if($self->{'field_cache'}{$name});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"field_cache"}{$name} 629 2456 3085
1616  
1617 2456 my $sep_pos;
1618  
1619 # Non-hierarchical name
1620 2456 ▶ if(($sep_pos = index($name, FF_SEPARATOR)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (($sep_pos = index($name, ".")) < 0) 1558 898 2456
1621 {
1622 1558 return $self->{'field_cache'}{$name} = $self->local_field($name, @_);
1623 }
1624  
1625 # First check if it's a local compound field
1626 898 my $prefix = substr($name, 0, $sep_pos);
1627 898 my $rest = substr($name, $sep_pos + 1);
1628 898 my $field = $self->field($prefix);
1629  
1630 898 ▶ if(UNIVERSAL::isa($field, 'Rose::HTML::Form::Field::Compound'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($field, "Rose::HTML::Form::Field::Compound")) 17 881 898
1631 {
1632 17 $field = $field->field($rest);
1633 17 ▶ return ($self->{'field_cache'}{$name} = $field) if($field);
Branch: 1 branch
BranchTrueFalseTotal
if $field 17 0 17
1634 }
1635  
1636 881 my($parent_form, $local_name) = $self->find_parent_form($name);
1637  
1638 881 ▶ return undef unless($parent_form);
Branch: 1 branch
BranchTrueFalseTotal
unless $parent_form 0 881 881
1639  
1640 881 return $self->{'field_cache'}{$name} = $parent_form->field($local_name, @_);
1641 }
1642  
1643 sub fields
1644 929 ▶{
Subroutine fields: called CC=10 SCAR=23.7
Pod documented
1645 929 my($self) = shift;
1646  
1647 929 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 927 929
1648 {
1649 2 $self->delete_fields;
1650 2 $self->add_fields(@_);
1651 }
1652  
1653 929 ▶ if(my $fields = $self->{'field_list'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $fields = $self->{"field_list"}) 682 247 929
1654 {
1655 682 ▶ return wantarray ? @$fields : $fields;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 680 2 682
1656 }
1657  
1658 247 my $fields = $self->{'fields'};
1659 247 my $fields_by_name = $self->{'fields_by_name'};
1660  
1661 $self->{'field_list'} =
1662 [
1663 1606 grep { defined }
1664 map
1665 {
1666 247 ▶ if(/$FF_SEPARATOR_RE([^$FF_SEPARATOR_RE]+)/o)
Branch: 1 branch
BranchTrueFalseTotal
if (/$Rose::HTML::Form::FF_SEPARATOR_RE([^$Rose::HTML::Form::FF_SEPARATOR_RE]+)/o) { } 610 996 1606
1667 {
1668 610 ▶ $self->field($_) || $fields->{$1} || $fields_by_name->{$1};
Condition33%2/6
$self->field($_) || $fields->{$1} || $fields_by_name->{$1}
l!l&&r!l&&!r
61000
$self->field($_) or $fields->{$1}
l!l&&r!l&&!r
61000
MC/DC0%0/3
$self->field($_) || $fields->{$1} || $fields_by_name->{$1}
$self->field($_) $fields->{$1} $fields_by_name->{$1}
Truth table25%1/4
A or B || C
A= $self->field($_)B= $fields->{$1}C= $fields_by_name->{$1}
ABCresult
1XX1
01X1
0011
0000
1669 }
1670 else
1671 {
1672 996 ▶ $fields->{$_} || $fields_by_name->{$_} || $self->field($_);
Condition66%4/6
$fields->{$_} || $fields_by_name->{$_} || $self->field($_)
l!l&&r!l&&!r
99204
$fields->{$_} or $fields_by_name->{$_}
l!l&&r!l&&!r
99204
MC/DC33%1/3
$fields->{$_} || $fields_by_name->{$_} || $self->field($_)
$fields->{$_} $fields_by_name->{$_} $self->field($_)
Truth table50%2/4
A or B || C
A= $fields->{$_}B= $fields_by_name->{$_}C= $self->field($_)
ABCresult
1XX1
01X1
0011
0000
1673 }
1674 }
1675 $self->field_monikers
1676 ];
1677  
1678 247 ▶ return wantarray ? @{$self->{'field_list'}} : $self->{'field_list'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 247 0 247
1679 }
1680  
1681 sub fields_depth_first
1682 52 ▶{
Subroutine fields_depth_first: called CC=3 SCAR=11.0
Pod documented
1683 52 my($self) = shift;
1684  
1685 52 my @fields = sort { $a->rank <=> $b->rank } $self->local_fields;
1686  
1687 52 foreach my $form ($self->forms)
1688 {
1689 42 push(@fields, $form->fields_depth_first);
1690 }
1691  
1692 52 ▶ return wantarray ? @fields : \@fields;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 52 0 52
1693 }
1694  
1695 sub field_monikers
1696 268 ▶{
Subroutine field_monikers: called CC=5 SCAR=16.2
Pod documented
1697 268 my($self) = shift;
1698  
1699 268 ▶ if(my $names = $self->{'field_monikers'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $names = $self->{"field_monikers"}) 25 243 268
1700 {
1701 25 ▶ return wantarray ? @$names : $names;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 22 3 25
1702 }
1703  
1704 243 my @info;
1705  
1706 243 $self->_find_field_info($self, \@info);
1707  
1708 $self->{'field_monikers'} =
1709 243 ▶ [ map { $_->[2] } sort { $self->compare_forms($a->[0], $b->[0]) || $self->compare_fields($a->[1], $b->[1]) } @info ];
Condition66%2/3
$self->compare_forms($Rose::HTML::Form::a->[0], $Rose::HTML::Form::b->[0]) || $self->compare_fields($Rose::HTML::Form::a->[1], $Rose::HTML::Form::b->[1])
l!l&&r!l&&!r
64333320
MC/DC0%0/2
$self->compare_forms($Rose::HTML::Form::a->[0], $Rose::HTML::Form::b->[0]) || $self->compare_fields($Rose::HTML::Form::a->[1], $Rose::HTML::Form::b->[1])
$self->compare_forms($Rose::HTML::Form::a->[0], $Rose::HTML::Form::b->[0]) $self->compare_fields($Rose::HTML::Form::a->[1], $Rose::HTML::Form::b->[1])
Truth table66%2/3
A || B
A= $self->compare_forms($Rose::HTML::Form::a->[0], $Rose::HTML::Form::b->[0])B= $self->compare_fields($Rose::HTML::Form::a->[1], $Rose::HTML::Form::b->[1])
ABresult
1X1
011
000
1710  
1711 243 ▶ return wantarray ? @{$self->{'field_monikers'}} : $self->{'field_monikers'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 243 0 243
1712 }
1713  
1714 13 ▶sub field_names { shift->field_monikers(@_) }
Subroutine field_names: called CC=1 SCAR=0.0
Pod documented
1715  
1716 sub _find_field_info
1717 548 ▶{
Subroutine _find_field_info: called CC=3 SCAR=11.0
1718 548 my($self, $form, $list) = @_;
1719  
1720 548 ▶ while(my($name, $field) = each %{$form->{'fields'}})
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$form{"fields"};}) 1599 548 2147
1721 {
1722 1599 push(@$list, [ $form, $field, $field->fq_moniker ]);
1723 }
1724  
1725 548 foreach my $sub_form ($form->forms)
1726 {
1727 305 $form->_find_field_info($sub_form, $list);
1728 }
1729 }
1730  
1731 sub find_parent_form
1732 1242 ▶{
Subroutine find_parent_form: called CC=8 SCAR=20.8
Pod undocumented
1733 1242 my($self, $name) = @_;
1734  
1735 # Non-hierarchical name
1736 1242 ▶ if(index($name, FF_SEPARATOR) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($name, ".") == -1) 278 964 1242
1737 {
1738 278 ▶ return $self->local_form($name) ? ($self, $name) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->local_form($name) ? : 0 278 278
1739 }
1740  
1741 964 my $parent_form;
1742  
1743 964 ▶ while($name =~ s/^([^$FF_SEPARATOR_RE]+)$FF_SEPARATOR_RE//o)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/^([^$Rose::HTML::Form::FF_SEPARATOR_RE]+)$Rose::HTML::Form::FF_SEPARATOR_RE//o) 1335 51 1386
1744 {
1745 1335 my $parent_name = $1;
1746 1335 ▶ last if($parent_form = $self->local_form($parent_name));
Branch: 1 branch
BranchTrueFalseTotal
if $parent_form = $self->local_form($parent_name) 913 422 1335
1747 }
1748  
1749 964 ▶ unless(defined $parent_form)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parent_form) 51 913 964
1750 {
1751 # Maybe this form ($self) is the parent?
1752 51 ▶ return ($self, $name) if($self->local_field($name));
Branch: 1 branch
BranchTrueFalseTotal
if $self->local_field($name) 30 21 51
1753 21 return undef;
1754 }
1755  
1756 913 ▶ return wantarray ? ($parent_form, $name) : $parent_form;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 913 0 913
1757 }
1758  
1759 sub choose_parent_form
1760 2 ▶{
Subroutine choose_parent_form: called CC=6 SCAR=20.9
Pod undocumented
1761 2 my($self, $name) = @_;
1762  
1763 # Non-hierarchical name
1764 2 ▶ if(index($name, FF_SEPARATOR) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($name, ".") == -1) 0 2 2
1765 {
1766 0 ▶ return wantarray ? ($self, $name) : $self;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1767 }
1768  
1769 2 my($parent_form, $local_name);
1770  
1771 2 ▶ while($name =~ s/^(.+)$FF_SEPARATOR_RE([^$FF_SEPARATOR_RE]+)$//o)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/^(.+)$Rose::HTML::Form::FF_SEPARATOR_RE([^$Rose::HTML::Form::FF_SEPARATOR_RE]+)$//o) 2 0 2
1772 {
1773 2 $local_name = $2;
1774 2 ▶ last if($parent_form = $self->form($1));
Branch: 1 branch
BranchTrueFalseTotal
if $parent_form = $self->form($1) 2 0 2
1775 }
1776  
1777 2 ▶ return wantarray ? ($parent_form, $local_name) : $parent_form;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
1778 }
1779  
1780 sub fq_form_name
1781 6119 ▶{
Subroutine fq_form_name: called CC=4 SCAR=13.9
Pod undocumented
1782 6119 my($self) = shift;
1783  
1784 6119 ▶ return $self->form_name unless($self->parent_form);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parent_form 3969 2150 6119
1785  
1786 2150 my @parts;
1787 2150 my $form = $self;
1788  
1789 2150 ▶ while(my $parent_form = $form->parent_form)
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent_form = $form->parent_form) 4025 2150 6175
1790 {
1791 4025 unshift(@parts, $form->form_name);
1792 4025 $form = $parent_form;
1793 }
1794  
1795 2150 ▶ return @parts ? join(FF_SEPARATOR, @parts) : '';
Branch: 1 branch
BranchTrueFalseTotal
@parts ? : 2150 0 2150
1796 }
1797  
1798 sub form_name_context
1799 126 ▶{
Subroutine form_name_context: called CC=3 SCAR=11.0
Pod undocumented
1800 126 my($self) = shift;
1801  
1802 126 ▶ return undef unless($self->parent_form);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parent_form 108 18 126
1803  
1804 18 my @context;
1805 18 my $form = $self;
1806  
1807 18 for(;;)
1808 {
1809 45 ▶ last unless($form->parent_form);
Branch: 1 branch
BranchTrueFalseTotal
unless $form->parent_form 18 27 45
1810 27 unshift(@context, $form->form_name);
1811 27 $form = $form->parent_form;
1812 }
1813  
1814 18 return join(FF_SEPARATOR, @context) . FF_SEPARATOR;
1815 }
1816  
1817 sub local_form
1818 2174 ▶{
Subroutine local_form: called CC=2 SCAR=6.9
Pod documented
1819 2174 my($self, $name) = @_;
1820 2174 ▶ return $self->{'forms'}{$name} if(exists $self->{'forms'}{$name});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"forms"}{$name} 1113 1061 2174
1821 1061 return undef;
1822 }
1823  
1824 sub form
1825 562 ▶{
Subroutine form: called CC=4 SCAR=13.9
Pod documented
1826 562 my($self, $name) = (shift, shift);
1827  
1828 # Set form
1829 562 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 561 562
1830 {
1831 1 my $form = shift;
1832 1 $self->delete_form($name);
1833 1 return $self->add_form($name => $form);
1834 }
1835  
1836 # Local form?
1837 561 ▶ if(my $form = $self->local_form($name))
Branch: 1 branch
BranchTrueFalseTotal
if (my $form = $self->local_form($name)) 200 361 561
1838 {
1839 200 return $form;
1840 }
1841  
1842 # Look up nested form
1843 361 my($parent_form, $local_name) = $self->find_parent_form($name);
1844 361 ▶ return undef unless(defined $parent_form);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parent_form 299 62 361
1845 62 return $parent_form->form($local_name);
1846 }
1847  
1848 sub _html_table
1849 5 ▶{
Subroutine _html_table: called CC=26 SCAR=40.7
1850 5 my($self, %args) = @_;
1851  
1852 5 ▶ my $xhtml = delete $args{'_xhtml'} ? 'xhtml' : 'html';
Branch: 1 branch
BranchTrueFalseTotal
delete $args{'_xhtml'} ? : 5 0 5
1853 5 my $xhtml_field = "${xhtml}_field";
1854 5 my $xhtml_label = "${xhtml}_label";
1855  
1856 my $max_button_depth =
1857 5 ▶ exists $args{'max_button_depth'} ? $args{'max_button_depth'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_button_depth'} ? : 0 5 5
1858  
1859 5 ▶ $args{'class'} = defined $args{'class'} ?
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'class'} ? : 0 5 5
1860 "$args{'class'} form" : 'form';
1861  
1862 5 ▶ $args{'tr'} ||= {};
Condition50%1/2
$args{"tr"} ||= {}
l!l
05
MC/DC0%0/1
$args{"tr"} ||= {}
$args{"tr"}
Truth table50%1/2
A
A= $args{"tr"}
Aresult
11
00
1863 5 ▶ $args{'td'} ||= {};
Condition50%1/2
$args{"td"} ||= {}
l!l
05
MC/DC0%0/1
$args{"td"} ||= {}
$args{"td"}
Truth table50%1/2
A
A= $args{"td"}
Aresult
11
00
1864  
1865 $args{'table'}{'class'} = defined $args{'table'}{'class'} ?
1866 "$args{'table'}{'class'} form" :
1867 5 ▶ defined $args{'class'} ? $args{'class'} : undef;
Branch: 2 branches
BranchTrueFalseTotal
defined $args{'table'}{'class'} ? : 0 5 5
defined $args{'class'} ? : 5 0 5
1868  
1869 5 ▶ $args{'tr'}{'class'} = defined $args{'tr'}{'class'} ?
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'tr'}{'class'} ? : 0 5 5
1870 "$args{'tr'}{'class'} field" : 'field';
1871  
1872 5 my $html = join('', map { $_->$xhtml() } $self->pre_children);
1873  
1874 0 $html .= join("\n", map { $_->$xhtml_field() }
1875 5 grep { $_->isa('Rose::HTML::Form::Field::Hidden') } $self->fields);
1876  
1877 5 ▶ $html .= "\n\n" if($html);
Branch: 1 branch
BranchTrueFalseTotal
if $html 2 3 5
1878  
1879 5 $html .= '<table' . Rose::HTML::Util::html_attrs_string($args{'table'}) . ">\n";
1880  
1881 5 my $form_start = "start_$xhtml";
1882 5 my $form_end = "end_$xhtml";
1883  
1884 5 my $i = 1;
1885  
1886 5 my @buttons;
1887  
1888 5 foreach my $field (grep { !$_->isa('Rose::HTML::Form::Field::Hidden') } $self->fields_depth_first)
1889 {
1890 10 ▶ if($field->is_button)
Branch: 1 branch
BranchTrueFalseTotal
if ($field->is_button) 0 10 10
1891 {
1892 0 ▶ next if($field->field_depth > $max_button_depth);
Branch: 1 branch
BranchTrueFalseTotal
if $field->field_depth > $max_button_depth 0 0 0
1893  
1894 0 ▶ if($field->field_depth == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($field->field_depth == 1) 0 0 0
1895 {
1896 0 push(@buttons, $field);
1897 0 next;
1898 }
1899 }
1900  
1901 10 ▶ if($field->isa('Rose::HTML::Form::Field::File'))
Branch: 1 branch
BranchTrueFalseTotal
if ($field->isa("Rose::HTML::Form::Field::File")) 0 10 10
1902 {
1903 0 $form_start = "start_multipart_$xhtml";
1904 }
1905  
1906 10 ▶ my $odd_even = $i++ % 2 ? 'odd' : 'even';
Branch: 1 branch
BranchTrueFalseTotal
$i++ % 2 ? : 5 5 10
1907  
1908 10 local $args{'tr'}{'class'} = "field-$odd_even";
1909 10 ▶ local $args{'td'}{'class'} = $args{'td'}{'class'} ? "$args{'td'}{'class'} label" : 'label';
Branch: 1 branch
BranchTrueFalseTotal
$args{'td'}{'class'} ? : 0 10 10
1910  
1911 10 my $label = $field->$xhtml_label();
1912  
1913 10 ▶ unless($label)
Branch: 1 branch
BranchTrueFalseTotal
unless ($label) 10 0 10
1914 {
1915 10 my $name = $field->name;
1916  
1917 10 for($name)
1918 {
1919 10 tr[_.][ ];
1920 10 s/\b(\w)/\u$1/g;
1921 }
1922  
1923 10 $label = Rose::HTML::Label->new(contents => Rose::HTML::Util::escape_html($name));
1924  
1925 10 ▶ if($field->html_attr_exists('id'))
Branch: 1 branch
BranchTrueFalseTotal
if ($field->html_attr_exists("id")) 0 10 10
1926 {
1927 0 $label->for($field->html_attr('id'));
1928 }
1929  
1930 10 $label = $label->$xhtml();
1931 }
1932  
1933 10 ▶ if($field->is_button)
Branch: 1 branch
BranchTrueFalseTotal
if ($field->is_button) { } 0 10 10
1934 {
1935 0 local $args{'td'}{'colspan'} = 2;
1936 $html .= '<tr' . Rose::HTML::Util::html_attrs_string($args{'tr'}) . ">\n" .
1937 0 '<td' . Rose::HTML::Util::html_attrs_string($args{'td'}) . '>' .
1938 $field->$xhtml_field . "</td>\n</tr>\n";
1939 }
1940 else
1941 {
1942 $html .= '<tr' . Rose::HTML::Util::html_attrs_string($args{'tr'}) . ">\n" .
1943 10 '<td' . Rose::HTML::Util::html_attrs_string($args{'td'}) . ">$label</td>\n";
1944  
1945 10 $args{'td'}{'class'} =~ s/(?:^| )label$//;
1946 10 ▶ $args{'td'}{'class'} = $args{'td'}{'class'} ? "$args{'td'}{'class'} field" : 'field';
Branch: 1 branch
BranchTrueFalseTotal
$args{'td'}{'class'} ? : 0 10 10
1947  
1948 10 $html .= '<td' . Rose::HTML::Util::html_attrs_string($args{'td'}) . '>' .
1949 $field->$xhtml() .
1950 "</td>\n</tr>\n";
1951 }
1952 }
1953  
1954 5 ▶ if(@buttons)
Branch: 1 branch
BranchTrueFalseTotal
if (@buttons) 0 5 5
1955 {
1956 0 ▶ my $odd_even = $i++ % 2 ? 'odd' : 'even';
Branch: 1 branch
BranchTrueFalseTotal
$i++ % 2 ? : 0 0 0
1957  
1958 0 local $args{'tr'}{'class'} = "field-$odd_even buttons";
1959 0 ▶ local $args{'td'}{'class'} = $args{'td'}{'class'} ? "$args{'td'}{'class'} label" : 'label';
Branch: 1 branch
BranchTrueFalseTotal
$args{'td'}{'class'} ? : 0 0 0
1960  
1961 0 local $args{'td'}{'colspan'} = 2;
1962  
1963 $html .= '<tr' . Rose::HTML::Util::html_attrs_string($args{'tr'}) . ">\n" .
1964 '<td' . Rose::HTML::Util::html_attrs_string($args{'td'}) . '>' .
1965 0 join(' ', map { $_->$xhtml_field() } @buttons) .
1966 "</td>\n</tr>\n";
1967 }
1968  
1969 5 $html .= "</table>\n\n" . join('', map { $_->$xhtml() } $self->post_children);
1970  
1971 5 ▶ $html .= "\n\n" unless($html =~ /\n\n\z/);
Branch: 1 branch
BranchTrueFalseTotal
unless $html =~ /\n\n\z/ 2 3 5
1972  
1973 5 return $self->$form_start() . "\n\n$html" . $self->$form_end();
1974 }
1975  
1976 0 ▶sub html_table { shift->_html_table(@_) }
Subroutine html_table: not called CC=1 SCAR=6.9
Pod undocumented
1977 5 ▶sub xhtml_table { shift->_html_table(@_, _xhtml => 1) }
Subroutine xhtml_table: called CC=1 SCAR=0.0
Pod undocumented
1978  
1979 sub app
1980 0 ▶{
Subroutine app: not called CC=2 SCAR=17.9
Pod documented
1981 0 my($self) = shift;
1982 0 ▶ Scalar::Util::weaken($self->{'app'} = shift) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
1983 0 return $self->{'app'};
1984 }
1985  
1986 sub app_form
1987 0 ▶{
Subroutine app_form: not called CC=2 SCAR=17.9
Pod undocumented
1988 0 my($self) = shift;
1989 0 ▶ Scalar::Util::weaken($self->{'app_form'} = shift) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
1990 0 return $self->{'app_form'};
1991 }
1992  
1993 8 our $AUTOLOAD;
1994  
1995 sub AUTOLOAD
1996 3 ▶{
Subroutine AUTOLOAD: called CC=8 SCAR=21.7
1997 3 my($self) = $_[0];
1998  
1999 3 ▶ my $class = ref($self) or croak "$self is not an object";
Branch: 1 branch
BranchTrueFalseTotal
my $class = ref $self or croak("$self is not an object") 3 0 3
2000  
2001 3 my $delegate = $class->delegate_to_subforms;
2002  
2003 3 ▶ unless($delegate)
Branch: 1 branch
BranchTrueFalseTotal
unless ($delegate) 0 3 3
2004 {
2005 0 goto &Rose::HTML::Object::AUTOLOAD;
2006 }
2007  
2008 3 my $method = $AUTOLOAD;
2009 3 $method =~ s/.*://;
2010  
2011 3 my $to_form;
2012  
2013 3 foreach my $form ($self->forms)
2014 {
2015 3 ▶ if($form->can($method))
Branch: 1 branch
BranchTrueFalseTotal
if ($form->can($method)) 2 1 3
2016 {
2017 2 $to_form = $form;
2018 2 last;
2019 }
2020 }
2021  
2022 3 ▶ unless($to_form)
Branch: 1 branch
BranchTrueFalseTotal
unless ($to_form) 1 2 3
2023 {
2024 1 $Rose::HTML::Object::AUTOLOAD = $AUTOLOAD;
2025 1 goto &Rose::HTML::Object::AUTOLOAD;
2026 }
2027  
2028 2 ▶ if($delegate eq 'compile')
Branch: 2 branches
BranchTrueFalseTotal
if ($delegate eq 'compile') { } 2 0 2
elsif ($delegate eq 'runtime') { } 0 0 0
2029 {
2030 2 my $form_name = $to_form->form_name;
2031  
2032 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2033 2 ▶ *$AUTOLOAD = sub { shift->form($form_name)->$method(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
2034 2 ${$class . '::__AUTODELEGATED'}{$method} = 1;
2035 2 goto &$AUTOLOAD;
2036 }
2037 elsif($delegate eq 'runtime')
2038 {
2039 0 $to_form->$method(@_);
2040 }
2041  
2042 0 $Rose::HTML::Object::AUTOLOAD = $AUTOLOAD;
2043 0 goto &Rose::HTML::Object::AUTOLOAD;
2044 }
2045  
2046 8 ▶if(__PACKAGE__->localizer->auto_load_messages)
Branch: 1 branch
BranchTrueFalseTotal
if (__PACKAGE__->localizer->auto_load_messages) 0 8 8
2047 {
2048 0 __PACKAGE__->localizer->load_all_messages;
2049 }
2050  
2051 8 ▶use utf8; # The __DATA__ section contains UTF-8 text
Subroutine BEGIN: called CC=1 SCAR=0.0
2052  
2053 8 1;
2054  
2055 __DATA__
« blib/lib/Rose/HTML/Object/MakeMethods/Generic.pm ↑ Summary blib/lib/Rose/HTML/Form/Field/Time/Minutes.pm »