File Coverage

lib/HTML/Object/DOM/Element/Source.pm
Criterion Covered Total %
statement 22 30 73.3
branch 0 4 0.0
condition n/a
subroutine 8 12 66.6
pod 4 4 100.0
total 34 50 68.0


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## HTML Object - ~/lib/HTML/Object/DOM/Element/Source.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::Source;
15             BEGIN
16             {
17 1     1   1092 use strict;
  1         2  
  1         30  
18 1     1   6 use warnings;
  1         2  
  1         29  
19 1     1   6 use parent qw( HTML::Object::DOM::Element );
  1         2  
  1         4  
20 1     1   113 use vars qw( $VERSION );
  1         2  
  1         60  
21 1     1   6 use HTML::Object::DOM::Element::Shared qw( :source );
  1         14  
  1         118  
22 1     1   19 our $VERSION = 'v0.2.0';
23             };
24              
25 1     1   13 use strict;
  1         5  
  1         32  
26 1     1   6 use warnings;
  1         2  
  1         251  
27              
28             sub init
29             {
30 0     0 1   my $self = shift( @_ );
31 0           $self->{_init_strict_use_sub} = 1;
32 0 0         $self->SUPER::init( @_ ) || return( $self->pass_error );
33 0 0         $self->{tag} = 'source' if( !CORE::length( "$self->{tag}" ) );
34 0           return( $self );
35             }
36              
37             # Note: property media
38 0     0 1   sub media : lvalue { return( shift->_set_get_property( 'media', @_ ) ); }
39              
40             # Note: property sizes
41 0     0 1   sub sizes : lvalue { return( shift->_set_get_property( 'sizes', @_ ) ); }
42              
43             # Note: property src inherited
44              
45             # Note: property srcset
46 0     0 1   sub srcset : lvalue { return( shift->_set_get_property( 'srcset', @_ ) ); }
47              
48             # Note: property type inherited
49              
50             1;
51             # NOTE: POD
52             __END__
53              
54             =encoding utf-8
55              
56             =head1 NAME
57              
58             HTML::Object::DOM::Element::Source - HTML Object DOM Source Class
59              
60             =head1 SYNOPSIS
61              
62             use HTML::Object::DOM::Element::Source;
63             my $source = HTML::Object::DOM::Element::Source->new ||
64             die( HTML::Object::DOM::Element::Source->error, "\n" );
65              
66             =head1 VERSION
67              
68             v0.2.0
69              
70             =head1 DESCRIPTION
71              
72             This interface provides special properties (beyond the regular L<HTML::Object::DOM::Element> object interface it also has available to it by inheritance) for manipulating <source> elements.
73              
74             =head1 INHERITANCE
75              
76             +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+
77             | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Source |
78             +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+
79              
80             =head1 PROPERTIES
81              
82             Inherits properties from its parent L<HTML::Object::DOM::Element>
83              
84             =head2 media
85              
86             Is a string reflecting the media L<HTML attribute|HTML::Object::DOM::Attribute>, containing the intended type of the media resource.
87              
88             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSourceElement/media>
89              
90             =head2 sizes
91              
92             The sizes HTML attribute on an C<source> element specifies different image widths.
93              
94             These widths are tied to browser conditions which helps create responsive images.
95              
96             Example:
97              
98             <picture>
99             <source srcset="/some/where/image-sm.jpg 120w,
100             /some/where/image.jpg 193w,
101             /some/where/image-lg.jpg 278w"
102             sizes="(max-width: 710px) 120px,
103             (max-width: 991px) 193px,
104             278px" />
105             <img src="/some/where/image-lg.jpg" alt="Some image" />
106             </picture>
107              
108             This means that:
109              
110             =over 4
111              
112             =item * A small image is used with a screen between 0 - 710px. The layout width is 120px.
113              
114             =item * A medium image is used with a screen between 711px - 991px. The layout width is 193px.
115              
116             =item * A large image is used with a screen 992px and larger. The layout width is 278px.
117              
118             =back
119              
120             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSourceElement/sizes>
121              
122             =head2 src
123              
124             Is a string reflecting the src L<HTML attribute|HTML::Object::DOM::Attribute>, containing the URL for the media resource. The C<src> property has a meaning only when the associated C<source> element is nested in a media element that is a L<video|HTML::Object::DOM::Element::Video> or an L<audio|HTML::Object::DOM::Element::Audio> element. It has no meaning and is ignored when it is nested in a C<picture> element.
125              
126             Note: If the C<src> property is updated (along with any siblings), the parent L<HTML::Object::DOM::Element::Media>'s load method should be called when done, since C<source> elements are not re-scanned automatically.
127              
128             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSourceElement/src>
129              
130             =head2 srcset
131              
132             Is a string reflecting the srcset L<HTML attribute|HTML::Object::DOM::Attribute>, containing a list of candidate images, separated by a comma (',', U+002C COMMA). A candidate image is a URL followed by a 'w' with the width of the images, or an 'x' followed by the pixel density.
133              
134             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSourceElement/srcset>
135              
136             =head2 type
137              
138             Is a string reflecting the type L<HTML attribute|HTML::Object::DOM::Attribute>, containing the type of the media resource.
139              
140             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSourceElement/type>
141              
142             =head1 METHODS
143              
144             Inherits methods from its parent L<HTML::Object::DOM::Element>
145              
146             =head1 AUTHOR
147              
148             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
149              
150             =head1 SEE ALSO
151              
152             L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSourceElement>, L<Mozilla documentation on source element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/source>
153              
154             =head1 COPYRIGHT & LICENSE
155              
156             Copyright(c) 2021 DEGUEST Pte. Ltd.
157              
158             All rights reserved
159              
160             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
161              
162             =cut