blib/lib/HTML/Object/DOM/ValidityState.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 70 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
init
2.0
badInput
2.0
CRAP 2.0
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/ValidityState.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::ValidityState;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( Module::Generic );
21 use vars qw( $VERSION );
22 our $VERSION = 'v0.2.0';
23 };
24  
25 use strict;
26 use warnings;
27  
28 sub init
29 {
30 my $self = shift( @_ );
31 $self->{_init_strict_use_sub} = 1;
32 $self->SUPER::init( @_ ) || return( $self->pass_error );
33 return( $self );
34 }
35  
36 # Note: property
37 sub badInput : lvalue { return( shift->_set_get_boolean( 'badinput', @_ ) ); }
38  
39 # Note: property
40 sub customError : lvalue { return( shift->_set_get_boolean( 'customerror', @_ ) ); }
41  
42 # Note: property
43 sub patternMismatch : lvalue { return( shift->_set_get_boolean( 'patternmismatch', @_ ) ); }
44  
45 # Note: property
46 sub rangeOverflow : lvalue { return( shift->_set_get_boolean( 'rangeoverflow', @_ ) ); }
47  
48 # Note: property
49 sub rangeUnderflow : lvalue { return( shift->_set_get_boolean( 'rangeunderflow', @_ ) ); }
50  
51 # Note: property
52 sub stepMismatch : lvalue { return( shift->_set_get_boolean( 'stepmismatch', @_ ) ); }
53  
54 # Note: property
55 sub tooLong : lvalue { return( shift->_set_get_boolean( 'toolong', @_ ) ); }
56  
57 # Note: property
58 sub tooShort : lvalue { return( shift->_set_get_boolean( 'tooshort', @_ ) ); }
59  
60 # Note: property
61 sub typeMismatch : lvalue { return( shift->_set_get_boolean( 'typemismatch', @_ ) ); }
62  
63 # Note: property
64 sub valid : lvalue { return( shift->_set_get_boolean( 'valid', @_ ) ); }
65  
66 # Note: property
67 sub valueMissing : lvalue { return( shift->_set_get_boolean( 'valuemissing', @_ ) ); }
68  
69 1;
70 # NOTE: POD
71 __END__
72  
73 =encoding utf-8
74  
75 =head1 NAME
76  
77 HTML::Object::DOM::ValidityState - HTML Object DOM Valid State Class
78  
79 =head1 SYNOPSIS
80  
81 use HTML::Object::DOM::ValidityState;
82 my $validity = HTML::Object::DOM::ValidityState->new ||
83 die( HTML::Object::DOM::ValidityState->error, "\n" );
84  
85 =head1 VERSION
86  
87 v0.2.0
88  
89 =head1 DESCRIPTION
90  
91 The C<ValidityState> interface represents the validity states that an element can be in, with respect to constraint validation. Together, they help explain why an element's value fails to validate, if it is not valid.
92  
93 This is used only so that some properties work (like L<HTML::Object::DOM::Element::Button/validity>), but since this is for interactive interface, which perl does not provide, it has limited use. Anyhow, you can set those boolean values yourself.
94  
95 =head1 PROPERTIES
96  
97 For each of these boolean properties, a value of true indicates that the specified reason validation may have failed is true, with the exception of the valid property, which is true if the element's value obeys all constraints.
98  
99 =head2 badInput
100  
101 A boolean value that is true if the user has provided input that the browser is unable to convert.
102  
103 Example:
104  
105 <input type="number" id="age">
106  
107 my $input = $doc->getElementById( 'age' );
108 if( $input->validity->badInput )
109 {
110 say( "Bad $input detected…" );
111 }
112 else
113 {
114 say( "Content of $input OK." );
115 }
116  
117 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/badInput>
118  
119 =head2 customError
120  
121 A boolean value indicating whether the element's custom validity message has been set to a non-empty string by calling the element's setCustomValidity() method. This C<setCustomValidity> method is implemented in L<HTML::Object::DOM::Element::Input>, L<HTML::Object::DOM::Element::Object> and L<HTML::Object::DOM::Element::Select>
122  
123 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/customError>
124  
125 =head2 patternMismatch
126  
127 A boolean value that is true if the value does not match the specified pattern, and false if it does match. If true, the element matches the C<:invalid> CSS pseudo-class.
128  
129 Example:
130  
131 <p>
132 <label>Enter your phone number in the format (123)456-7890
133 (<input name="tel1" type="tel" pattern="[0-9]{3}" placeholder="###" aria-label="3-digit area code" size="2"/>)-
134 <input name="tel2" type="tel" pattern="[0-9]{3}" placeholder="###" aria-label="3-digit prefix" size="2"/> -
135 <input name="tel3" type="tel" pattern="[0-9]{4}" placeholder="####" aria-label="4-digit number" size="3"/>
136 </label>
137 </p>
138  
139 input:invalid {
140 border: red solid 3px;
141 }
142  
143 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/patternMismatch>
144  
145 =head2 rangeOverflow
146  
147 A boolean value that is true if the value is greater than the maximum specified by the max attribute, or false if it is less than or equal to the maximum. If true, the element matches the C<:invalid> and :out-of-range and CSS pseudo-classes.
148  
149 Example:
150  
151 <input type="number" min="20" max="40" step="2" />
152  
153 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/rangeOverflow>
154  
155 =head2 rangeUnderflow
156  
157 A boolean value that is true if the value is less than the minimum specified by the min attribute, or false if it is greater than or equal to the minimum. If true, the element matches the C<:invalid> and :out-of-range CSS pseudo-classes.
158  
159 Example:
160  
161 <input type="number" min="20" max="40" step="2" />
162  
163 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/rangeUnderflow>
164  
165 =head2 stepMismatch
166  
167 A boolean value that is true if the value does not fit the rules determined by the step attribute (that is, it is not evenly divisible by the step value), or false if it does fit the step rule. If true, the element matches the C<:invalid> and :out-of-range CSS pseudo-classes.
168  
169 Example:
170  
171 <input type="number" min="20" max="40" step="2" />
172  
173 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/stepMismatch>
174  
175 =head2 tooLong
176  
177 A boolean value that is true if the value exceeds the specified maxlength for L<HTML::Object::DOM::Element::Input> or L<HTML::Object::DOM::Element::TextArea> objects, or false if its length is less than or equal to the maximum length. Note: This property is never true in Gecko, because elements' values are prevented from being longer than maxlength. If true, the element matches the C<:invalid> and C<:out-of-range> CSS pseudo-classes.
178  
179 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/tooLong>
180  
181 =head2 tooShort
182  
183 A boolean value that is true if the value fails to meet the specified minlength for L<HTML::Object::DOM::Element::Input> or L<HTML::Object::DOM::Element::TextArea> objects, or false if its length is greater than or equal to the minimum length. If true, the element matches the C<:invalid> and C<:out-of-range> CSS pseudo-classes.
184  
185 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/tooShort>
186  
187 =head2 typeMismatch
188  
189 A boolean value that is true if the value is not in the required syntax (when type is email or url), or false if the syntax is correct. If true, the element matches the C<:invalid> CSS pseudo-class.
190  
191 Example:
192  
193 <p>
194 <label>
195 Enter an email address:
196 <input type="email" value="example.com" />
197 </label>
198 </p>
199 <p>
200 <label>
201 Enter a URL:
202 <input type="url" value="example.com" />
203 </label>
204 </p>
205  
206 input:invalid {
207 border: red solid 3px;
208 }
209  
210 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/typeMismatch>
211  
212 =head2 valid
213  
214 A boolean value that is true if the element meets all its validation constraints, and is therefore considered to be valid, or false if it fails any constraint. If true, the element matches the C<:valid> CSS pseudo-class; the :invalid CSS pseudo-class otherwise.
215  
216 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/valid>
217  
218 =head2 valueMissing
219  
220 A boolean value that is true if the element has a required attribute, but no value, or false otherwise. If true, the element matches the C<:invalid> CSS pseudo-class.
221  
222 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/valueMissing>
223  
224 =head1 AUTHOR
225  
226 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
227  
228 =head1 SEE ALSO
229  
230 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState>
231  
232 =head1 COPYRIGHT & LICENSE
233  
234 Copyright(c) 2021 DEGUEST Pte. Ltd.
235  
236 All rights reserved
237  
238 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
239  
240 =cut