File Coverage

blib/lib/Rose/HTML/Form/Field/OnOff/Checkable.pm
Criterion Covered Total %
statement 31 32 96.8
branch 19 20 95.0
condition 1 3 33.3
subroutine 9 9 100.0
pod 3 7 42.8
total 63 71 88.7


line stmt bran cond sub pod time code
1             package Rose::HTML::Form::Field::OnOff::Checkable;
2              
3 9     9   71 use strict;
  9         25  
  9         284  
4              
5 9     9   46 use base 'Rose::HTML::Form::Field::OnOff';
  9         19  
  9         4764  
6              
7             our $VERSION = '0.606';
8              
9             __PACKAGE__->add_required_html_attrs(
10             {
11             value => 'on',
12             });
13              
14             sub checked
15             {
16 1204     1204 0 1908 my($self) = shift;
17              
18 1204 100       2574 if(@_)
19             {
20 555         1450 $self->is_cleared(0);
21              
22 555 100       3085 $self->{'checked'} =
    100          
23             $self->html_attr(checked => $_[0] ? 1 : (defined $_[0] ? 0 : undef));
24              
25 555 50 33     1367 if((my $parent = $self->parent_field) && $self->auto_invalidate_parent)
26             {
27 0         0 $parent->invalidate_value;
28             }
29              
30 555         1192 return $self->{'checked'};
31             }
32              
33 649 100       1537 return 0 if($self->is_cleared);
34 556 100       4487 return defined $self->{'checked'} ? $self->{'checked'} : $self->default_value;
35             }
36              
37             *input_value = \&checked;
38              
39 259 100   259 0 509 sub is_checked { shift->checked ? 1 : 0 }
40              
41 259     259 0 530 sub is_on { shift->is_checked }
42              
43 143     143 1 1515 sub value { shift->html_attr('value', @_) }
44              
45             sub clear
46             {
47 380     380 1 601 my($self) = shift;
48              
49 380         946 $self->checked(0);
50 380         1122 $self->error(undef);
51 380         864 $self->is_cleared(1);
52             }
53              
54             sub reset
55             {
56 42     42 1 74 my($self) = shift;
57              
58 42         111 $self->checked(undef);
59 42         156 $self->error(undef);
60 42         151 $self->is_cleared(0);
61 42         183 return 1;
62             }
63              
64             sub hidden
65             {
66 387     387 0 676 my($self) = shift;
67              
68 387 100       747 if(@_)
69             {
70 32 100       132 if($self->{'_hidden'} = shift(@_) ? 1 : 0)
    100          
71             {
72 16         38 $self->checked(undef);
73             }
74             }
75              
76 387         1113 return $self->{'_hidden'};
77             }
78              
79             1;