File Coverage

blib/lib/Rose/HTML/Form/Field/Option.pm
Criterion Covered Total %
statement 30 30 100.0
branch 4 4 100.0
condition 2 3 66.6
subroutine 13 13 100.0
pod 7 9 77.7
total 56 59 94.9


line stmt bran cond sub pod time code
1              
2             use strict;
3 12     12   170528  
  12         38  
  12         330  
4             use Rose::HTML::Util();
5 12     12   696 use Rose::HTML::Text;
  12         24  
  12         183  
6 12     12   729  
  12         21  
  12         87  
7             use base qw(Rose::HTML::Object::WithWrapAroundChildren
8 12         5246 Rose::HTML::Form::Field::OnOff::Selectable);
9 12     12   65  
  12         22  
10             our $VERSION = '0.606';
11              
12             __PACKAGE__->add_valid_html_attrs
13             (
14             'label',
15             'selected',
16             );
17              
18             __PACKAGE__->add_boolean_html_attrs
19             (
20             'selected',
21             );
22              
23             __PACKAGE__->delete_valid_html_attrs(qw(name type checked));
24             __PACKAGE__->delete_required_html_attr('type');
25              
26              
27 1484     1484 1 4621 {
28 292     292 1 1064 my($self) = shift;
29             $self->html_attr(selected => $self->selected);
30             return $self->html_tag(@_);
31             }
32 445     445 1 1293  
33 445         931 {
34 445         1101 my($self) = shift;
35             $self->html_attr(selected => $self->selected);
36             return $self->xhtml_tag(@_);
37             }
38              
39 145     145 1 217  
40 145         297 {
41 145         393 my($self) = shift;
42             $self->label_text_object->text(@_) if(@_);
43             return $self->SUPER::label(@_);
44 1184     1184 0 1919 }
45              
46             {
47             my($self) = shift;
48 391     391 1 709 return $self->{'label_text_object'} ||=
49 391 100       841 ref($self)->object_type_class_loaded('literal text')->new(text => $self->label);
50 391         1110 }
51              
52              
53             {
54             my($self) = shift;
55 1397     1397 0 1886 $self->local_name(shift) if(@_);
56 1397   66     3772 return $self->fq_name;
57             }
58              
59             1;
60 7     7 1 20  
61              
62             =head1 NAME
63              
64 888     888 1 1234 Rose::HTML::Form::Field::Option - Object representation of the "option" HTML tag.
65 888 100       2373  
66 888         1749 =head1 SYNOPSIS
67              
68             $field =
69             Rose::HTML::Form::Field::Option->new(
70             value => 'apple',
71             label => 'Apple');
72              
73             $field->selected(1);
74              
75             print $field->html;
76              
77             ...
78              
79             =head1 DESCRIPTION
80              
81             L<Rose::HTML::Form::Field::Option> is an object representation of a single option in a pop-up menu or select box in an HTML form.
82              
83             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.
84              
85             =head1 HTML ATTRIBUTES
86              
87             Valid attributes:
88              
89             accept
90             accesskey
91             alt
92             checked
93             class
94             dir
95             disabled
96             id
97             ismap
98             label
99             lang
100             maxlength
101             name
102             onblur
103             onchange
104             onclick
105             ondblclick
106             onfocus
107             onkeydown
108             onkeypress
109             onkeyup
110             onmousedown
111             onmousemove
112             onmouseout
113             onmouseover
114             onmouseup
115             onselect
116             readonly
117             selected
118             size
119             src
120             style
121             tabindex
122             title
123             type
124             usemap
125             value
126             xml:lang
127              
128             Required attributes:
129              
130             value
131              
132             Boolean attributes:
133              
134             checked
135             disabled
136             ismap
137             readonly
138             selected
139              
140             =head1 CONSTRUCTOR
141              
142             =over 4
143              
144             =item B<new PARAMS>
145              
146             Constructs a new L<Rose::HTML::Form::Field::Option> object based on PARAMS, where PARAMS are name/value pairs. Any object method is a valid parameter name.
147              
148             =back
149              
150             =head1 OBJECT METHODS
151              
152             =over 4
153              
154             =item B<hidden [BOOL]>
155              
156             Get or set a boolean value that indicates whether or not this radio button will be shown in its parent L<select box|Rose::HTML::Form::Field::SelectBox>, L<pop-up menu|Rose::HTML::Form::Field::PopUpMenu>, or L<option group|Rose::HTML::Form::Field::OptionGroup>. Setting it to true also sets L<selected|/selected> to false.
157              
158             =item B<hide>
159              
160             Calls L<hidden|/hidden>, passing a true value.
161              
162             =item B<selected [BOOL]>
163              
164             Select or unselect the option by passing a boolean value. If BOOL is true, the option will be selected. If it's false, it will be unselected. Returns true if the option is selected, false otherwise.
165              
166             =item B<short_label [TEXT]>
167              
168             Get or set the value of the "label" HTML attribute. When present, user agents are supposed to use this value instead of the contents of the option tag as the label for the option. Example:
169              
170             $field =
171             Rose::HTML::Form::Field::Option->new(
172             value => 'apple',
173             label => 'Shiny Apple');
174              
175             print $field->html;
176              
177             # The HTML:
178             #
179             # <option value="apple">Shiny Apple</option>
180             #
181             # Label shown in web browser: "Shiny Apple"
182              
183             $field->short_label("Apple");
184             print $field->html;
185              
186             # The HTML:
187             #
188             # <option label="Apple" value="apple">Shiny Apple</option>
189             #
190             # Label shown in web browser: "Apple"
191              
192             (Hey, don't look at me, I didn't write the HTML specs...)
193              
194             =item B<show>
195              
196             Calls L<hidden|/hidden>, passing a false value.
197              
198             =back
199              
200             =head1 AUTHOR
201              
202             John C. Siracusa (siracusa@gmail.com)
203              
204             =head1 LICENSE
205              
206             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.