File Coverage

lib/HTML/Object/DOM/Element/Image.pm
Criterion Covered Total %
statement 22 42 52.3
branch 0 4 0.0
condition n/a
subroutine 8 20 40.0
pod 12 12 100.0
total 42 78 53.8


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## HTML Object - ~/lib/HTML/Object/DOM/Element/Image.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::Image;
15             BEGIN
16             {
17 1     1   1020 use strict;
  1         2  
  1         30  
18 1     1   5 use warnings;
  1         2  
  1         27  
19 1     1   5 use parent qw( HTML::Object::DOM::Element );
  1         14  
  1         5  
20 1     1   68 use vars qw( $VERSION );
  1         2  
  1         54  
21 1     1   7 use HTML::Object::DOM::Element::Shared qw( :img );
  1         2  
  1         163  
22 1     1   20 our $VERSION = 'v0.2.0';
23             };
24              
25 1     1   5 use strict;
  1         2  
  1         30  
26 1     1   5 use warnings;
  1         2  
  1         456  
27              
28             sub init
29             {
30 0     0 1   my $self = shift( @_ );
31 0           $self->{complete} = 1;
32 0           $self->{decoding} = 'auto';
33 0           $self->{naturalheight} = 0;
34 0           $self->{naturalwidth} = 0;
35 0           $self->{_init_strict_use_sub} = 1;
36 0 0         $self->SUPER::init( @_ ) || return( $self->pass_error );
37 0 0         $self->{tag} = 'image' if( !CORE::length( "$self->{tag}" ) );
38 0           return( $self );
39             }
40              
41             # Note: property alt inherited
42              
43             # Note: property read-only
44 0     0 1   sub complete : lvalue { return( shift->_set_get_boolean( 'complete', @_ ) ); }
45              
46             # Note: property crossOrigin inherited
47              
48             # Note: property read-only currentSrc inherited
49              
50 0     0 1   sub decode { return; }
51              
52             # Note: property
53 0     0 1   sub decoding : lvalue { return( shift->_set_get_scalar_as_object( 'decoding', @_ ) ); }
54              
55             # Note: property height inherited
56              
57             # Note: property
58 0     0 1   sub isMap : lvalue { return( shift->_set_get_property( { attribute => 'ismap', is_boolean => 1 }, @_ ) ); }
59              
60             # Note: property
61 0     0 1   sub loading : lvalue { return( shift->_set_get_property( 'loading', @_ ) ); }
62              
63             # Note: property read-only
64 0     0 1   sub naturalHeight : lvalue { return( shift->_set_get_number( 'naturalheight', @_ ) ); }
65              
66             # Note: property read-only
67 0     0 1   sub naturalWidth : lvalue { return( shift->_set_get_number( 'naturalwidth', @_ ) ); }
68              
69             # Note: property referrerPolicy inherited
70              
71             # Note: property
72 0     0 1   sub sizes : lvalue { return( shift->_set_get_property( 'sizes', @_ ) ); }
73              
74             # Note: property src inherited
75              
76             # Note: property
77 0     0 1   sub srcset : lvalue { return( shift->_set_get_property( 'srcset', @_ ) ); }
78              
79             # Note: property useMap inherited
80              
81             # Note: property width inherited
82              
83             # Note: property read-only
84 0     0 1   sub x : lvalue { return( shift->_set_get_number( 'x', @_ ) ); }
85              
86             # Note: property read-only
87 0     0 1   sub y : lvalue { return( shift->_set_get_number( 'y', @_ ) ); } # ::
88              
89             1;
90             # NOTE: POD
91             __END__
92              
93             =encoding utf-8
94              
95             =head1 NAME
96              
97             HTML::Object::DOM::Element::Image - HTML Object DOM Image Class
98              
99             =head1 SYNOPSIS
100              
101             use HTML::Object::DOM::Element::Image;
102             my $img = HTML::Object::DOM::Element::Image->new ||
103             die( HTML::Object::DOM::Element::Image->error, "\n" );
104              
105             =head1 VERSION
106              
107             v0.2.0
108              
109             =head1 DESCRIPTION
110              
111             This interface represents an HTML C<<img>> element, providing the properties and methods used to manipulate image elements.
112              
113             =head1 INHERITANCE
114              
115             +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
116             | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Image |
117             +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
118              
119             =head1 PROPERTIES
120              
121             Inherits properties from its parent L<HTML::Object::DOM::Element>
122              
123             =head2 alt
124              
125             A string that reflects the alt HTML attribute, thus indicating the alternate fallback content to be displayed if the image has not been loaded.
126              
127             Example:
128              
129             <img src="/some/file/image.png" alt="Great Picture" />
130              
131             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt>
132              
133             =head2 complete
134              
135             This does nothing and always returns true under perl environment.
136              
137             Under JavaScript environment, this returns a boolean value that is true if the browser has finished fetching the image, whether successful or not. That means this value is also true if the image has no src value indicating an image to load.
138              
139             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/complete>
140              
141             =head2 crossOrigin
142              
143             A string specifying the CORS setting for this image element. See CORS settings attributes for further details. This may be C<undef> if CORS is not used.
144              
145             Example:
146              
147             my $image = $doc->createElement( 'img' );
148             $image->crossOrigin = "anonymous";
149              
150             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/crossOrigin>
151              
152             =head2 currentSrc
153              
154             Under perl environment, this returns the same value as L</src>, but under JavaScript environment, this returns a string representing the URL from which the currently displayed image was loaded. This may change as the image is adjusted due to changing conditions, as directed by any media queries which are in place.
155              
156             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/currentSrc>
157              
158             =head2 decoding
159              
160             An optional string representing a hint given to the browser on how it should decode the image. If this value is provided, it must be one of the possible permitted values: C<sync> to decode the image synchronously, C<async> to decode it asynchronously, or C<auto> to indicate no preference (which is the default). Read the decoding page for details on the implications of this property's values.
161              
162             Example:
163              
164             my $img = $doc->createElement( 'img' );
165             $img->decoding = 'sync';
166             $img->src = '/some/where/logo.png';
167              
168             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding>
169              
170             =head2 height
171              
172             An integer value that reflects the height HTML attribute, indicating the rendered height of the image in CSS pixels.
173              
174             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height>
175              
176             =head2 isMap
177              
178             Provided with a boolean value and this sets or gets the HTML attribute C<ismap> that indicates that the image is part of a server-side image map. This is different from a client-side image map, specified using an C<<img>> element and a corresponding C<<map>> which contains C<<area>> elements indicating the clickable areas in the image. The image must be contained within an C<<a>> element; see the ismap page for details.
179              
180             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/isMap>
181              
182             =head2 loading
183              
184             Provided with a string (C<eager> or C<lazy>) and this sets or gets the C<loading> HTML attribute that provides a hint to the browser to optimize loading the document by determining whether to load the image immediately (C<eager>) or on an as-needed basis (C<lazy>).
185              
186             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading>
187              
188             =head2 naturalHeight
189              
190             Under perl environment, this always return 0, but you can change this value.
191              
192             Under JavaScript environment, this returns an integer value representing the intrinsic height of the image in CSS pixels, if it is available; else, it shows 0. This is the height the image would be if it were rendered at its natural full size.
193              
194             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/naturalHeight>
195              
196             =head2 naturalWidth
197              
198             Under perl environment, this always return 0, but you can change this value.
199              
200             Under JavaScript environment, this returns an integer value representing the intrinsic width of the image in CSS pixels, if it is available; otherwise, it will show 0. This is the width the image would be if it were rendered at its natural full size.
201              
202             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/naturalWidth>
203              
204             =head2 referrerPolicy
205              
206             A string that reflects the referrerpolicy HTML attribute, which tells the user agent how to decide which referrer to use in order to fetch the image.
207              
208             You can use whatever value you want, but the values supported by web browser are:
209              
210             =over 4
211              
212             =item C<no-referrer>
213              
214             This means that the C<Referer> HTTP header will not be sent.
215              
216             =item C<origin>
217              
218             This means that the referrer will be the origin of the page, that is roughly the scheme, the host and the port.
219              
220             =item C<unsafe-url>
221              
222             This means that the referrer will include the origin and the path (but not the fragment, password, or username). This case is unsafe as it can leak path information that has been concealed to third-party by using TLS.
223              
224             =back
225              
226             Example:
227              
228             my $img = $doc->createElement( 'img' );
229             $img->src = '/some/where/logo.png';
230             $img->referrerPolicy = 'origin';
231              
232             my $div = $doc->getElementById('divAround');
233             $div->appendChild( $img ); # Fetch the image using the origin as the referrer
234              
235             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy>
236              
237             =head2 sizes
238              
239             A string reflecting the C<sizes> HTML attribute. This string specifies a list of comma-separated conditional sizes for the image; that is, for a given viewport size, a particular image size is to be used. Read the documentation on the C<sizes> page for details on the format of this string.
240              
241             Example:
242              
243             <img src="/files/16870/new-york-skyline-wide->jpg"
244             srcset="/files/16870/new-york-skyline-wide->jpg 3724w,
245             /files/16869/new-york-skyline-4by3->jpg 1961w,
246             /files/16871/new-york-skyline-tall->jpg 1060w"
247             sizes="((min-width: 50em) and (max-width: 60em)) 50em,
248             ((min-width: 30em) and (max-width: 50em)) 30em,
249             (max-width: 30em) 20em">
250              
251             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/sizes>
252              
253             =head2 src
254              
255             A string that reflects the src HTML attribute, which contains the full URL of the image including base URI.
256              
257             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/src>
258              
259             =head2 srcset
260              
261             A string reflecting the srcset HTML attribute. This specifies a list of candidate images, separated by commas (',', U+002C COMMA). Each candidate image is a URL followed by a space, followed by a specially-formatted string indicating the size of the image. The size may be specified either the width or a size multiple. Read the Mozilla srcset documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/srcset> for specifics on the format of the size substring.
262              
263             Example:
264              
265             "images/team-photo.jpg 1x, images/team-photo-retina.jpg 2x, images/team-photo-full 2048w"
266              
267             Another example:
268              
269             "header640.png 640w, header960.png 960w, header1024.png 1024w, header.png"
270              
271             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/srcset>
272              
273             =head2 useMap
274              
275             A string reflecting the usemap HTML attribute, containing the page-local URL of the C<<map>> element describing the image map to use. The page-local URL is a pound (hash) symbol (#) followed by the ID of the C<<map>> element, such as #my-map-element. The C<<map>> in turn contains C<<area>> elements indicating the clickable areas in the image.
276              
277             Example:
278              
279             <map name="mainmenu-map">
280             <area shape="circle" coords="25, 25, 75" href="/index.html" alt="Return to home page">
281             <area shape="rect" coords="25, 25, 100, 150" href="/index.html" alt="Shop">
282             </map>
283              
284             <img src="menubox->png" usemap="#mainmenu-map" />
285              
286             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/useMap>
287              
288             =head2 width
289              
290             An integer value that reflects the width HTML attribute, indicating the rendered width of the image in CSS pixels.
291              
292             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width>
293              
294             =head2 x
295              
296             Provided with an integer, and this sets or gets the horizontal offset of the left border edge of the image's CSS layout box relative to the origin of the C<<html>> element's containing block.
297              
298             Since this is a perl environment, this has no effect, but you can still set whatever value you want.
299              
300             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/x>
301              
302             =head2 y
303              
304             Provided with an integer, and this sets or gets the vertical offset of the top border edge of the image's CSS layout box relative to the origin of the C<<html>> element's containing block.
305              
306             Since this is a perl environment, this has no effect, but you can still set whatever value you want.
307              
308             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/y>
309              
310             =head1 METHODS
311              
312             Inherits methods from its parent L<HTML::Object::DOM::Element>
313              
314             =head2 decode
315              
316             Since this is a perl environment, there is no decoding of the image, and this always returns C<undef>.
317              
318             Under a JavaScript environment, this returns a Promise that resolves when the image is decoded and it's safe to append the image to the DOM. This prevents rendering of the next frame from having to pause to decode the image, as would happen if an undecoded image were added to the DOM.
319              
320             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode>
321              
322             =head1 AUTHOR
323              
324             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
325              
326             =head1 SEE ALSO
327              
328             L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement>, L<Mozilla documentation on image element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img>
329              
330             =head1 COPYRIGHT & LICENSE
331              
332             Copyright(c) 2021 DEGUEST Pte. Ltd.
333              
334             All rights reserved
335              
336             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
337              
338             =cut