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

filter: Statementstmt 82.8% 29 / 35 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 9 / 15 Podpod 100% 7 / 7 totaltotal 77.0% 47 / 61 CC 3 SCAR 5.4
CC
3
Cov
79%
init
3.1
async
2.0
charset
2.0
CRAP 1.7
« lib/HTML/Object/DOM/Screen.pm ↑ Summary lib/HTML/Object/XPath/NodeSet.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Script.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::Script;
15 BEGIN
16 {
17 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶ use parent qw( HTML::Object::DOM::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶ use HTML::Object::DOM::Element::Shared qw( :script );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 our $VERSION = 'v0.2.0';
24 };
25  
26 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 sub init
30 {
31 10 ▶ my $self = shift( @_ );
Subroutine init: called CC=3 SCAR=11.3
Pod documented
32 10 $self->{_init_strict_use_sub} = 1;
33 10 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 10 10
34 10 ▶ $self->{tag} = 'script' if( !CORE::length( "$self->{tag}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length qq[$self->{"tag"}] 0 10 10
35 10 return( $self );
36 }
37  
38 # Note: property async
39 0 ▶sub async : lvalue { return( shift->_set_get_property({ attribute => 'async', is_boolean => 1 }, @_ ) ); }
Subroutine async: not called CC=1 SCAR=6.9
Pod documented
40  
41 # Note: property charset
42 0 ▶sub charset : lvalue { return( shift->_set_get_property( 'charset', @_ ) ); }
Subroutine charset: not called CC=1 SCAR=6.9
Pod documented
43  
44 # Note: property crossOrigin inherited
45  
46 # Note: property defer
47 0 ▶sub defer : lvalue { return( shift->_set_get_property({ attribute => 'defer', is_boolean => 1 }, @_ ) ); }
Subroutine defer: not called CC=1 SCAR=6.9
Pod documented
48  
49 # Note: property event
50 0 ▶sub event : lvalue { return( shift->_set_get_property( 'event', @_ ) ); }
Subroutine event: not called CC=1 SCAR=6.9
Pod documented
51  
52 # Note: property noModule
53 0 ▶sub noModule : lvalue { return( shift->_set_get_property({ attribute => 'nomodule', is_boolean => 1 }, @_ ) ); }
Subroutine noModule: not called CC=1 SCAR=6.9
Pod documented
54  
55 # Note: property referrerPolicy inherited
56  
57 # Note: property src inherited
58  
59 # Note: property text
60 0 ▶sub text : lvalue { return( shift->textContent( @_ ) ); }
Subroutine text: not called CC=1 SCAR=6.9
Pod documented
61  
62 # Note: property type inherited
63  
64 6 1;
65 # NOTE: POD
66 __END__
67  
68 =encoding utf-8
69  
70 =head1 NAME
71  
72 HTML::Object::DOM::Element::Script - HTML Object DOM Script Class
73  
74 =head1 SYNOPSIS
75  
76 use HTML::Object::DOM::Element::Script;
77 my $script = HTML::Object::DOM::Element::Script->new ||
78 die( HTML::Object::DOM::Element::Script->error, "\n" );
79  
80 =head1 VERSION
81  
82 v0.2.0
83  
84 =head1 DESCRIPTION
85  
86 This implements the interface for C<<script>> elements, which provides special properties and methods for manipulating the behavior and execution of C<<script>> elements (beyond the inherited L<HTML::Object::Element> interface).
87  
88 =head1 INHERITANCE
89  
90 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+
91 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Script |
92 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+
93  
94 =head1 PROPERTIES
95  
96 Inherits properties from its parent L<HTML::Object::DOM::Element>
97  
98 =head2 async
99  
100 The async and defer attributes are boolean attributes that control how the script should be executed. The C<defer> and C<async> attributes must not be specified if the src attribute is absent.
101  
102 There are three possible execution modes:
103  
104 =over 4
105  
106 =item 1. If the async attribute is present, then the script will be executed asynchronously as soon as it downloads.
107  
108 =item 2. If the async attribute is absent but the defer attribute is present, then the script is executed when the page has finished parsing.
109  
110 =item 3. If neither attribute is present, then the script is fetched and executed immediately, blocking further parsing of the page.
111  
112 =back
113  
114 The C<defer> attribute may be specified with the C<async> attribute, so legacy browsers that only support defer (and not async) fall back to the defer behavior instead of the default blocking behavior.
115  
116 Note: The exact processing details for these attributes are complex, involving many different aspects of HTML, and therefore are scattered throughout the specification. These algorithms describe the core ideas, but they rely on the parsing rules for C<<script>> start and end tags in HTML, in foreign content, and in XML; the rules for the C<document.write()> method; the handling of scripting; and so on.
117  
118 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/async>
119  
120 =head2 charset
121  
122 Is a string representing the character encoding of an external script. It reflects the charset attribute.
123  
124 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/charset>
125  
126 =head2 crossOrigin
127  
128 Is a string reflecting the CORS setting for the script element. For scripts from other origins, this controls if error information will be exposed.
129  
130 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/crossOrigin>
131  
132 =head2 defer
133  
134 The C<defer> attribute may be specified even if the C<async> attribute is specified, to cause legacy web browsers that only support defer (and not async) to fall back to the defer behavior instead of the blocking behavior that is the default.
135  
136 =head2 event
137  
138 Is a string; an obsolete way of registering event handlers on elements in an HTML document.
139  
140 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/event>
141  
142 =head2 noModule
143  
144 Is a boolean value that if true, stops the script's execution in browsers that support ES2015 modules - used to run fallback scripts in older browsers that do not support C<JavaScript> modules.
145  
146 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/noModule>
147  
148 =head2 referrerPolicy
149  
150 Is a string that reflects the referrerpolicy HTML attribute indicating which referrer to use when fetching the script, and fetches done by that script.
151  
152 Example:
153  
154 my $scriptElem = $doc->createElement( 'script' );
155 $scriptElem->src = '/';
156 $scriptElem->referrerPolicy = 'unsafe-url';
157 $doc->body->appendChild( $scriptElem );
158  
159 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/referrerPolicy>
160  
161 =head2 src
162  
163 Is a string representing the URL of an external script. It reflects the src HTML attribute. You can get and set an L<URI> object.
164  
165 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/src>
166  
167 =head2 text
168  
169 Is a string that joins and returns the contents of all Text nodes inside the C<<script>> element (ignoring other nodes like comments) in tree order. On setting, it acts the same way as the L<textContent|HTML::Object::DOM::Node/textContent> IDL attribute.
170  
171 Note: When inserted using the document.write() method, <script> elements execute (typically synchronously), but when inserted using innerHTML or outerHTML, they do not execute at all.
172  
173 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/text>
174  
175 =head2 type
176  
177 Is a string representing the MIME type of the script. It reflects the type HTML attribute.
178  
179 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/type>
180  
181 =head1 METHODS
182  
183 Inherits methods from its parent L<HTML::Object::DOM::Element>
184  
185 =head1 AUTHOR
186  
187 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
188  
189 =head1 SEE ALSO
190  
191 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement>, L<Mozilla documentation on script element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script>, L<W3C specifications|https://html.spec.whatwg.org/multipage/scripting.html#htmlscriptelement>
192  
193 =head1 COPYRIGHT & LICENSE
194  
195 Copyright(c) 2021 DEGUEST Pte. Ltd.
196  
197 All rights reserved
198  
199 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
200  
201 =cut
« lib/HTML/Object/DOM/Screen.pm ↑ Summary lib/HTML/Object/XPath/NodeSet.pm »