blib/lib/HTML/Object/DOM/Element/Output.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 79 CC 4 SCAR 14.4
CC
4
Cov
0%
init
12.0
htmlFor
6.0
BEGIN
2.0
CRAP 4.2
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Output.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/23
7 ## Modified 2022/09/18
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTML::Object::DOM::Element::Output;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( HTML::Object::DOM::Element );
21 use vars qw( $VERSION );
22 use HTML::Object::DOM::Element::Shared qw( :output );
23 our $VERSION = 'v0.2.0';
24 };
25  
26 use strict;
27 use warnings;
28  
29 sub init
30 {
31 my $self = shift( @_ );
32 $self->{defaultvalue} = undef;
33 $self->{_init_strict_use_sub} = 1;
34 $self->SUPER::init( @_ ) || return( $self->pass_error );
35 $self->{tag} = 'output' if( !CORE::length( "$self->{tag}" ) );
36 $self->{type} = 'output';
37 $self->_set_get_internal_attribute_callback( 'for' => sub
38 {
39 my( $this, $val ) = @_;
40 my $list;
41 return if( !( $list = $this->{_for_list} ) );
42 # $list->debug( $self->debug );
43 $list->update( $val );
44 });
45 return( $self );
46 }
47  
48 # Note: method checkValidity inherited
49  
50 # Note: property defaultValue
51 sub defaultValue : lvalue { return( shift->_set_get_property( 'defaultvalue', @_ ) ); }
52  
53 # Note: property form read-only inherited
54  
55 # Note: property htmlFor read-only
56 sub htmlFor
57 {
58 my $self = shift( @_ );
59 unless( $self->{_for_list} )
60 {
61 my $for = $self->attr( 'for' );
62 require HTML::Object::TokenList;
63 $self->{_for_list} = HTML::Object::TokenList->new( $for, element => $self, attribute => 'for', debug => $self->debug ) ||
64 return( $self->pass_error( HTML::Object::TokenList->error ) );
65 }
66 return( $self->{_for_list} );
67 }
68  
69 # Note: property labels read-only inherited
70  
71 # Note: property name inherited
72  
73 # Note: method reportValidity inherited
74  
75 # Note: method setCustomValidity inherited
76  
77 # Note: property type read-only inherited
78  
79 # Note: property validationMessage read-only inherited
80  
81 # Note: property validity read-only inherited
82  
83 # Note: property value
84 {
85 no warnings 'redefine';
86 sub value : lvalue { return( shift->textContent( @_ ) ); }
87 }
88  
89 # Note: property willValidate read-only inherited
90  
91 1;
92 # NOTE: POD
93 __END__
94  
95 =encoding utf-8
96  
97 =head1 NAME
98  
99 HTML::Object::DOM::Element::Output - HTML Object DOM Output Class
100  
101 =head1 SYNOPSIS
102  
103 use HTML::Object::DOM::Element::Output;
104 my $output = HTML::Object::DOM::Element::Output->new ||
105 die( HTML::Object::DOM::Element::Output->error, "\n" );
106  
107 =head1 VERSION
108  
109 v0.2.0
110  
111 =head1 DESCRIPTION
112  
113 This interface provides properties and methods (beyond those inherited from L<HTML::Object::Element>) for manipulating the layout and presentation of C<<output>> elements.
114  
115 =head1 INHERITANCE
116  
117 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+
118 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Output |
119 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+
120  
121 =head1 PROPERTIES
122  
123 Inherits properties from its parent L<HTML::Object::DOM::Element>
124  
125 =head2 defaultValue
126  
127 A string representing the default value of the element, initially the empty string.
128  
129 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/defaultValue>
130  
131 =head2 form
132  
133 Read-only.
134  
135 An L<HTML::Object::DOM::Element::Form> indicating the form associated with the control, reflecting the form HTML attribute if it is defined.
136  
137 Example:
138  
139 <form
140 action="/action_page.php"
141 id="numform"
142 oninput="x.value=parseInt(a.value)+parseInt(b.value)">
143 <input type="range" id="a" name="a" value="50" />
144 + <input type="number" id="b" name="b" value="25" />
145 <input type="submit" />
146 </form>
147  
148 <output form="numform" id="x" name="x" for="a b"></output>
149  
150 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/form>
151  
152 =head2 htmlFor
153  
154 Read-only.
155  
156 A L<TokenList|HTML::Object::TokenList> reflecting the for HTML attribute, containing a list of IDs of other elements in the same document that contribute to (or otherwise affect) the calculated value.
157  
158 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/htmlFor>
159  
160 =head2 labels
161  
162 Read-only.
163  
164 Returns a L<HTML::Object::DOM::NodeList> of L<<label>|HTML::Object::DOM::Element::Label> elements associated with the element.
165  
166 Example:
167  
168 <label id="label1" for="test">Label 1</label>
169 <output id="test">Output</output>
170 <label id="label2" for="test">Label 2</label>
171  
172 use HTML::Object::DOM qw( window );
173 window->addEventListener( DOMContentLoaded => sub
174 {
175 my $output = $doc->getElementById( 'test' );
176 for( my $i = 0; $i < $output->labels->length; $i++ )
177 {
178 say( $output->labels->[$i]->textContent ); # "Label 1" and "Label 2"
179 }
180 });
181  
182 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/labels>
183  
184 =head2 name
185  
186 A string reflecting the name HTML attribute, containing the name for the control that is submitted with form data.
187  
188 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/name>
189  
190 =head2 type
191  
192 Normally this is read-only, but under perl you can set whatever string value you want. By default the value is C<output>.
193  
194 Under JavaScript, this is a read-only property that returns the string C<output>.
195  
196 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/type>
197  
198 =head2 validationMessage
199  
200 Read-only.
201  
202 A string representing a localized message that describes the validation constraints that the control does not satisfy (if any). This is the empty string if the control is not a candidate for constraint validation (willValidate is false), or it satisfies its constraints.
203  
204 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/validationMessage>
205  
206 =head2 validity
207  
208 Read-only.
209  
210 A C<ValidityState> representing the validity states that this element is in.
211  
212 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/validity>
213  
214 =head2 value
215  
216 A string representing the value of the contents of the elements. Behaves like the L<HTML::Object::DOM::Node/textContent> property.
217  
218 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/value>
219  
220 =head2 willValidate
221  
222 Read-only.
223  
224 A boolean value indicating whether the element is a candidate for constraint validation.
225  
226 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/willValidate>
227  
228 =head1 METHODS
229  
230 Inherits methods from its parent L<HTML::Object::DOM::Element>
231  
232 =head2 checkValidity
233  
234 Checks the validity of the element and returns a boolean value holding the check result.
235  
236 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/checkValidity>
237  
238 =head2 reportValidity
239  
240 This method reports the problems with the constraints on the element, if any, to the user. If there are problems, fires an invalid event at the element, and returns false; if there are no problems, it returns true.
241 When the problem is reported, the user agent may focus the element and change the scrolling position of the document or perform some other action that brings the element to the user's attention. User agents may report more than one constraint violation if this element suffers from multiple problems at once. If the element is not rendered, then the user agent may report the error for the running script instead of notifying the user.
242  
243 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/reportValidity>
244  
245 =head2 setCustomValidity
246  
247 Sets a custom validity message for the element. If this message is not the empty string, then the element is suffering from a custom validity error, and does not validate.
248  
249 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/setCustomValidity>
250  
251 =head1 AUTHOR
252  
253 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
254  
255 =head1 SEE ALSO
256  
257 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement>, L<Mozilla documentation on output element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/output>
258  
259 =head1 COPYRIGHT & LICENSE
260  
261 Copyright(c) 2021 DEGUEST Pte. Ltd.
262  
263 All rights reserved
264  
265 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
266  
267 =cut