line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Element::Checkbox; |
2
|
|
|
|
|
|
|
|
3
|
24
|
|
|
24
|
|
5282
|
use strict; |
|
24
|
|
|
|
|
31
|
|
|
24
|
|
|
|
|
979
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
24
|
|
|
24
|
|
88
|
use Moose; |
|
24
|
|
|
|
|
28
|
|
|
24
|
|
|
|
|
121
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'HTML::FormFu::Element'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'HTML::FormFu::Role::Element::Input'; |
11
|
|
|
|
|
|
|
|
12
|
24
|
|
|
24
|
|
104433
|
use HTML::FormFu::Constants qw( $EMPTY_STR ); |
|
24
|
|
|
|
|
38
|
|
|
24
|
|
|
|
|
8409
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->mk_output_accessors(qw( default )); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
after BUILD => sub { |
17
|
|
|
|
|
|
|
my ( $self, $args ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$self->field_type('checkbox'); |
20
|
|
|
|
|
|
|
$self->value(1); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$self->multi_layout( [ |
23
|
|
|
|
|
|
|
'field', |
24
|
|
|
|
|
|
|
'label', |
25
|
|
|
|
|
|
|
] ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return; |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub process_value { |
31
|
104
|
|
|
104
|
|
139
|
my ( $self, $input ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# ignore submitted input |
34
|
|
|
|
|
|
|
|
35
|
104
|
|
|
|
|
251
|
return $self->value; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub prepare_attrs { |
39
|
104
|
|
|
104
|
|
142
|
my ( $self, $render ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
104
|
|
|
|
|
258
|
my $form = $self->form; |
42
|
104
|
|
|
|
|
2183
|
my $submitted = $form->submitted; |
43
|
104
|
|
|
|
|
299
|
my $default = $self->default; |
44
|
104
|
|
|
|
|
231
|
my $original = $self->value; |
45
|
|
|
|
|
|
|
|
46
|
104
|
50
|
|
|
|
226
|
my $value |
47
|
|
|
|
|
|
|
= defined $self->name |
48
|
|
|
|
|
|
|
? $self->get_nested_hash_value( $form->input, $self->nested_name ) |
49
|
|
|
|
|
|
|
: undef; |
50
|
|
|
|
|
|
|
|
51
|
104
|
100
|
100
|
|
|
367
|
if (defined $value and ref $value eq 'ARRAY') { |
52
|
2
|
50
|
|
|
|
3
|
$value = $original if grep { $_ eq $original } @$value; |
|
4
|
|
|
|
|
10
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
104
|
100
|
100
|
|
|
1990
|
if ( $submitted |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
56
|
|
|
|
|
|
|
&& defined $value |
57
|
|
|
|
|
|
|
&& defined $original |
58
|
|
|
|
|
|
|
&& $value eq $original ) |
59
|
|
|
|
|
|
|
{ |
60
|
23
|
|
|
|
|
93
|
$render->{attributes}{checked} = 'checked'; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
elsif ($submitted |
63
|
|
|
|
|
|
|
&& $self->retain_default |
64
|
|
|
|
|
|
|
&& ( !defined $value || $value eq $EMPTY_STR ) ) |
65
|
|
|
|
|
|
|
{ |
66
|
8
|
|
|
|
|
55
|
$render->{attributes}{checked} = 'checked'; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif ($submitted) { |
69
|
34
|
|
|
|
|
58
|
delete $render->{attributes}{checked}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
elsif ( defined $default && defined $original && $default eq $original ) { |
72
|
11
|
|
|
|
|
25
|
$render->{attributes}{checked} = 'checked'; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
104
|
|
|
|
|
362
|
$self->SUPER::prepare_attrs($render); |
76
|
|
|
|
|
|
|
|
77
|
104
|
|
|
|
|
159
|
return; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 NAME |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
HTML::FormFu::Element::Checkbox - Checkbox form field |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 VERSION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
version 2.05 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SYNOPSIS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $e = $form->element( Checkbox => 'foo' ); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 DESCRIPTION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Checkbox form field. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 METHODS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 value |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Default Value: 1 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 default_empty_value |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Inherited. See L<HTML::FormFu::Role::Element::Field/default_empty_value> for details. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 multi_layout |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Overrides the default value of |
115
|
|
|
|
|
|
|
L<multi_layout|HTML::FormFu::Role::Element::Field/multi_layout> |
116
|
|
|
|
|
|
|
to swap the C<field> and C<label> around. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SEE ALSO |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from |
121
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Element::Input>, |
122
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Element::Field>, |
123
|
|
|
|
|
|
|
L<HTML::FormFu::Element> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L<HTML::FormFu> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AUTHOR |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Carl Franks, C<cfranks@cpan.org> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 LICENSE |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
134
|
|
|
|
|
|
|
the same terms as Perl itself. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |