| 1 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Element::Checkbox; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 24 | $HTML::FormFu::Element::Checkbox::VERSION = '2.06'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Checkbox form field | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 24 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 24 | extends 'HTML::FormFu::Element'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 24 | with 'HTML::FormFu::Role::Element::Input'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 24 | ▶ | use HTML::FormFu::Constants qw( $EMPTY_STR ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 24 | __PACKAGE__->mk_output_accessors(qw( default )); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | after BUILD => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 96 | ▶ | my ( $self, $args ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 96 | $self->field_type('checkbox'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 96 | $self->value(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 96 | $self->multi_layout( [ 'field', 'label', ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 96 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 24 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | sub process_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 104 | ▶ | my ( $self, $input ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # ignore submitted input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 104 | return $self->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | sub prepare_attrs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 104 | ▶ | my ( $self, $render ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_attrs: called CC=17 SCAR=28.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 104 | my $form = $self->form; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 104 | my $submitted = $form->submitted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 104 | my $default = $self->default; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 104 | my $original = $self->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 104 | ▶ | my $value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | = defined $self->name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ? $self->get_nested_hash_value( $form->input, $self->nested_name ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 104 | ▶ | if ( defined $value and ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value and ref $value eq "ARRAY"
MC/DC100%2/2
defined $value and ref $value eq "ARRAY"
defined $value
ref $value eq "ARRAY"
Truth table100%3/3
A and B
A= defined $valueB= ref $value eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | ▶ | $value = $original if grep { $_ eq $original } @$value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 104 | ▶ | if ( $submitted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition88%8/9
$submitted and defined $value and defined $original and $value eq $original
$submitted and defined $value and defined $original
$submitted and defined $value
MC/DC75%3/4
$submitted and defined $value and defined $original and $value eq $original
$submitted
defined $value
defined $original
$value eq $original
Truth table80%4/5
A and B and C and D
A= $submittedB= defined $valueC= defined $originalD= $value eq $original
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | && defined $value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | && defined $original | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | && $value eq $original ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 23 | $render->{attributes}{checked} = 'checked'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ▶ | elsif ($submitted | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition77%7/9
$submitted and $self->retain_default and !defined($value) || $value eq $HTML::FormFu::Element::Checkbox::EMPTY_STR
$submitted and $self->retain_default
not defined $value or $value eq $HTML::FormFu::Element::Checkbox::EMPTY_STR
MC/DC50%2/4
$submitted and $self->retain_default and !defined($value) || $value eq $HTML::FormFu::Element::Checkbox::EMPTY_STR
$submitted
$self->retain_default
not defined $value
$value eq $HTML::FormFu::Element::Checkbox::EMPTY_STR
Truth table80%4/5
A and B and not(C) or D
A= $submittedB= $self->retain_defaultC= not defined $valueD= $value eq $HTML::FormFu::Element::Checkbox::EMPTY_STR
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | && $self->retain_default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | && ( !defined $value || $value eq $EMPTY_STR ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 8 | $render->{attributes}{checked} = 'checked'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | elsif ($submitted) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 34 | delete $render->{attributes}{checked}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ▶ | elsif ( defined $default && defined $original && $default eq $original ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
defined $default and defined $original and $default eq $original
defined $default and defined $original
MC/DC66%2/3
defined $default and defined $original and $default eq $original
defined $default
defined $original
$default eq $original
Truth table75%3/4
A and B and C
A= defined $defaultB= defined $originalC= $default eq $original
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 11 | $render->{attributes}{checked} = 'checked'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 104 | $self->SUPER::prepare_attrs($render); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 104 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 24 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | HTML::FormFu::Element::Checkbox - Checkbox form field | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | version 2.06 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | my $e = $form->element( Checkbox => 'foo' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | Checkbox form field. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | =head2 value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | Default Value: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | =head2 default_empty_value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | Inherited. See L<HTML::FormFu::Role::Element::Field/default_empty_value> for details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | =head2 multi_layout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | Overrides the default value of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | L<multi_layout|HTML::FormFu::Role::Element::Field/multi_layout> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | to swap the C<field> and C<label> around. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | Is a sub-class of, and inherits methods from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | L<HTML::FormFu::Role::Element::Input>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | L<HTML::FormFu::Role::Element::Field>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | L<HTML::FormFu::Element> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | L<HTML::FormFu> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | Carl Franks, C<cfranks@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | This library is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | Carl Franks <cpan@fireartist.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | This software is copyright (c) 2018 by Carl Franks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||