line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Factory::Control::Role::BooleanValue; |
2
|
|
|
|
|
|
|
$Form::Factory::Control::Role::BooleanValue::VERSION = '0.022'; |
3
|
1
|
|
|
1
|
|
513
|
use Moose::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
excludes qw( |
6
|
|
|
|
|
|
|
Form::Factory::Control::Role::ListValue |
7
|
|
|
|
|
|
|
Form::Factory::Control::Role::ScalarValue |
8
|
|
|
|
|
|
|
); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: boolean valued controls |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has true_value => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
required => 1, |
16
|
|
|
|
|
|
|
default => 1, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has false_value => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
required => 1, |
23
|
|
|
|
|
|
|
default => '', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _is_it_true { |
28
|
6
|
|
|
6
|
|
12
|
my ($self, $value) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# blow off these warnings rather than test for them |
31
|
1
|
|
|
1
|
|
3789
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
243
|
|
32
|
|
|
|
|
|
|
|
33
|
6
|
100
|
|
|
|
206
|
return 1 if $value eq $self->true_value; |
34
|
2
|
50
|
|
|
|
65
|
return '' if $value eq $self->false_value; |
35
|
2
|
|
|
|
|
9
|
return scalar undef; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub is_currently_true { |
39
|
12
|
|
|
12
|
1
|
13
|
my $self = shift; |
40
|
|
|
|
|
|
|
|
41
|
12
|
50
|
|
|
|
27
|
if (@_) { |
42
|
0
|
|
|
|
|
0
|
my $is_true = shift; |
43
|
0
|
0
|
|
|
|
0
|
$self->current_value($is_true ? $self->true_value : $self->false_value); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
12
|
100
|
|
|
|
498
|
return $self->_is_it_true($self->value) if $self->has_value; |
47
|
7
|
50
|
|
|
|
260
|
return $self->_is_it_true($self->default_value) if $self->has_default_value; |
48
|
7
|
|
|
|
|
12
|
return scalar undef; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub is_true { |
53
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
54
|
1
|
|
|
|
|
40
|
return $self->_is_it_true($self->value); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
around current_value => sub { |
59
|
|
|
|
|
|
|
my $next = shift; |
60
|
|
|
|
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
my $truth = $self->is_currently_true; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->value(@_) if @_; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
if ($truth) { |
66
|
|
|
|
|
|
|
return $self->true_value; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif (defined $truth) { |
69
|
|
|
|
|
|
|
return $self->false_value; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
|
|
|
|
|
|
return scalar undef; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
around has_current_value => sub { |
78
|
|
|
|
|
|
|
my $next = shift; |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
return defined $self->is_currently_true; |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=pod |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=encoding UTF-8 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 NAME |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Form::Factory::Control::Role::BooleanValue - boolean valued controls |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 VERSION |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
version 0.022 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 DESCRIPTION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Controls that implement this role have a boolean value. This say much about how that is actually implemented, just that is has a L</true_value> a L</false_value> and then a flag stating whether the true value or false value is currently selected. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 true_value |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
The string value the control should have when the control L</is_true>. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 false_value |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
The string value the control should have when the control is not L</is_true>. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 METHODS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 is_currently_true |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Returns a true value when the C<current_value> is set to L</true_value> or a false value when the C<current_value> is set to L</false_value>. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This method returns C<undef> if it is neither true nor false. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
If passed a value, e.g.: |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$self->is_currently_true(1); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This will set the C<current_value>. If a true value is given, the C<value> will be set to L</true_value>. Otherwise, it will cause the C<current_value> to take on the contents of L</false_value>. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 is_true |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Returns a true value when the C<value> is set to L</true_value> or a false value when the C<value> is set to L</false_value>. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
This method returns C<undef> if it is neither true nor false. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Unlikely L</is_currently_true>, this may not be used as a setter. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 current_value |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
We need to handle current value special. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 has_current_value |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
If the value is true or false, it has a current value. Otherwise, it does not. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 AUTHOR |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp <hanenkamp@cpan.org> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Qubling Software LLC. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
152
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |