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

filter: Statementstmt 0.0% 0 / 198 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 10 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 83 Podpod 0.0% 0 / 76 totaltotal 0.0% 0 / 387 CC 11 SCAR 14.0
CC
11
Cov
0%
list
20.0
origin
20.0
form
12.0
CRAP 4.0
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Shared.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/25
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::Shared;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use vars qw( @EXPORT_OK %EXPORT_TAGS $VERSION );
21 use Exporter qw( import );
22 our @EXPORT_OK = qw(
23 accept accessKey align allowdirs alt autocapitalize autocomplete autofocus checked checkValidity compact crossOrigin currentSrc defaultChecked defaultValue dirName disabled download files form formAction formEnctype formMethod formNoValidate formTarget hash height host hostname href hreflang indeterminate inputmode labels list max maxLength min minLength multiple name origin password pathname pattern placeholder port protocol readOnly referrerPolicy rel relList reportValidity required selectionDirection selectionEnd selectionStart search setCustomValidity size src step target type useMap username value validationMessage validity valueAsDate valueAsNumber webkitdirectory webkitEntries willValidate width
24 );
25 our %EXPORT_TAGS = (
26 anchor => [qw( download hash host hostname href hreflang origin password pathname port protocol referrerPolicy rel relList search target username )],
27 area => [qw( accessKey alt download hash host hostname href hreflang origin password pathname port protocol referrerPolicy rel relList search target username )],
28 base => [qw( href target )],
29 button => [qw(
30 form formAction formEnctype formMethod formNoValidate formTarget
31 accessKey autofocus disabled form labels name type validationMessage validity value willValidate
32 )],
33 canvas => [qw( height width )],
34 caption => [qw( align )],
35 dir => [qw( compact )],
36 div => [qw( align )],
37 dl => [qw( compact )],
38 embed => [qw( align height name src width )],
39 fencedframe => [qw( height width )],
40 fieldset => [qw( disabled checkValidity form name reportValidity setCustomValidity validationMessage validity willValidate )],
41 form => [qw(
42 accept autocapitalize autocomplete name
43  
44 checkValidity reportValidity
45 )],
46 heading => [qw( align )],
47 hr => [qw( align size width )],
48 iframe => [qw( align height name referrerPolicy src width )],
49 img => [qw( alt crossOrigin currentSrc height referrerPolicy src useMap width )],
50 input => [qw(
51 accept accessKey align allowdirs alt autocapitalize autocomplete autofocus checked
52 defaultChecked defaultValue dirName disabled files form
53 formAction formEnctype formMethod formNoValidate formTarget height indeterminate
54 inputmode labels list max maxLength min minLength multiple name pattern placeholder
55 readOnly required selectionDirection selectionEnd selectionStart size src step
56 type useMap validationMessage validity value valueAsDate valueAsNumber
57 webkitEntries webkitdirectory width willValidate
58 )],
59 label => [qw( form )],
60 legend => [qw( accessKey align form )],
61 li => [qw( type value )],
62 'link' => [qw( crossOrigin disabled href hreflang referrerPolicy rel relList type )],
63 'map' => [qw( name )],
64 marquee => [qw( height width )],
65 media => [qw( crossOrigin currentSrc src )],
66 menu => [qw( compact type )],
67 meter => [qw( labels max min value )],
68 object => [qw( align checkValidity height name setCustomValidity type useMap validity validationMessage width willValidate )],
69 ol => [qw( compact type )],
70 optgroup => [qw( disabled )],
71 option => [qw( disabled form )],
72 output => [qw( checkValidity form labels setCustomValidity type validity validationMessage value willValidate )],
73 paragraph => [qw( align )],
74 param => [qw( name type value )],
75 pre => [qw( width )],
76 progress => [qw( labels value )],
77 script => [qw( crossOrigin src referrerPolicy type )],
78 'select' => [qw( checkValidity disabled form labels name reportValidity required setCustomValidity type validationMessage validity value willValidate )],
79 slot => [qw( name )],
80 source => [qw( src type )],
81 style => [qw( disabled type )],
82 table => [qw( align width )],
83 tablecaption => [qw( align )],
84 tablecell => [qw( align height width )],
85 tablecol => [qw( align width )],
86 tablerow => [qw( align )],
87 tablesection => [qw( align )],
88 track => [qw( src )],
89 ulist => [qw( compact type )],
90 video => [qw( height width )],
91 );
92 $EXPORT_TAGS{all} = [@EXPORT_OK];
93 our $VERSION = 'v0.2.0';
94 };
95  
96 use strict;
97 use warnings;
98  
99 # Note: property for input
100 sub accept : lvalue { return( shift->_set_get_property( 'accept', @_ ) ); }
101  
102 # Note: property for input
103 sub accessKey : lvalue { return( shift->_set_get_property( 'accesskey', @_ ) ); }
104  
105 # Note: property for embed
106 sub align : lvalue { return( shift->_set_get_property( 'align', @_ ) ); }
107  
108 # Note: property for input
109 sub allowdirs : lvalue { return( shift->_set_get_boolean( 'allowdirs', @_ ) ); }
110  
111 # Note: property for img, input
112 sub alt : lvalue { return( shift->_set_get_property( 'alt', @_ ) ); }
113  
114 # Note: property for input
115 sub autocapitalize : lvalue { return( shift->_set_get_property( 'autocapitalize', @_ ) ); }
116  
117 # Note: property for input
118 sub autocomplete : lvalue { return( shift->_set_get_property( 'autocomplete', @_ ) ); }
119  
120 # Note: property for input
121 sub autofocus : lvalue { return( shift->_set_get_property( { attribute => 'autofocus', is_boolean => 1 }, @_ ) ); }
122  
123 # Note: property boolean for input
124 sub checked : lvalue { return( shift->_set_get_property( { attribute => 'checked', is_boolean => 1 }, @_ ) ); }
125  
126 # Note: method
127 sub checkValidity { return( shift->_set_get_boolean( 'checkValidity', @_ ) ); }
128  
129 # Note: property
130 sub compact : lvalue { return( shift->_set_get_property( { attribute => 'compact', is_boolean => 1 }, @_ ) ); }
131  
132 # Note: property
133 sub crossOrigin : lvalue { return( shift->_set_get_property( 'crossorigin', @_ ) ); }
134  
135 # Note: property
136 sub currentSrc : lvalue { return( shift->_set_get_property( 'currentsrc', @_ ) ); }
137  
138 # Note: property boolean for input
139 sub defaultChecked : lvalue { return( shift->_set_get_property( { attribute => 'defaultchecked', is_boolean => 1 }, @_ ) ); }
140  
141 # Note: property for input
142 sub defaultValue : lvalue { return( shift->_set_get_property( 'value', @_ ) ); }
143  
144 # Note: property for input
145 sub dirName { return( shift->_set_get_scalar_as_object( 'dirName', @_ ) ); }
146  
147 # Note: property for input
148 sub disabled : lvalue { return( shift->_set_get_property( { attribute => 'disabled', is_boolean => 1 }, @_ ) ); }
149  
150 # Note: property for anchor, area
151 sub download : lvalue { return( shift->_set_get_property( 'download', @_ ) ); }
152  
153 # Note: property for input
154 sub files { return( shift->_set_get_object( 'files', 'HTML::Object::DOM::FileList' ) ); }
155  
156 # Note: property read-only
157 sub form
158 {
159 my $self = shift( @_ );
160 # If the element has a 'form' attribute containing the form it, we use it to find the specific form, otherwise we search for the parent form
161 my $id = $self->attr( 'form' );
162 if( defined( $id ) && CORE::length( "$id" ) )
163 {
164 my $root = $self->root;
165 return if( !defined( $root ) );
166 # my $form = $root->getElementById( $id );
167 my $forms = $root->look_down( _tag => 'form', id => $id );
168 return( $forms->first );
169 }
170 else
171 {
172 return( $self->_get_parent_form );
173 }
174 }
175  
176 # Note: property for input
177 sub formAction : lvalue { return( shift->_set_get_form_attribute( 'action', @_ ) ); }
178  
179 # Note: property for input
180 sub formEnctype : lvalue { return( shift->_set_get_form_attribute( 'enctype', @_ ) ); }
181  
182 # Note: property for input
183 sub formMethod : lvalue { return( shift->_set_get_form_attribute( 'method', @_ ) ); }
184  
185 # Note: property for input
186 sub formNoValidate : lvalue { return( shift->_set_get_form_attribute( 'novalidate', @_ ) ); }
187  
188 # Note: property for input
189 sub formTarget : lvalue { return( shift->_set_get_form_attribute( 'target', @_ ) ); }
190  
191 # Note: property for anchor
192 sub hash : lvalue { return( shift->_set_get_uri_property( 'hash', @_ ) ); }
193  
194 # Note: property for input
195 sub height : lvalue { return( shift->_set_get_property( 'height', @_ ) ); }
196  
197 # Note: property for anchor
198 sub host : lvalue { return( shift->_set_get_uri_property( 'host', @_ ) ); }
199  
200 # Note: property for anchor
201 sub hostname : lvalue { return( shift->_set_get_uri_property( 'hostname', @_ ) ); }
202  
203 # Note: property for anchor
204 sub href : lvalue { return( shift->_set_get_property( { attribute => 'href', is_uri => 1 }, @_ ) ); }
205  
206 # Note: property for anchor
207 sub hreflang : lvalue { return( shift->_set_get_property( 'hreflang', @_ ) ); }
208  
209 # Note: property boolean for input
210 sub indeterminate : lvalue { return( shift->_set_get_property( { attribute => 'indeterminate', is_boolean => 1 }, @_ ) ); }
211  
212 #Note: property for input
213 sub inputmode : lvalue { return( shift->_set_get_property( 'inputmode', @_ ) ); }
214  
215 # Note: property
216 sub labels
217 {
218 my $self = shift( @_ );
219 my $results = $self->new_array;
220 # No need to go further really
221 my $id = $self->attributes->get( 'id' );
222 return( $results ) if( !defined( $id ) || !length( $id ) );
223 my $root = $self->root || return( $results );
224 $results = $root->look_down( _tag => 'label', 'for' => $id );
225 return( $self->new_nodelist( $results ) );
226 }
227  
228 # Note: property for input; an element object pointing to <datalist>
229 sub list
230 {
231 my $self = shift( @_ );
232 if( @_ )
233 {
234 return( $self->_set_get_object_without_init( 'list', 'HTML::Object::DOM::Element', @_ ) );
235 }
236 else
237 {
238 return( $self->{list} ) if( ref( $self->{list} ) );
239 my $root = $self->root;
240 my $id = $self->attr( 'list' );
241 return( $self->new_null ) if( !defined( $id ) );
242 my $elem = $root->look_down( _tag => 'datalist', id => $id );
243 return( $self->{list} = $elem );
244 }
245 }
246  
247 # Note: property for input
248 sub max : lvalue { return( shift->_set_get_property( 'max', @_ ) ); }
249  
250 # Note: property for input
251 sub maxLength : lvalue { return( shift->_set_get_property( 'maxlength', @_ ) ); }
252  
253 # Note: property for input
254 sub min : lvalue { return( shift->_set_get_property( 'min', @_ ) ); }
255  
256 # Note: property for input
257 sub minLength : lvalue { return( shift->_set_get_property( 'minlength', @_ ) ); }
258  
259 # Note: property boolean for input
260 sub multiple : lvalue { return( shift->_set_get_property( { attribute => 'multiple', is_boolean => 1 }, @_ ) ); }
261  
262 # Note: property for input
263 sub name : lvalue { return( shift->_set_get_property( 'name', @_ ) ); }
264  
265 # Note: property for anchor
266 sub origin
267 {
268 my $self = shift( @_ );
269 my $uri = $self->_set_get_anchor_uri;
270 # We use ref() and not ->isa on purpose, because URI::https (for example) is a subclass of URI::_generic
271 # so ->isa( 'URI::_generic' ) will always return true
272 return if( ref( $uri ) eq 'URI::_generic' );
273 return if( !$uri->host );
274 # The web standard is to return a hostname without its port if it is a standard port, even if it was specified
275 # e.g. https://example.org:443 -> https://example.org
276 # return( $uri->canonical );
277 # I need a way to remove the port if it is standard. URI->canonical gives us that, but also includes the path, which we do not want
278 # and we do not want a trailing '/', which canonical adds
279 my $origin = URI->new( join( '', $uri->scheme, '://', $uri->host_port ) )->canonical;
280 # substr( $origin, -1, 1, '' ) if( substr( $origin, -1, 1 ) eq '/' );
281 $origin->path( substr( $origin->path, 0, -1 ) ) if( substr( $origin->path, -1, 1 ) eq '/' );
282 return( $origin );
283 }
284  
285 # Note: property for anchor
286 sub password : lvalue { return( shift->_set_get_uri_property( 'password', @_ ) ); }
287  
288 # Note: property for anchor
289 sub pathname : lvalue { return( shift->_set_get_uri_property( 'pathname', @_ ) ); }
290  
291 # Note: property for input
292 sub pattern : lvalue { return( shift->_set_get_property( 'pattern', @_ ) ); }
293  
294 # Note: property for input
295 sub placeholder : lvalue { return( shift->_set_get_property( 'placeholder', @_ ) ); }
296  
297 # Note: property for anchor
298 sub port : lvalue { return( shift->_set_get_uri_property( 'port', @_ ) ); }
299  
300 # Note: property for anchor
301 sub protocol : lvalue { return( shift->_set_get_uri_property( 'protocol', @_ ) ); }
302  
303 # Note: property boolean for input
304 sub readOnly : lvalue { return( shift->_set_get_property( { attribute => 'readonly', is_boolean => 1 }, @_ ) ); }
305  
306 # Note: property for anchor
307 sub referrerPolicy : lvalue { return( shift->_set_get_property( 'referrerpolicy', @_ ) ); }
308  
309 # Note: property for anchor
310 sub rel : lvalue { return( shift->_set_get_property( 'rel', @_ ) ); }
311  
312 # Note: property for anchor
313 sub relList
314 {
315 my $self = shift( @_ );
316 unless( $self->{_rel_list} )
317 {
318 my $rel = $self->attr( 'rel' );
319 require HTML::Object::TokenList;
320 $self->{_rel_list} = HTML::Object::TokenList->new( $rel, element => $self, attribute => 'rel', debug => $self->debug ) ||
321 return( $self->pass_error( HTML::Object::TokenList->error ) );
322 }
323 return( $self->{_rel_list} );
324 }
325  
326 # Note: method
327 sub reportValidity { return( shift->_set_get_boolean( 'reportValidity', @_ ) ); }
328  
329 # Note: property for input
330 sub required : lvalue { return( shift->_set_get_property( { attribute => 'required', is_boolean => 1 }, @_ ) ); }
331  
332 # Note: property for input
333 sub selectionDirection : lvalue { return( shift->_set_get_property( 'selectiondirection', @_ ) ); }
334  
335 # Note: property for input
336 sub selectionEnd : lvalue { return( shift->_set_get_property( 'selectionend', @_ ) ); }
337  
338 # Note: property for input
339 sub selectionStart : lvalue { return( shift->_set_get_property( 'selectionstart', @_ ) ); }
340  
341 # Note: property for anchor
342 sub search : lvalue { return( shift->_set_get_uri_property( 'search', @_ ) ); }
343  
344 # Note: method for fieldset, input, object
345 sub setCustomValidity { return( shift->_set_get_scalar_as_object( 'setcustomvalidity', @_ ) ); }
346  
347 sub size : lvalue { return( shift->_set_get_property( 'selectionstart', @_ ) ); }
348  
349 # Note: property for input
350 sub src : lvalue { return( shift->_set_get_property( { attribute => 'src', is_uri => 1 }, @_ ) ); }
351  
352 # Note: property for input
353 sub step : lvalue { return( shift->_set_get_property( 'step', @_ ) ); }
354  
355 # Note: tabIndex is inherited directly HTML::Object::DOM::Element
356  
357 # Note: property for anchor
358 sub target : lvalue { return( shift->_set_get_property( 'target', @_ ) ); }
359  
360 # Note: property for input
361 sub type : lvalue { return( shift->_set_get_property( 'type', @_ ) ); }
362  
363 # Note: property for img, input
364 sub useMap : lvalue { return( shift->_set_get_property( 'usemap', @_ ) ); }
365  
366 # Note: property for anchor
367 sub username : lvalue { return( shift->_set_get_uri_property( 'username', @_ ) ); }
368  
369 # Note: property for input
370 sub value : lvalue { return( shift->_set_get_property( 'value', @_ ) ); }
371  
372 # Note: property read-only for input
373 sub validationMessage : lvalue { return( shift->_set_get_scalar_as_object( 'validationmessage', @_ ) ); }
374  
375 # Note: property read-only for input
376 sub validity { return( shift->_set_get_object( 'validity', 'HTML::Object::DOM::ValidityState', @_ ) ); }
377  
378 # Note: property for input
379 sub valueAsDate : lvalue { return( shift->_set_get_property( { attribute => 'value', is_datetime => 1 }, @_ ) ); }
380  
381 # Note: property for input
382 sub valueAsNumber : lvalue { return( shift->_set_get_property( { attribute => 'value', is_number => 1 }, @_ ) ); }
383  
384 # Note: property boolean for input
385 sub webkitdirectory : lvalue { return( shift->_set_get_property( { attribute => 'webkitdirectory', is_boolean => 1 }, @_ ) ); }
386  
387 sub webkitEntries { return; }
388  
389 # Note: property read-only for input
390 sub willValidate : lvalue { return( shift->_set_get_boolean( 'willvalidate', @_ ) ); }
391  
392 # Note: property for input
393 sub width : lvalue { return( shift->_set_get_property( 'width', @_ ) ); }
394  
395 1;
396 # NOTE: POD
397 __END__