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

filter: Statementstmt 58.0% 29 / 50 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 52.9% 9 / 17 Podpod 87.5% 7 / 8 totaltotal 50.0% 45 / 90 CC 7 SCAR 22.0
CC
7
Cov
46%
track
30.0
init
12.0
default
2.0
CRAP 9.0
« blib/lib/HTML/Object/XPath/Function.pm ↑ Summary lib/HTML/Object/XPath/Function.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Track.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::Track;
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( @EXPORT_OK %EXPORT_TAGS $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶ use HTML::Object::DOM::Element::Shared qw( :track );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 use constant {
24 # Indicates that the text track's cues have not been obtained.
25 1 NONE => 0,
26 # Indicates that the text track is loading and there have been no fatal errors encountered so far. Further cues might still be added to the track by the parser.
27 LOADING => 1,
28 # Indicates that the text track has been loaded with no fatal errors.
29 LOADED => 2,
30 # Indicates that the text track was enabled, but when the user agent attempted to obtain it, this failed in some way. Some or all of the cues are likely missing and will not be obtained.
31 ERROR => 3,
32 1 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 our @EXPORT_OK = qw( NONE LOADING LOADED ERROR );
34 1 our %EXPORT_TAGS = (
35 all => [qw( NONE LOADING LOADED ERROR )],
36 );
37 1 our $VERSION = 'v0.2.0';
38 };
39  
40 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 sub init
44 {
45 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=3 SCAR=24.8
Pod documented
46 0 $self->{_init_strict_use_sub} = 1;
47 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
48 0 ▶ $self->{tag} = 'track' if( !CORE::length( "$self->{tag}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length qq[$self->{"tag"}] 0 0 0
49 0 return( $self );
50 }
51  
52 # Note: property default
53 0 ▶sub default : lvalue { return( shift->_set_get_property( { attribute => 'default', is_boolean => 1 }, @_ ) ); }
Subroutine default: not called CC=1 SCAR=6.9
Pod documented
54  
55 # Note: property kind
56 0 ▶sub kind : lvalue { return( shift->_set_get_property( 'kind', @_ ) ); }
Subroutine kind: not called CC=1 SCAR=6.9
Pod documented
57  
58 # Note: property label
59 0 ▶sub label : lvalue { return( shift->_set_get_property( 'label', @_ ) ); }
Subroutine label: not called CC=1 SCAR=6.9
Pod documented
60  
61 0 ▶sub oncuechange : lvalue { return( shift->on( 'cuechange', @_ ) ); }
Subroutine oncuechange: not called CC=1 SCAR=6.9
Pod undocumented
62  
63 # Note: property readyState read-only
64 0 ▶sub readyState : lvalue { return( shift->_set_get_number( 'readystate', @_ ) ); }
Subroutine readyState: not called CC=1 SCAR=6.9
Pod documented
65  
66 # Note: property src is inherited
67  
68 # Note: property srclang
69 0 ▶sub srclang : lvalue { return( shift->_set_get_property( 'srclang', @_ ) ); }
Subroutine srclang: not called CC=1 SCAR=6.9
Pod documented
70  
71 # Note: property track read-only
72 sub track
73 {
74 0 ▶ my $self = shift( @_ );
Subroutine track: not called CC=5 SCAR=34.0
Pod documented
75 0 ▶ return( $self->{track} ) if( defined( $self->{track} ) && ref( $self->{track} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"track"} and ref $self->{"track"} 0 0 0
Condition0%0/3
defined $self->{"track"} and ref $self->{"track"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"track"} and ref $self->{"track"}
defined $self->{"track"} ref $self->{"track"}
Truth table0%0/3
A and B
A= defined $self->{"track"}B= ref $self->{"track"}
ABresult
0X0
100
111
76 0 ▶ $self->_load_class( 'HTML::Object::DOM::TextTrack' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::TextTrack") or return $self->pass_error 0 0 0
77 0 my $kind = $self->kind;
78 0 my $label = $self->label;
79 0 my $lang = $self->srclang;
80 0 my $track = HTML::Object::DOM::TextTrack->new( $kind, $label, $lang,
81 {
82 id => $self->id,
83 debug => $self->debug,
84 });
85 0 ▶ return( $self->pass_error( HTML::Object::DOM::TextTrack->error ) ) if( !defined( $track ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $track 0 0 0
86 0 $track->parent( $self );
87 0 return( $self->{track} = $track );
88 }
89  
90 1 1;
91 # NOTE: POD
92 __END__
93  
94 =encoding utf-8
95  
96 =head1 NAME
97  
98 HTML::Object::DOM::Element::Track - HTML Object DOM Track Class
99  
100 =head1 SYNOPSIS
101  
102 use HTML::Object::DOM::Element::Track;
103 my $track = HTML::Object::DOM::Element::Track->new ||
104 die( HTML::Object::DOM::Element::Track->error, "\n" );
105  
106 my $video = $doc->getElementsByTagName('video')->[0];
107 # or
108 my $video = $doc->createElement('video');
109 $video->controls = 1; # true
110 # Source 1
111 my $source1 = $doc->createElement('source');
112 $source1->src = 'https://example.org/some/where/videos/video.webm';
113 # Source 2
114 my $source2 = $doc->createElement('source');
115 $source2->src = 'https://example.org/some/where/videos/video.mp4';
116 # Track 1
117 my $track1 = $doc->createElement('track');
118 $track1->kind = 'subtitles';
119 $track1->src = 'subtitles-en.vtt';
120 $track1->label = 'English captions';
121 $track1->srclang = 'en';
122 $track1->type = 'text/vtt';
123 $track1->default = 1; # true
124 # Track 2
125 my $track2 = $doc->createElement('track');
126 $track2->kind = 'subtitles';
127 $track2->src = 'subtitles-fr.vtt';
128 $track2->label = 'Sous-titres Français';
129 $track2->srclang = 'fr';
130 $track2->type = 'text/vtt';
131 # Track 3
132 my $track3 = $doc->createElement('track');
133 $track3->kind = 'subtitles';
134 $track3->src = 'subtitles-ja.vtt';
135 $track3->label = '日本語字幕';
136 $track3->srclang = 'ja'";
137 $track3->type = 'text/vtt';
138 # Append everything
139 $video->appendChild( $source1 );
140 $video->appendChild( $source2 );
141 $video->appendChild( $track1 );
142 $video->appendChild( $track2 );
143 $video->appendChild( $track3 );
144 my $p = $doc->createElement('p');
145 $p->textContent = q{This browser does not support the video element.};
146 $video->appendChild( $p );
147  
148 <video controls="">
149 <source src="https://example.org/some/where/videos/video.webm" type="video/webm" />
150 <source src="https://example.org/some/where/videos/video.mp4" type="video/mp4" />
151 <track src="subtitles-en.vtt" label="English captions" kind="subtitles" srclang="en" default />
152 <track src="subtitles-fr.vtt" label="Sous-titres Français" kind="subtitles" srclang="fr" />
153 <track src="subtitles-ja.vtt" label="日本語字幕" kind="subtitles" srclang="ja" />
154 <p>This browser does not support the video element.</p>
155 </video>
156  
157 =head1 VERSION
158  
159 v0.2.0
160  
161 =head1 DESCRIPTION
162  
163 This interface represents an HTML C<<track>> element within the DOM. This element can be used as a child of either C<<audio>> or C<<video>> to specify a text track containing information such as closed captions or subtitles.
164  
165 =head1 INHERITANCE
166  
167 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
168 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Track |
169 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
170  
171 =head1 PROPERTIES
172  
173 Inherits properties from its parent L<HTML::Object::DOM::Element>
174  
175 =head2 default
176  
177 A boolean value reflecting the C<default> attribute, indicating that the track is to be enabled if the user's preferences do not indicate that another track would be more appropriate.
178  
179 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement/default>
180  
181 =head2 kind
182  
183 Is a string that reflects the C<kind> HTML attribute, indicating how the text track is meant to be used. Possible values are: subtitles, captions, descriptions, chapters, or metadata.
184  
185 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement/kind>
186  
187 =head2 label
188  
189 Is a string that reflects the C<label> HTML attribute, indicating a user-readable title for the track.
190  
191 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement/label>
192  
193 =head2 readyState
194  
195 Returns an unsigned short that show the readiness state of the track. Below are the possible constant values.
196 You can export and use those constants by calling either of the following:
197  
198 use HTML::Object::DOM::Element::Track qw( :all );
199 # or
200 use HTML::Object::DOM qw( :track );
201  
202 See L</CONSTANTS> for the constants that can be exported and used.
203  
204 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement/readyState>
205  
206 =head2 src
207  
208 Is a string that reflects the src HTML attribute, indicating the address of the text track data.
209  
210 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement/src>
211  
212 =head2 srclang
213  
214 Is a string that reflects the srclang HTML attribute, indicating the language of the text track data.
215  
216 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement/srclang>
217  
218 =head2 track
219  
220 Returns C<TextTrack> is the track element's text track data.
221  
222 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement/track>
223  
224 =head1 METHODS
225  
226 Inherits methods from its parent L<HTML::Object::DOM::Element>
227  
228 =head1 EVENTS
229  
230 Event listeners for those events can also be found by prepending C<on> before the event type:
231  
232 For example, C<cuechange> event listeners can be set also with C<oncuechange> method:
233  
234 $e->oncuechange(sub{ # do something });
235 # or as an lvalue method
236 $e->oncuechange = sub{ # do something };
237  
238 =head2 cuechange
239  
240 Under perl, this event is not triggered obviously, but you can trigger it yourself.
241  
242 Under JavaScript, this is sent when the underlying L<TextTrack|HTML::Object::DOM::TextTrack> has changed the currently-presented cues. This event is always sent to the L<TextTrack|HTML::Object::DOM::TextTrack> but is also sent to the L<HTML::Object::DOM::Element::Track> if one is associated with the track.
243 You may also use the C<oncuechange> event handler to establish a handler for this event.
244  
245 Example:
246  
247 $track->addEventListener( cuechange => sub
248 {
249 my $cues = $track->activeCues; # array of current $cues
250 });
251  
252 $track->oncuechange = sub
253 {
254 my $cues = $track->activeCues; # array of current $cues
255 }
256  
257 Another example:
258  
259 my $textTrackElem = $doc->getElementById( 'texttrack' );
260  
261 $textTrackElem->addEventListener( cuechange => sub
262 {
263 my $cues = $event->target->track->activeCues;
264 });
265  
266 or
267  
268 $textTrackElem->oncuechange = sub
269 {
270 my $cues = $_->target->track->activeCues;
271 });
272  
273 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement/cuechange_event>
274  
275 =head1 CONSTANTS
276  
277 The following constants can be exported and used, such as:
278  
279 use HTML::Object::DOM::Element::Track qw( :all );
280 # or directly from HTML::Object::DOM
281 use HTML::Object::DOM qw( :track );
282  
283 =over 4
284  
285 =item NONE (0)
286  
287 Indicates that the text track's cues have not been obtained.
288  
289 =item LOADING (1)
290  
291 Indicates that the text track is loading and there have been no fatal errors encountered so far. Further cues might still be added to the track by the parser.
292  
293 =item LOADED (2)
294  
295 Indicates that the text track has been loaded with no fatal errors.
296  
297 =item ERROR (3)
298  
299 Indicates that the text track was enabled, but when the user agent attempted to obtain it, this failed in some way. Some or all of the cues are likely missing and will not be obtained.
300  
301 =back
302  
303 =head1 AUTHOR
304  
305 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
306  
307 =head1 SEE ALSO
308  
309 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement>, L<Mozilla documentation on track element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track>
310  
311 =head1 COPYRIGHT & LICENSE
312  
313 Copyright(c) 2021 DEGUEST Pte. Ltd.
314  
315 All rights reserved
316  
317 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
318  
319 =cut
« blib/lib/HTML/Object/XPath/Function.pm ↑ Summary lib/HTML/Object/XPath/Function.pm »