File Coverage

lib/HTML/Object/DOM/ValidityState.pm
Criterion Covered Total %
statement 19 34 55.8
branch 0 2 0.0
condition n/a
subroutine 7 19 36.8
pod 12 12 100.0
total 38 67 56.7


line stmt bran cond sub pod time code
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 1     1   986 use strict;
  1         3  
  1         30  
18 1     1   4 use warnings;
  1         3  
  1         28  
19 1     1   6 use parent qw( Module::Generic );
  1         2  
  1         4  
20 1     1   60 use vars qw( $VERSION );
  1         1  
  1         59  
21 1     1   18 our $VERSION = 'v0.2.0';
22             };
23              
24 1     1   8 use strict;
  1         2  
  1         18  
25 1     1   4 use warnings;
  1         3  
  1         375  
26              
27             sub init
28             {
29 0     0 1   my $self = shift( @_ );
30 0           $self->{_init_strict_use_sub} = 1;
31 0 0         $self->SUPER::init( @_ ) || return( $self->pass_error );
32 0           return( $self );
33             }
34              
35             # Note: property
36 0     0 1   sub badInput : lvalue { return( shift->_set_get_boolean( 'badinput', @_ ) ); }
37              
38             # Note: property
39 0     0 1   sub customError : lvalue { return( shift->_set_get_boolean( 'customerror', @_ ) ); }
40              
41             # Note: property
42 0     0 1   sub patternMismatch : lvalue { return( shift->_set_get_boolean( 'patternmismatch', @_ ) ); }
43              
44             # Note: property
45 0     0 1   sub rangeOverflow : lvalue { return( shift->_set_get_boolean( 'rangeoverflow', @_ ) ); }
46              
47             # Note: property
48 0     0 1   sub rangeUnderflow : lvalue { return( shift->_set_get_boolean( 'rangeunderflow', @_ ) ); }
49              
50             # Note: property
51 0     0 1   sub stepMismatch : lvalue { return( shift->_set_get_boolean( 'stepmismatch', @_ ) ); }
52              
53             # Note: property
54 0     0 1   sub tooLong : lvalue { return( shift->_set_get_boolean( 'toolong', @_ ) ); }
55              
56             # Note: property
57 0     0 1   sub tooShort : lvalue { return( shift->_set_get_boolean( 'tooshort', @_ ) ); }
58              
59             # Note: property
60 0     0 1   sub typeMismatch : lvalue { return( shift->_set_get_boolean( 'typemismatch', @_ ) ); }
61              
62             # Note: property
63 0     0 1   sub valid : lvalue { return( shift->_set_get_boolean( 'valid', @_ ) ); }
64              
65             # Note: property
66 0     0 1   sub valueMissing : lvalue { return( shift->_set_get_boolean( 'valuemissing', @_ ) ); }
67              
68             1;
69             # NOTE: POD
70             __END__
71              
72             =encoding utf-8
73              
74             =head1 NAME
75              
76             HTML::Object::DOM::ValidityState - HTML Object DOM Valid State Class
77              
78             =head1 SYNOPSIS
79              
80             use HTML::Object::DOM::ValidityState;
81             my $validity = HTML::Object::DOM::ValidityState->new ||
82             die( HTML::Object::DOM::ValidityState->error, "\n" );
83              
84             =head1 VERSION
85              
86             v0.2.0
87              
88             =head1 DESCRIPTION
89              
90             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.
91              
92             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.
93              
94             =head1 PROPERTIES
95              
96             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.
97              
98             =head2 badInput
99              
100             A boolean value that is true if the user has provided input that the browser is unable to convert.
101              
102             Example:
103              
104             <input type="number" id="age">
105              
106             my $input = $doc->getElementById( 'age' );
107             if( $input->validity->badInput )
108             {
109             say( "Bad $input detected…" );
110             }
111             else
112             {
113             say( "Content of $input OK." );
114             }
115              
116             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/badInput>
117              
118             =head2 customError
119              
120             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>
121              
122             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/customError>
123              
124             =head2 patternMismatch
125              
126             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.
127              
128             Example:
129              
130             <p>
131             <label>Enter your phone number in the format (123)456-7890
132             (<input name="tel1" type="tel" pattern="[0-9]{3}" placeholder="###" aria-label="3-digit area code" size="2"/>)-
133             <input name="tel2" type="tel" pattern="[0-9]{3}" placeholder="###" aria-label="3-digit prefix" size="2"/> -
134             <input name="tel3" type="tel" pattern="[0-9]{4}" placeholder="####" aria-label="4-digit number" size="3"/>
135             </label>
136             </p>
137              
138             input:invalid {
139             border: red solid 3px;
140             }
141              
142             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/patternMismatch>
143              
144             =head2 rangeOverflow
145              
146             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.
147              
148             Example:
149              
150             <input type="number" min="20" max="40" step="2" />
151              
152             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/rangeOverflow>
153              
154             =head2 rangeUnderflow
155              
156             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.
157              
158             Example:
159              
160             <input type="number" min="20" max="40" step="2" />
161              
162             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/rangeUnderflow>
163              
164             =head2 stepMismatch
165              
166             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.
167              
168             Example:
169              
170             <input type="number" min="20" max="40" step="2" />
171              
172             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/stepMismatch>
173              
174             =head2 tooLong
175              
176             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.
177              
178             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/tooLong>
179              
180             =head2 tooShort
181              
182             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.
183              
184             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/tooShort>
185              
186             =head2 typeMismatch
187              
188             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.
189              
190             Example:
191              
192             <p>
193             <label>
194             Enter an email address:
195             <input type="email" value="example.com" />
196             </label>
197             </p>
198             <p>
199             <label>
200             Enter a URL:
201             <input type="url" value="example.com" />
202             </label>
203             </p>
204              
205             input:invalid {
206             border: red solid 3px;
207             }
208              
209             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/typeMismatch>
210              
211             =head2 valid
212              
213             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.
214              
215             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/valid>
216              
217             =head2 valueMissing
218              
219             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.
220              
221             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/valueMissing>
222              
223             =head1 AUTHOR
224              
225             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
226              
227             =head1 SEE ALSO
228              
229             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/ValidityState>
230              
231             =head1 COPYRIGHT & LICENSE
232              
233             Copyright(c) 2021 DEGUEST Pte. Ltd.
234              
235             All rights reserved
236              
237             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
238              
239             =cut