lib/HTML/Object/DOM/VTTCue.pm

filter: Statementstmt 42.8% 24 / 56 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 36.3% 8 / 22 Podpod 100% 14 / 14 totaltotal 43.8% 46 / 105 CC 7 SCAR 20.5
CC
7
Cov
35%
init
30.0
getCueAsHTML
12.0
align
2.0
CRAP 7.8
« lib/HTML/Object/DOM/Element/Progress.pm ↑ Summary blib/lib/HTML/Object/DOM/TextTrackCueList.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/VTTCue.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/27
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::VTTCue;
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::TextTrackCue );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶ use HTML::Object::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 our $VERSION = 'v0.2.0';
24 };
25  
26 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 sub init
30 {
31 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=5 SCAR=34.0
Pod documented
32 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ < 3 0 0 0
33 message => sprintf( "At least 3 arguments required, but only %d passed", scalar( @_ ) ),
34 class => 'HML::Object::TypeError',
35 }) ) if( scalar( @_ ) < 3 );
36 0 my $start = shift( @_ );
37 0 my $end = shift( @_ );
38 0 my $text = shift( @_ );
39 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_number($start) 0 0 0
40 message => "start argument provided is not a number",
41 class => 'HML::Object::TypeError',
42 }) ) if( !$self->_is_number( $start ) );
43 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_number($end) 0 0 0
44 message => "end argument provided is not a number",
45 class => 'HML::Object::TypeError',
46 }) ) if( !$self->_is_number( $end ) );
47 0 $self->{positionalign} = 'auto';
48 0 $self->{startTime} = $start;
49 0 $self->{endTime} = $end;
50 0 $self->{text} = $text;
51 0 $self->{_init_strict_use_sub} = 1;
52 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
53 0 return( $self );
54 }
55  
56 # Note: property
57 0 ▶sub align : lvalue { return( shift->_set_get_scalar_as_object( 'align', @_ ) ); }
Subroutine align: not called CC=1 SCAR=6.9
Pod documented
58  
59 0 ▶sub endTime : lvalue { return( shift->_set_get_scalar_as_object( 'endTime', @_ ) ); }
Subroutine endTime: not called CC=1 SCAR=6.9
Pod documented
60  
61 sub getCueAsHTML
62 {
63 0 ▶ my $self = shift( @_ );
Subroutine getCueAsHTML: not called CC=3 SCAR=24.8
Pod documented
64 0 ▶ $self->_load_class( 'HTML::Object::DOM::DocumentFragment' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::DocumentFragment") or return $self->pass_error 0 0 0
65 0 my $frag = HTML::Object::DOM::DocumentFragment->new;
66 0 ▶ my $text = $frag->new_text( value => $self->{text} ) || return( $self->pass_error( $frag->error ) );
Condition0%0/2
$frag->new_text('value', $self->{'text'}) || (return $self->pass_error($frag->error))
l!l
00
MC/DC0%0/1
$frag->new_text('value', $self->{'text'}) || (return $self->pass_error($frag->error))
$frag->new_text('value', $self->{'text'})
Truth table0%0/2
A
A= $frag->new_text('value', $self->{'text'})
Aresult
11
00
67 0 $frag->appendChild( $text );
68 0 return( $frag );
69 }
70  
71 # Note: property
72 0 ▶sub line : lvalue { return( shift->_set_get_scalar_as_object( 'line', @_ ) ); }
Subroutine line: not called CC=1 SCAR=6.9
Pod documented
73  
74 # Note: property
75 0 ▶sub lineAlign : lvalue { return( shift->_set_get_scalar_as_object( 'linealign', @_ ) ); }
Subroutine lineAlign: not called CC=1 SCAR=6.9
Pod documented
76  
77 # Note: property
78 0 ▶sub position : lvalue { return( shift->_set_get_scalar_as_object( 'position', @_ ) ); }
Subroutine position: not called CC=1 SCAR=6.9
Pod documented
79  
80 # Note: property
81 0 ▶sub positionAlign : lvalue { return( shift->_set_get_scalar_as_object( 'positionalign', @_ ) ); }
Subroutine positionAlign: not called CC=1 SCAR=6.9
Pod documented
82  
83 # Note: property
84 0 ▶sub region : lvalue { return( shift->_set_get_object_without_init( 'region', 'HTML::Object::DOM::VTTRegion', @_ ) ); }
Subroutine region: not called CC=1 SCAR=6.9
Pod documented
85  
86 # Note: property
87 0 ▶sub size : lvalue { return( shift->_set_get_number( 'size', @_ ) ); }
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
88  
89 # Note: property
90 0 ▶sub snapToLines : lvalue { return( shift->_set_get_boolean( 'snaptolines', @_ ) ); }
Subroutine snapToLines: not called CC=1 SCAR=6.9
Pod documented
91  
92 0 ▶sub startTime : lvalue { return( shift->_set_get_scalar_as_object( 'startTime', @_ ) ); }
Subroutine startTime: not called CC=1 SCAR=6.9
Pod documented
93  
94 # Note: property
95 0 ▶sub text : lvalue { return( shift->_set_get_scalar_as_object( 'text', @_ ) ); }
Subroutine text: not called CC=1 SCAR=6.9
Pod documented
96  
97 # Note: property
98 0 ▶sub vertical : lvalue { return( shift->_set_get_scalar_as_object( 'vertical', @_ ) ); }
Subroutine vertical: not called CC=1 SCAR=6.9
Pod documented
99  
100 1 1;
101 # NOTE: POD
102 __END__
103  
104 =encoding utf-8
105  
106 =head1 NAME
107  
108 HTML::Object::DOM::VTTCue - HTML Object DOM VTTCue Class
109  
110 =head1 SYNOPSIS
111  
112 use HTML::Object::DOM::VTTCue;
113 my $cue = HTML::Object::DOM::VTTCue->new ||
114 die( HTML::Object::DOM::VTTCue->error, "\n" );
115  
116 <video controls src="https://example.org/some/where/media/video.mp4"></video>
117  
118 my $video = $doc->querySelector('video');
119 my $track = $video->addTextTrack("captions", "Captions", "en");
120 $track->mode = 'showing';
121 $track->addCue( new HTML::Object::DOM::VTTCue( 0, 0.9, 'Hildy!') ) ;
122 $track->addCue( new HTML::Object::DOM::VTTCue( 1, 1.4, 'How are you?' ) );
123 $track->addCue( new HTML::Object::DOM::VTTCue( 1.5, 2.9, 'Tell me, is the lord of the universe in?' ) );
124 $track->addCue( new HTML::Object::DOM::VTTCue( 3, 4.2, 'Yes, he\'s in - in a bad humor' ) );
125 $track->addCue( new HTML::Object::DOM::VTTCue( 4.3, 6, 'Somebody must\'ve stolen the crown jewels' ) );
126 say( $track->cues );
127  
128 =head1 VERSION
129  
130 v0.2.0
131  
132 =head1 DESCRIPTION
133  
134 This implements a C<VTTCue> object representing a cue which will be presented during the time span given.
135  
136 The C<VTTCue> interface-part of the Web API for handling C<WebVTT> (text tracks on media presentations)-describes and controls the text track associated with a particular L<<track> element|HTML::Object::DOM::Element::Track>.
137  
138 =head1 INHERITANCE
139  
140 +---------------------------------+ +---------------------------+
141 | HTML::Object::DOM::TextTrackCue | --> | HTML::Object::DOM::VTTCue |
142 +---------------------------------+ +---------------------------+
143  
144 =head1 CONSTRUCTOR
145  
146 =head2 new
147  
148 C<VTTCue> takes 3 parameters: C<startTime>, C<endTime> and C<text>
149  
150 =over 4
151  
152 =item startTime
153  
154 This is a double representing the initial text track cue start time. This is the time, given in seconds and fractions of a second, denoting the beginning of the range of the media data to which this cue applies. For example, if a cue is to be visible from 50 seconds to a one minute, five and a half seconds in the media's playback, C<startTime> will be 50.0.
155 C<endTime>
156  
157 =item endTime
158  
159 This is a double representing the ending time for this text track cue. This is the time at which the cue should stop being presented to the user, given in seconds and fractions thereof. Given the example cue mentioned under C<startTime>, the value of C<endTime> would be 65.5.
160 text
161  
162 =item text
163  
164 A string providing the text that will be shown during the time span indicated by C<startTime> and C<endTime>.
165  
166 =back
167  
168 =head1 PROPERTIES
169  
170 =head2 align
171  
172 Returns an enum representing the alignment of all the lines of text within the cue box.
173  
174 Example:
175  
176 my $video = $doc->querySelector('video');
177 my $track = $video->addTextTrack("captions", "Captions", "en");
178 $track->mode = "showing";
179  
180 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
181 $cue1->align = 'start';
182 say( $cue1->align );
183  
184 $track->addCue( $cue1 );
185  
186 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/align>
187  
188 =head2 endTime
189  
190 This is a double representing the ending time for this text track cue. This is the time at which the cue should stop being presented to the user, given in seconds and fractions thereof. Given the example cue mentioned under C<startTime>, the value of C<endTime> would be 65.5.
191 text
192  
193 =head2 line
194  
195 Returns the line positioning of the cue. This can be the string C<auto> or a number whose interpretation depends on the value of L</snapToLines>.
196  
197 Example:
198  
199 my $video = $doc->querySelector('video');
200 my $track = $video->addTextTrack("captions", "Captions", "en");
201 $track->mode = "showing";
202  
203 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
204 $cue1->line = '1';
205 say( $cue1->line );
206  
207 $track->addCue( $cue1 );
208  
209 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/line>
210  
211 =head2 lineAlign
212  
213 Returns an enum representing the alignment of the L</line>.
214  
215 Example:
216  
217 my $video = $doc->querySelector('video');
218 my $track = $video->addTextTrack("captions", "Captions", "en");
219 $track->mode = "showing";
220  
221 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
222 $cue1->lineAlign = 'center';
223 say( $cue1->lineAlign );
224  
225 $track->addCue( $cue1 );
226  
227 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/lineAlign>
228  
229 =head2 position
230  
231 Returns the indentation of the cue within the line. This can be the string C<auto> or a number representing the percentage of the L</region>, or the video size if L</region> is C<undef>.
232  
233 Example:
234  
235 my $video = $doc->querySelector('video');
236 my $track = $video->addTextTrack("captions", "Captions", "en");
237 $track->mode = "showing";
238  
239 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
240 $cue1->position = '2';
241 say( $cue1->position );
242  
243 $track->addCue( $cue1 );
244  
245 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/position>
246  
247 =head2 positionAlign
248  
249 Returns an enum representing the alignment of the cue. This is used to determine what the L</position> is anchored to. The default is C<auto>.
250  
251 Example:
252  
253 my $video = $doc->querySelector('video');
254 my $track = $video->addTextTrack("captions", "Captions", "en");
255 $track->mode = "showing";
256  
257 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
258 $cue1->positionAlign = 'line-right';
259 say( $cue1->positionAlign );
260  
261 $track->addCue( $cue1 );
262  
263 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/positionAlign>
264  
265 =head2 region
266  
267 A L<VTTRegion|HTML::Object::DOM::VTTRegion> object describing the video's sub-region that the cue will be drawn onto, or C<undef> if none is assigned.
268  
269 Example:
270  
271 my $video = $doc->querySelector('video');
272 my $track = $video->addTextTrack("captions", "Captions", "en");
273 $track->mode = "showing";
274  
275 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
276 say( $cue1->region );
277  
278 $track->addCue( $cue1 );
279  
280 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/region>
281  
282 =head2 size
283  
284 Returns a double representing the size of the cue, as a percentage of the video size.
285  
286 Example:
287  
288 my $video = $doc->querySelector('video');
289 my $track = $video->addTextTrack("captions", "Captions", "en");
290 $track->mode = "showing";
291  
292 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
293 $cue1->size = 50;
294 say( $cue1->size );
295  
296 $track->addCue( $cue1 );
297  
298 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/size>
299  
300 =head2 snapToLines
301  
302 Returns true if the L</line> attribute is an integer number of lines or a percentage of the video size.
303  
304 Example:
305  
306 my $video = $doc->querySelector('video');
307 my $track = $video->addTextTrack("captions", "Captions", "en");
308 $track->mode = "showing";
309  
310 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
311 $cue1->snapToLines = 1; # true
312 say( $cue1->snapToLines );
313  
314 $track->addCue( $cue1 );
315  
316 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/snapToLines>
317  
318 =head2 startTime
319  
320 This is a double representing the initial text track cue start time. This is the time, given in seconds and fractions of a second, denoting the beginning of the range of the media data to which this cue applies. For example, if a cue is to be visible from 50 seconds to a one minute, five and a half seconds in the media's playback, C<startTime> will be 50.0.
321 C<endTime>
322  
323 =head2 text
324  
325 Returns a string with the contents of the cue.
326  
327 Example:
328  
329 my $video = $doc->querySelector('video');
330 my $track = $video->addTextTrack("captions", "Captions", "en");
331 $track->mode = "showing";
332  
333 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
334 $cue1->text = 'new cue value';
335 say( $cue1->text ) # 'new cue value';
336  
337 $track->addCue( $cue1 );
338  
339 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/text>
340  
341 =head2 vertical
342  
343 Returns an enum representing the cue writing direction.
344  
345 Example:
346  
347 my $video = $doc->querySelector('video');
348 my $track = $video->addTextTrack("captions", "Captions", "en");
349 $track->mode = "showing";
350  
351 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
352 $cue1->vertical = 'rl';
353 say( $cue1->vertical );
354  
355 $track->addCue( $cue1 );
356  
357 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/vertical>
358  
359 =head1 METHODS
360  
361 Inherits methods from its parent L<HTML::Object::Element>
362  
363 =head2 getCueAsHTML
364  
365 Returns the cue text as a L<HTML::Object::DOM::DocumentFragment>.
366  
367 Example:
368  
369 my $video = $doc->querySelector('video');
370 my $track = $video->addTextTrack("captions", "Captions", "en");
371 $track->mode = "showing";
372  
373 my $cue1 = HTML::Object::DOM::VTTCue->new( 0, 0.9, 'Hildy!' );
374 say( $cue1->getCueAsHTML() );
375  
376 $track->addCue( $cue1 );
377  
378 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/getCueAsHTML>
379  
380 =head1 AUTHOR
381  
382 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
383  
384 =head1 SEE ALSO
385  
386 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VTTCue>, L<W3C specifications|https://www.w3.org/TR/webvtt1/>, L<Specifications|https://w3c.github.io/webvtt/#the-vttcue-interface>
387  
388 =head1 COPYRIGHT & LICENSE
389  
390 Copyright(c) 2021 DEGUEST Pte. Ltd.
391  
392 All rights reserved
393  
394 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
395  
396 =cut
« lib/HTML/Object/DOM/Element/Progress.pm ↑ Summary blib/lib/HTML/Object/DOM/TextTrackCueList.pm »