lib/HTML/Object/DOM/Element/Image.pm

filter: Statementstmt 54.5% 24 / 44 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 8 / 20 Podpod 100% 12 / 12 totaltotal 55.0% 44 / 80 CC 3 SCAR 11.0
CC
3
Cov
50%
init
12.0
complete
2.0
decode
2.0
CRAP 3.0
« blib/lib/HTML/Object/Comment.pm ↑ Summary blib/lib/HTML/Object/Attribute.pm »
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 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use parent qw( HTML::Object::DOM::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶ use HTML::Object::DOM::Element::Shared qw( :img );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 our $VERSION = 'v0.2.0';
24 };
25  
26 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 sub init
30 {
31 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=3 SCAR=24.8
Pod documented
32 0 $self->{complete} = 1;
33 0 $self->{decoding} = 'auto';
34 0 $self->{naturalheight} = 0;
35 0 $self->{naturalwidth} = 0;
36 0 $self->{_init_strict_use_sub} = 1;
37 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
38 0 ▶ $self->{tag} = 'image' if( !CORE::length( "$self->{tag}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length qq[$self->{"tag"}] 0 0 0
39 0 return( $self );
40 }
41  
42 # Note: property alt inherited
43  
44 # Note: property read-only
45 0 ▶sub complete : lvalue { return( shift->_set_get_boolean( 'complete', @_ ) ); }
Subroutine complete: not called CC=1 SCAR=6.9
Pod documented
46  
47 # Note: property crossOrigin inherited
48  
49 # Note: property read-only currentSrc inherited
50  
51 0 ▶sub decode { return; }
Subroutine decode: not called CC=1 SCAR=6.9
Pod documented
52  
53 # Note: property
54 0 ▶sub decoding : lvalue { return( shift->_set_get_scalar_as_object( 'decoding', @_ ) ); }
Subroutine decoding: not called CC=1 SCAR=6.9
Pod documented
55  
56 # Note: property height inherited
57  
58 # Note: property
59 0 ▶sub isMap : lvalue { return( shift->_set_get_property( { attribute => 'ismap', is_boolean => 1 }, @_ ) ); }
Subroutine isMap: not called CC=1 SCAR=6.9
Pod documented
60  
61 # Note: property
62 0 ▶sub loading : lvalue { return( shift->_set_get_property( 'loading', @_ ) ); }
Subroutine loading: not called CC=1 SCAR=6.9
Pod documented
63  
64 # Note: property read-only
65 0 ▶sub naturalHeight : lvalue { return( shift->_set_get_number( 'naturalheight', @_ ) ); }
Subroutine naturalHeight: not called CC=1 SCAR=6.9
Pod documented
66  
67 # Note: property read-only
68 0 ▶sub naturalWidth : lvalue { return( shift->_set_get_number( 'naturalwidth', @_ ) ); }
Subroutine naturalWidth: not called CC=1 SCAR=6.9
Pod documented
69  
70 # Note: property referrerPolicy inherited
71  
72 # Note: property
73 0 ▶sub sizes : lvalue { return( shift->_set_get_property( 'sizes', @_ ) ); }
Subroutine sizes: not called CC=1 SCAR=6.9
Pod documented
74  
75 # Note: property src inherited
76  
77 # Note: property
78 0 ▶sub srcset : lvalue { return( shift->_set_get_property( 'srcset', @_ ) ); }
Subroutine srcset: not called CC=1 SCAR=6.9
Pod documented
79  
80 # Note: property useMap inherited
81  
82 # Note: property width inherited
83  
84 # Note: property read-only
85 0 ▶sub x : lvalue { return( shift->_set_get_number( 'x', @_ ) ); }
Subroutine x: not called CC=1 SCAR=6.9
Pod documented
86  
87 # Note: property read-only
88 0 ▶sub y : lvalue { return( shift->_set_get_number( 'y', @_ ) ); } # ::
Subroutine y: not called CC=1 SCAR=6.9
Pod documented
89  
90 1 1;
91 # NOTE: POD
92 __END__
93  
94 =encoding utf-8
95  
96 =head1 NAME
97  
98 HTML::Object::DOM::Element::Image - HTML Object DOM Image Class
99  
100 =head1 SYNOPSIS
101  
102 use HTML::Object::DOM::Element::Image;
103 my $img = HTML::Object::DOM::Element::Image->new ||
104 die( HTML::Object::DOM::Element::Image->error, "\n" );
105  
106 =head1 VERSION
107  
108 v0.2.0
109  
110 =head1 DESCRIPTION
111  
112 This interface represents an HTML C<<img>> element, providing the properties and methods used to manipulate image elements.
113  
114 =head1 INHERITANCE
115  
116 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
117 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Image |
118 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
119  
120 =head1 PROPERTIES
121  
122 Inherits properties from its parent L<HTML::Object::DOM::Element>
123  
124 =head2 alt
125  
126 A string that reflects the alt HTML attribute, thus indicating the alternate fallback content to be displayed if the image has not been loaded.
127  
128 Example:
129  
130 <img src="/some/file/image.png" alt="Great Picture" />
131  
132 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt>
133  
134 =head2 complete
135  
136 This does nothing and always returns true under perl environment.
137  
138 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.
139  
140 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/complete>
141  
142 =head2 crossOrigin
143  
144 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.
145  
146 Example:
147  
148 my $image = $doc->createElement( 'img' );
149 $image->crossOrigin = "anonymous";
150  
151 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/crossOrigin>
152  
153 =head2 currentSrc
154  
155 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.
156  
157 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/currentSrc>
158  
159 =head2 decoding
160  
161 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.
162  
163 Example:
164  
165 my $img = $doc->createElement( 'img' );
166 $img->decoding = 'sync';
167 $img->src = '/some/where/logo.png';
168  
169 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding>
170  
171 =head2 height
172  
173 An integer value that reflects the height HTML attribute, indicating the rendered height of the image in CSS pixels.
174  
175 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height>
176  
177 =head2 isMap
178  
179 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.
180  
181 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/isMap>
182  
183 =head2 loading
184  
185 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>).
186  
187 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading>
188  
189 =head2 naturalHeight
190  
191 Under perl environment, this always return 0, but you can change this value.
192  
193 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.
194  
195 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/naturalHeight>
196  
197 =head2 naturalWidth
198  
199 Under perl environment, this always return 0, but you can change this value.
200  
201 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.
202  
203 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/naturalWidth>
204  
205 =head2 referrerPolicy
206  
207 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.
208  
209 You can use whatever value you want, but the values supported by web browser are:
210  
211 =over 4
212  
213 =item C<no-referrer>
214  
215 This means that the C<Referer> HTTP header will not be sent.
216  
217 =item C<origin>
218  
219 This means that the referrer will be the origin of the page, that is roughly the scheme, the host and the port.
220  
221 =item C<unsafe-url>
222  
223 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.
224  
225 =back
226  
227 Example:
228  
229 my $img = $doc->createElement( 'img' );
230 $img->src = '/some/where/logo.png';
231 $img->referrerPolicy = 'origin';
232  
233 my $div = $doc->getElementById('divAround');
234 $div->appendChild( $img ); # Fetch the image using the origin as the referrer
235  
236 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy>
237  
238 =head2 sizes
239  
240 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.
241  
242 Example:
243  
244 <img src="/files/16870/new-york-skyline-wide->jpg"
245 srcset="/files/16870/new-york-skyline-wide->jpg 3724w,
246 /files/16869/new-york-skyline-4by3->jpg 1961w,
247 /files/16871/new-york-skyline-tall->jpg 1060w"
248 sizes="((min-width: 50em) and (max-width: 60em)) 50em,
249 ((min-width: 30em) and (max-width: 50em)) 30em,
250 (max-width: 30em) 20em">
251  
252 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/sizes>
253  
254 =head2 src
255  
256 A string that reflects the src HTML attribute, which contains the full URL of the image including base URI.
257  
258 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/src>
259  
260 =head2 srcset
261  
262 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.
263  
264 Example:
265  
266 "images/team-photo.jpg 1x, images/team-photo-retina.jpg 2x, images/team-photo-full 2048w"
267  
268 Another example:
269  
270 "header640.png 640w, header960.png 960w, header1024.png 1024w, header.png"
271  
272 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/srcset>
273  
274 =head2 useMap
275  
276 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.
277  
278 Example:
279  
280 <map name="mainmenu-map">
281 <area shape="circle" coords="25, 25, 75" href="/index.html" alt="Return to home page">
282 <area shape="rect" coords="25, 25, 100, 150" href="/index.html" alt="Shop">
283 </map>
284  
285 <img src="menubox->png" usemap="#mainmenu-map" />
286  
287 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/useMap>
288  
289 =head2 width
290  
291 An integer value that reflects the width HTML attribute, indicating the rendered width of the image in CSS pixels.
292  
293 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width>
294  
295 =head2 x
296  
297 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.
298  
299 Since this is a perl environment, this has no effect, but you can still set whatever value you want.
300  
301 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/x>
302  
303 =head2 y
304  
305 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.
306  
307 Since this is a perl environment, this has no effect, but you can still set whatever value you want.
308  
309 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/y>
310  
311 =head1 METHODS
312  
313 Inherits methods from its parent L<HTML::Object::DOM::Element>
314  
315 =head2 decode
316  
317 Since this is a perl environment, there is no decoding of the image, and this always returns C<undef>.
318  
319 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.
320  
321 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode>
322  
323 =head1 AUTHOR
324  
325 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
326  
327 =head1 SEE ALSO
328  
329 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>
330  
331 =head1 COPYRIGHT & LICENSE
332  
333 Copyright(c) 2021 DEGUEST Pte. Ltd.
334  
335 All rights reserved
336  
337 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
338  
339 =cut
« blib/lib/HTML/Object/Comment.pm ↑ Summary blib/lib/HTML/Object/Attribute.pm »