line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Widget::Element::Radio; |
2
|
|
|
|
|
|
|
|
3
|
88
|
|
|
88
|
|
80643
|
use warnings; |
|
88
|
|
|
|
|
197
|
|
|
88
|
|
|
|
|
2857
|
|
4
|
88
|
|
|
88
|
|
484
|
use strict; |
|
88
|
|
|
|
|
187
|
|
|
88
|
|
|
|
|
2899
|
|
5
|
88
|
|
|
88
|
|
591
|
use base 'HTML::Widget::Element'; |
|
88
|
|
|
|
|
200
|
|
|
88
|
|
|
|
|
7962
|
|
6
|
88
|
|
|
88
|
|
514
|
use NEXT; |
|
88
|
|
|
|
|
203
|
|
|
88
|
|
|
|
|
582
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/comment checked label value retain_default/); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
HTML::Widget::Element::Radio - Radio Element |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $e = $widget->element( 'Radio', 'foo' ); |
17
|
|
|
|
|
|
|
$e->comment('(Required)'); |
18
|
|
|
|
|
|
|
$e->label('Foo'); |
19
|
|
|
|
|
|
|
$e->checked('checked'); |
20
|
|
|
|
|
|
|
$e->value('bar'); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Radio Element. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 METHODS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 retain_default |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
If true, overrides the default behaviour, so that after a field is missing |
31
|
|
|
|
|
|
|
from the form submission, the xml output will contain the default value, |
32
|
|
|
|
|
|
|
rather than be empty. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 new |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
14
|
|
|
14
|
1
|
95
|
shift->NEXT::new(@_)->value(1); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 containerize |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub containerize { |
47
|
24
|
|
|
24
|
1
|
47
|
my ( $self, $w, $value, $errors, $args ) = @_; |
48
|
|
|
|
|
|
|
|
49
|
24
|
50
|
|
|
|
61
|
$value = ref $value eq 'ARRAY' ? shift @$value : $value; |
50
|
|
|
|
|
|
|
|
51
|
24
|
|
|
|
|
70
|
my $name = $self->name; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Search for multiple radio button with the same name |
54
|
24
|
|
|
|
|
126
|
my $multi = 0; |
55
|
24
|
|
|
|
|
78
|
my @elements = $w->find_elements( name => $name ); |
56
|
|
|
|
|
|
|
|
57
|
24
|
|
|
|
|
64
|
for my $element (@elements) { |
58
|
54
|
100
|
|
|
|
175
|
next if $element eq $self; |
59
|
30
|
50
|
|
|
|
135
|
if ( $element->isa('HTML::Widget::Element::Radio') ) { |
60
|
30
|
|
|
|
|
59
|
$multi++; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Generate unique id |
65
|
24
|
100
|
|
|
|
63
|
if ($multi) { |
66
|
21
|
|
100
|
|
|
77
|
$w->{_stash} ||= {}; |
67
|
21
|
|
100
|
|
|
86
|
$w->{_stash}->{radio} ||= {}; |
68
|
21
|
|
|
|
|
58
|
my $num = ++$w->{_stash}->{radio}->{$name}; |
69
|
21
|
|
|
|
|
126
|
my $id = $self->id( $w, "$name\_$num" ); |
70
|
21
|
|
66
|
|
|
86
|
$self->attributes->{id} ||= $id; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
24
|
100
|
66
|
|
|
97
|
my $checked = |
|
|
100
|
|
|
|
|
|
74
|
|
|
|
|
|
|
defined $value |
75
|
|
|
|
|
|
|
? ( defined $value && $value eq $self->value ) |
76
|
|
|
|
|
|
|
? 'checked' |
77
|
|
|
|
|
|
|
: undef |
78
|
|
|
|
|
|
|
: undef; |
79
|
|
|
|
|
|
|
|
80
|
24
|
100
|
100
|
|
|
155
|
if ( !defined $value |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
81
|
|
|
|
|
|
|
&& ( $self->retain_default || !$args->{submitted} ) |
82
|
|
|
|
|
|
|
&& $self->checked ) |
83
|
|
|
|
|
|
|
{ |
84
|
5
|
|
|
|
|
94
|
$checked = 'checked'; |
85
|
|
|
|
|
|
|
} |
86
|
24
|
|
|
|
|
178
|
$value = $self->value; |
87
|
|
|
|
|
|
|
|
88
|
24
|
|
|
|
|
146
|
my $l = $self->mk_label( $w, $self->label, $self->comment, $errors ); |
89
|
24
|
|
|
|
|
158
|
my $i = $self->mk_input( $w, |
90
|
|
|
|
|
|
|
{ checked => $checked, type => 'radio', value => $value }, $errors ); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#$l ? ( $l->unshift_content($i) ) : ( $l = $i ); |
93
|
24
|
|
|
|
|
122
|
my $e = $self->mk_error( $w, $errors ); |
94
|
|
|
|
|
|
|
|
95
|
24
|
|
|
|
|
130
|
return $self->container( { element => $i, error => $e, label => $l } ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SEE ALSO |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Sebastian Riedel, C |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 LICENSE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
109
|
|
|
|
|
|
|
the same terms as Perl itself. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |