line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
6
|
|
5858
|
use strict; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
240
|
|
18
|
6
|
|
|
6
|
|
59
|
use warnings; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
296
|
|
19
|
6
|
|
|
6
|
|
39
|
use parent qw( HTML::Object::DOM::Element ); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
55
|
|
20
|
6
|
|
|
6
|
|
553
|
use vars qw( $VERSION ); |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
376
|
|
21
|
6
|
|
|
6
|
|
73
|
use HTML::Object::DOM::Element::Shared qw( :script ); |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
1238
|
|
22
|
6
|
|
|
6
|
|
169
|
our $VERSION = 'v0.2.0'; |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
6
|
|
|
6
|
|
46
|
use strict; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
232
|
|
26
|
6
|
|
|
6
|
|
50
|
use warnings; |
|
6
|
|
|
|
|
24
|
|
|
6
|
|
|
|
|
2104
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub init |
29
|
|
|
|
|
|
|
{ |
30
|
10
|
|
|
10
|
1
|
833
|
my $self = shift( @_ ); |
31
|
10
|
|
|
|
|
873
|
$self->{_init_strict_use_sub} = 1; |
32
|
10
|
50
|
|
|
|
79
|
$self->SUPER::init( @_ ) || return( $self->pass_error ); |
33
|
10
|
50
|
|
|
|
63
|
$self->{tag} = 'script' if( !CORE::length( "$self->{tag}" ) ); |
34
|
10
|
|
|
|
|
106
|
return( $self ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Note: property async |
38
|
0
|
|
|
0
|
1
|
|
sub async : lvalue { return( shift->_set_get_property({ attribute => 'async', is_boolean => 1 }, @_ ) ); } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Note: property charset |
41
|
0
|
|
|
0
|
1
|
|
sub charset : lvalue { return( shift->_set_get_property( 'charset', @_ ) ); } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Note: property crossOrigin inherited |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Note: property defer |
46
|
0
|
|
|
0
|
1
|
|
sub defer : lvalue { return( shift->_set_get_property({ attribute => 'defer', is_boolean => 1 }, @_ ) ); } |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Note: property event |
49
|
0
|
|
|
0
|
1
|
|
sub event : lvalue { return( shift->_set_get_property( 'event', @_ ) ); } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Note: property noModule |
52
|
0
|
|
|
0
|
1
|
|
sub noModule : lvalue { return( shift->_set_get_property({ attribute => 'nomodule', is_boolean => 1 }, @_ ) ); } |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Note: property referrerPolicy inherited |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Note: property src inherited |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Note: property text |
59
|
0
|
|
|
0
|
1
|
|
sub text : lvalue { return( shift->textContent( @_ ) ); } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Note: property type inherited |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
# NOTE: POD |
65
|
|
|
|
|
|
|
__END__ |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=encoding utf-8 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
HTML::Object::DOM::Element::Script - HTML Object DOM Script Class |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
use HTML::Object::DOM::Element::Script; |
76
|
|
|
|
|
|
|
my $script = HTML::Object::DOM::Element::Script->new || |
77
|
|
|
|
|
|
|
die( HTML::Object::DOM::Element::Script->error, "\n" ); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 VERSION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
v0.2.0 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 DESCRIPTION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
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). |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 INHERITANCE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+ |
90
|
|
|
|
|
|
|
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Script | |
91
|
|
|
|
|
|
|
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 PROPERTIES |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Inherits properties from its parent L<HTML::Object::DOM::Element> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 async |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
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. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
There are three possible execution modes: |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over 4 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item 1. If the async attribute is present, then the script will be executed asynchronously as soon as it downloads. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=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. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item 3. If neither attribute is present, then the script is fetched and executed immediately, blocking further parsing of the page. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=back |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
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. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
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. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/async> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 charset |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Is a string representing the character encoding of an external script. It reflects the charset attribute. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/charset> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 crossOrigin |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Is a string reflecting the CORS setting for the script element. For scripts from other origins, this controls if error information will be exposed. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/crossOrigin> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 defer |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
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. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 event |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Is a string; an obsolete way of registering event handlers on elements in an HTML document. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/event> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 noModule |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
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. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/noModule> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 referrerPolicy |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Is a string that reflects the referrerpolicy HTML attribute indicating which referrer to use when fetching the script, and fetches done by that script. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Example: |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $scriptElem = $doc->createElement( 'script' ); |
154
|
|
|
|
|
|
|
$scriptElem->src = '/'; |
155
|
|
|
|
|
|
|
$scriptElem->referrerPolicy = 'unsafe-url'; |
156
|
|
|
|
|
|
|
$doc->body->appendChild( $scriptElem ); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/referrerPolicy> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 src |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
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. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/src> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 text |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
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. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
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. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/text> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 type |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Is a string representing the MIME type of the script. It reflects the type HTML attribute. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/type> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 METHODS |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Inherits methods from its parent L<HTML::Object::DOM::Element> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 AUTHOR |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 SEE ALSO |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
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> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Copyright(c) 2021 DEGUEST Pte. Ltd. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
All rights reserved |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |