FormHandler/Field/Checkbox.pm

filter: Statementstmt 100% 19 / 19 Branchbran 100% 2 / 2 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 100% 30 / 30 CC 3 SCAR 7.9
CC
3
Cov
100%
validate
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
« FormHandler/Field/DateTime.pm ↑ Summary FormHandler/Field/PasswordConf.pm »
1 package HTML::FormHandler::Field::Checkbox;
2 # ABSTRACT: a checkbox field type
3 25 $HTML::FormHandler::Field::Checkbox::VERSION = '0.410000';
4 25 ▶use HTML::FormHandler::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 extends 'HTML::FormHandler::Field';
6  
7  
8 25 has '+widget' => ( default => 'Checkbox' );
9 25 has 'checkbox_value' => ( is => 'rw', default => 1 );
10 25 has '+input_without_param' => ( default => 0 );
11 25 has '+type_attr' => ( default => 'checkbox' );
12 25 has 'option_label' => ( is => 'rw' );
13 25 has 'option_wrapper' => ( is => 'rw' );
14  
15 sub validate {
16 50 ▶ my $self = shift;
Subroutine validate: called CC=3 SCAR=11.0
Pod documented
17 50 ▶ $self->add_error($self->get_message('required'), $self->loc_label) if( $self->required && !$self->value );
Branch: 1 branch
BranchTrueFalseTotal
if $self->required and not $self->value 2 48 50
Condition100%3/3
$self->required and not $self->value
!ll&&!rl&&r
4082
MC/DC100%2/2
$self->required and not $self->value
$self->required not $self->value
Truth table100%3/3
A and not(B)
A= $self->requiredB= not $self->value
ABresult
0X0
100
111
18 50 return;
19 }
20  
21 25 __PACKAGE__->meta->make_immutable;
22 25 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 25 1;
24  
25 __END__
26  
27 =pod
28  
29 =encoding UTF-8
30  
31 =head1 NAME
32  
33 HTML::FormHandler::Field::Checkbox - a checkbox field type
34  
35 =head1 VERSION
36  
37 version 0.410000
38  
39 =head1 DESCRIPTION
40  
41 This field is very similar to the Boolean Widget except that this
42 field allows other positive values besides 1. Since unselected
43 checkboxes do not return a parameter, fields with Checkbox type
44 will always be set to the 'input_without_param' default if they
45 do not appear in the form.
46  
47 =head2 widget
48  
49 checkbox
50  
51 =head2 checkbox_value
52  
53 In order to create the HTML for a checkbox, there must be a 'value="xx"'.
54 This value is specified with the 'checkbox_value' attribute, which
55 defaults to 1.
56  
57 =head2 input_without_param
58  
59 If the checkbox is not checked, it will be set to the value
60 of this attribute (the unchecked value). Default = 0. Because
61 unchecked checkboxes do not return anything in the HTTP parameters,
62 the absence of a checkbox key in the parameters hash forces this
63 field to this value. This means that Checkbox fields, unlike other
64 fields, will not be ignored if there is no input. If a particular
65 checkbox should not be processed for a particular form, you must
66 set 'inactive' to 1 instead.
67  
68 Note that a checkbox is only 'checked' when the 'checkbox_value' is
69 provided. The 'value' for a non-checked checkbox is only really
70 useful for creating form values such as are stored in a database.
71  
72 =head1 AUTHOR
73  
74 FormHandler Contributors - see HTML::FormHandler
75  
76 =head1 COPYRIGHT AND LICENSE
77  
78 This software is copyright (c) 2017 by Gerda Shank.
79  
80 This is free software; you can redistribute it and/or modify it under
81 the same terms as the Perl 5 programming language system itself.
82  
83 =cut
« FormHandler/Field/DateTime.pm ↑ Summary FormHandler/Field/PasswordConf.pm »