File Coverage

blib/lib/Rose/HTML/Form/Field/RadioButton.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition 4 8 50.0
subroutine 6 6 100.0
pod 4 4 100.0
total 30 34 88.2


line stmt bran cond sub pod time code
1              
2             use strict;
3 7     7   182107  
  7         27  
  7         191  
4             use base 'Rose::HTML::Form::Field::OnOff::Checkable';
5 7     7   30  
  7         11  
  7         2509  
6             our $VERSION = '0.606';
7              
8             __PACKAGE__->delete_valid_html_attrs(qw(ismap usemap alt src));
9             __PACKAGE__->required_html_attr_value(type => 'radio');
10              
11             {
12             my($self) = shift;
13             $self->html_attr(checked => $self->checked);
14 120     120 1 664 return $self->SUPER::html_field(@_);
15 120         303 }
16 120         310  
17             {
18             my($self) = shift;
19             $self->html_attr(checked => $self->checked);
20             return $self->SUPER::xhtml_field(@_);
21 75     75 1 472 }
22 75         193  
23 75         209 {
24             my($self) = shift;
25              
26             return ($self->html_prefix || '') .
27             $self->html_radio_button . ' ' . $self->html_label .
28 120     120 1 671 ($self->html_suffix || '');
29             }
30 120   50     241  
      50        
31             {
32             my($self) = shift;
33             return ($self->html_prefix || '') .
34             $self->xhtml_radio_button . ' ' . $self->html_label .
35             ($self->html_suffix || '');
36             }
37 75     75 1 130  
38 75   50     153 1;
      50        
39              
40              
41             =head1 NAME
42              
43             Rose::HTML::Form::Field::RadioButton - Object representation of a single radio button field in an HTML form.
44              
45             =head1 SYNOPSIS
46              
47             $field =
48             Rose::HTML::Form::Field::RadioButton->new(
49             label => 'Run tests',
50             name => 'tests',
51             value => 'yes');
52              
53             $checked = $field->is_checked; # false
54              
55             $field->checked(1);
56              
57             print $field->html;
58              
59             ...
60              
61             =head1 DESCRIPTION
62              
63             L<Rose::HTML::Form::Field::RadioButton> is an object representation of a single radio button field in an HTML form.
64              
65             This class inherits from, and follows the conventions of, L<Rose::HTML::Form::Field>. Inherited methods that are not overridden will not be documented a second time here. See the L<Rose::HTML::Form::Field> documentation for more information.
66              
67             =head1 HTML ATTRIBUTES
68              
69             Valid attributes:
70              
71             accept
72             accesskey
73             checked
74             class
75             dir
76             disabled
77             id
78             lang
79             maxlength
80             name
81             onblur
82             onchange
83             onclick
84             ondblclick
85             onfocus
86             onkeydown
87             onkeypress
88             onkeyup
89             onmousedown
90             onmousemove
91             onmouseout
92             onmouseover
93             onmouseup
94             onselect
95             readonly
96             size
97             style
98             tabindex
99             title
100             type
101             value
102             xml:lang
103              
104             Required attributes (default values in parentheses):
105              
106             type (radio)
107             value
108              
109             Boolean attributes:
110              
111             checked
112             disabled
113             readonly
114              
115             =head1 CONSTRUCTOR
116              
117             =over 4
118              
119             =item B<new PARAMS>
120              
121             Constructs a new L<Rose::HTML::Form::Field::RadioButton> object based on PARAMS, where PARAMS are name/value pairs. Any object method is a valid parameter name.
122              
123             =back
124              
125             =head1 OBJECT METHODS
126              
127             =over 4
128              
129             =item B<checked [BOOL]>
130              
131             Check or uncheck the radio button by passing a boolean value. If BOOL is true, the radio button will be checked. If it is false, it will be unchecked. Returns true if the radio button is checked, false otherwise.
132              
133             =item B<hidden [BOOL]>
134              
135             Get or set a boolean value that indicates whether or not this radio button will be shown in its parent L<radio button group|Rose::HTML::Form::Field::RadioButtonGroup>. Setting it to true also sets L<checked|/checked> to false.
136              
137             =item B<hide>
138              
139             Calls L<hidden|/hidden>, passing a true value.
140              
141             =item B<html_radio_button>
142              
143             Returns the HTML serialization of the radio button field only (i.e., without any label or error message)
144              
145             =item B<is_checked>
146              
147             Returns true if the radio button is checked, false otherwise.
148              
149             =item B<is_on>
150              
151             Simply calls L<is_checked()|/is_checked>. This method exists for API uniformity between radio buttons and checkboxes.
152              
153             =item B<show>
154              
155             Calls L<hidden|/hidden>, passing a false value.
156              
157             =item B<value [VALUE]>
158              
159             Gets or sets the value of the "value" HTML attribute.
160              
161             =item B<xhtml_radio_button>
162              
163             Returns the XHTML serialization of the radio button field only (i.e., without any label or error message)
164              
165             =back
166              
167             =head1 AUTHOR
168              
169             John C. Siracusa (siracusa@gmail.com)
170              
171             =head1 LICENSE
172              
173             Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.