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

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 86 CC 5 SCAR 18.3
CC
5
Cov
0%
init
20.0
sizes
6.0
BEGIN
2.0
CRAP 6.2
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Link.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/22
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::Link;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( HTML::Object::DOM::Element );
21 use vars qw( $VERSION );
22 use HTML::Object::DOM::Element::Shared qw( :link );
23 # There are a few properties and methods that are common to AnchorElement class, so
24 # instead of re-writing them, we re-use those from AnchorElement.
25 require HTML::Object::DOM::Element::Anchor;
26 our $VERSION = 'v0.2.0';
27 };
28  
29 use strict;
30 use warnings;
31  
32 sub init
33 {
34 my $self = shift( @_ );
35 $self->{_init_strict_use_sub} = 1;
36 $self->SUPER::init( @_ ) || return( $self->pass_error );
37 $self->{tag} = 'link' if( !CORE::length( "$self->{tag}" ) );
38 $self->_set_get_internal_attribute_callback( rel => sub
39 {
40 my( $this, $val ) = @_;
41 my $list;
42 return if( !( $list = $this->{_rel_list} ) );
43 # $list->debug( $self->debug );
44 $list->update( $val );
45 });
46 $self->_set_get_internal_attribute_callback( sizes => sub
47 {
48 my( $this, $val ) = @_;
49 my $list;
50 return if( !( $list = $this->{_sizes_list} ) );
51 # $list->debug( $self->debug );
52 $list->update( $val );
53 });
54 return( $self );
55 }
56  
57 # Note: property
58 sub as : lvalue { return( shift->_set_get_property( 'as', @_ ) ); }
59  
60 # Note: property crossOrigin inherited
61  
62 # Note: property disabled inherited
63  
64 # Note: property href inherited
65  
66 # Note: property hreflang inherited
67  
68 # Note: property
69 sub media : lvalue { return( shift->_set_get_property( 'media', @_ ) ); }
70  
71 # Note: property referrerPolicy inherited
72  
73 # Note: property rel inherited
74  
75 # Note: property relList inherited
76  
77 # Note: property
78 sub sizes
79 {
80 my $self = shift( @_ );
81 unless( $self->{_sizes_list} )
82 {
83 my $sizes = $self->attr( 'sizes' );
84 require HTML::Object::TokenList;
85 $self->{_sizes_list} = HTML::Object::TokenList->new( $sizes, element => $self, attribute => 'sizes', debug => $self->debug ) ||
86 return( $self->pass_error( HTML::Object::TokenList->error ) );
87 }
88 return( $self->{_sizes_list} );
89 }
90  
91 # TODO: make call to this method return a CSS::Object
92 # Note: property
93 sub sheet { return; }
94  
95 # Note: property type inherited
96  
97 1;
98 # NOTE: POD
99 __END__
100  
101 =encoding utf-8
102  
103 =head1 NAME
104  
105 HTML::Object::DOM::Element::Link - HTML Object DOM Link Class
106  
107 =head1 SYNOPSIS
108  
109 use HTML::Object::DOM::Element::Link;
110 my $link = HTML::Object::DOM::Element::Link->new ||
111 die( HTML::Object::DOM::Element::Link->error, "\n" );
112  
113 =head1 VERSION
114  
115 v0.2.0
116  
117 =head1 DESCRIPTION
118  
119 The C<LinkElement> interface represents reference information for external resources and the relationship of those resources to a document and vice-versa (corresponds to <link> element; not to be confused with <a>, which is represented by L<HTML::Object::DOM::Element::Anchor>). This object inherits all of the properties and methods of the L<HTML::Object::DOM::Element> interface.
120  
121 =head1 INHERITANCE
122  
123 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +----------------------------------+
124 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Link |
125 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +----------------------------------+
126  
127 =head1 PROPERTIES
128  
129 Inherits properties from its parent L<HTML::Object::DOM::DOM::Element>
130  
131 =head2 as
132  
133 A string representing the type of content being loaded by the HTML link.
134  
135 Example:
136  
137 <link rel="preload" href="myFont.woff2" as="font"
138 type="font/woff2" crossorigin="anonymous">
139  
140 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/as>
141  
142 =head2 crossOrigin
143  
144 A string that corresponds to the CORS setting for this link element. See CORS settings attributes for details.
145  
146 Example:
147  
148 <link rel="preload" href="myFont.woff2" as="font"
149 type="font/woff2" crossorigin="anonymous">
150  
151 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/crossOrigin>
152  
153 =head2 disabled
154  
155 A boolean value which represents whether the link is disabled; currently only used with style sheet links.
156  
157 If the boolean value provided is false, the disabled property will be removed altogether. If it is true, it will be set to an empty value.
158  
159 Example:
160  
161 my $link = $doc->createElement( 'link' );
162 $link->disabled = 1;
163 # <link disabled="" />
164 $link->disabled = 0;
165 # <link />
166  
167 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/disabled>
168  
169 =head2 href
170  
171 A string representing the URI for the target resource.
172  
173 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/href>
174  
175 =head2 hreflang
176  
177 A string representing the language code for the linked resource.
178  
179 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/hreflang>
180  
181 =head2 media
182  
183 A string representing a list of one or more media formats to which the resource applies.
184  
185 Example:
186  
187 <link href="print.css" rel="stylesheet" media="print" />
188 <link href="mobile.css" rel="stylesheet" media="screen and (max-width: 600px)" />
189  
190 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/media>
191  
192 =head2 referrerPolicy
193  
194 A string that reflects the referrerpolicy HTML attribute indicating which referrer to use.
195  
196 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/referrerPolicy>
197  
198 =head2 rel
199  
200 A string representing the forward relationship of the linked resource from the document to the resource.
201  
202 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/rel>
203  
204 =head2 relList
205  
206 Read-only.
207  
208 A L<HTML::Object::TokenList> that reflects the rel HTML attribute, as a L<list of tokens|HTML::Object::DOM::TokenList>.
209  
210 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/relList>
211  
212 =head2 sizes
213  
214 Read-only.
215  
216 A L<HTML::Object::TokenList> that reflects the sizes HTML attribute, as a L<list of tokens|HTML::Object::DOM::TokenList>.
217  
218 <link rel="apple-touch-icon-precomposed" sizes="114x114"
219 href="apple-icon-114.png" type="image/png">
220  
221 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/sizes>
222  
223 =head2 sheet
224  
225 Read-only.
226  
227 This currently always returns C<undef>. Maybe in the future this would return a L<CSS::Object> object.
228  
229 Normally, under JavaScript environment, this would return the L<StyleSheet object|https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet> associated with the given element, or C<undef> if there is none.
230  
231 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/sheet> and also the L<CSSObject documentation|https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet>
232  
233 =head2 type
234  
235 A string representing the MIME type of the linked resource.
236  
237 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/type>
238  
239 =head1 METHODS
240  
241 No specific method; inherits methods from its parent, L<HTML::Object::DOM::DOM::Element>
242  
243 =head1 AUTHOR
244  
245 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
246  
247 =head1 SEE ALSO
248  
249 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement>, L<specification on link|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link>
250  
251 =head1 COPYRIGHT & LICENSE
252  
253 Copyright(c) 2021 DEGUEST Pte. Ltd.
254  
255 All rights reserved
256  
257 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
258  
259 =cut