blib/lib/HTML/Object/DOM/VideoTrack.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 74 CC 4 SCAR 15.5
CC
4
Cov
0%
init
12.0
selected
6.0
BEGIN
2.0
CRAP 4.7
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/VideoTrack.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/28
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::VideoTrack;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( HTML::Object::EventTarget );
21 use vars qw( $VERSION );
22 use HTML::Object::Exception;
23 our $VERSION = 'v0.2.0';
24 };
25  
26 use strict;
27 use warnings;
28  
29 sub init
30 {
31 my $self = shift( @_ );
32 return( $self->error({
33 message => sprintf( "At least 1 argument required, but only %d passed", scalar( @_ ) ),
34 class => 'HML::Object::TypeError',
35 }) ) if( scalar( @_ ) < 3 );
36 my $kind = shift( @_ );
37 my $label = shift( @_ );
38 my $lang = shift( @_ );
39 return( $self->error({
40 message => "kind argument provided is not a string",
41 class => 'HML::Object::TypeError',
42 }) ) if( $kind !~ /^\w+$/ );
43 # If set, this should be the same as the id in HTML::Object::DOM::Element::Track
44 $self->{id} = undef;
45 $self->{kind} = $kind;
46 $self->{label} = $label;
47 $self->{language} = $lang;
48 $self->{_init_strict_use_sub} = 1;
49 $self->SUPER::init( @_ ) || return( $self->pass_error );
50 return( $self );
51 }
52  
53 # Note: property id inherited
54  
55 # Note: property kind inherited
56  
57 # Note: property label inherited
58  
59 # Note: property language inherited
60  
61 # Note: property
62 sub selected : lvalue { return( shift->_set_get_boolean({
63 field => 'selected',
64 callbacks =>
65 {
66 add => sub
67 {
68 my $me = shift( @_ );
69 my $parent;
70 if( ( $parent = $me->parent ) && ( my $coderef = $parent->can( '_update_selected' ) ) )
71 {
72 $coderef->( $parent, $me );
73 }
74 }
75 }
76 }, @_ ) ); }
77  
78 # Note: property
79 sub sourceBuffer { return; }
80  
81 1;
82 # NOTE: POD
83 __END__
84  
85 =encoding utf-8
86  
87 =head1 NAME
88  
89 HTML::Object::DOM::VideoTrack - HTML Object DOM VideoTrack Class
90  
91 =head1 SYNOPSIS
92  
93 use HTML::Object::DOM::VideoTrack;
94 my $track = HTML::Object::DOM::VideoTrack->new ||
95 die( HTML::Object::DOM::VideoTrack->error, "\n" );
96  
97 =head1 VERSION
98  
99 v0.2.0
100  
101 =head1 DESCRIPTION
102  
103 The C<VideoTrack> interface represents a single video track from a <video> element.
104  
105 To get a C<VideoTrack> for a given media element, use the element's L<videoTracks|HTML::Object::DOM::Element::Media/videoTracks> property, which returns a L<VideoTrackList|HTML::Object::DOM::VideoTrackList> object from which you can get the individual tracks contained in the media:
106  
107 my $el = $doc->querySelector('video');
108 my $tracks = $el->videoTracks;
109 my $firstTrack = $tracks->[0];
110  
111 Scan through all of the media's video tracks, activating the first video track that is in the user's preferred language (taken from a variable userLanguage).
112  
113 for( my $i = 0; $i < $tracks->length; $i++ )
114 {
115 if( $tracks->[$i]->language eq $userLanguage )
116 {
117 $tracks->[$i]->selected = 1; # true
118 last;
119 }
120 });
121  
122 =head1 INHERITANCE
123  
124 +-----------------------+ +---------------------------+ +-------------------------------+
125 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::VideoTrack |
126 +-----------------------+ +---------------------------+ +-------------------------------+
127  
128 =head1 PROPERTIES
129  
130 Inherits properties from its parent L<HTML::Object::EventTarget>
131  
132 =head2 id
133  
134 Sets or gets a string which uniquely identifies the track within the media. This ID can be used to locate a specific track within a video track list by calling C<VideoTrackList>.getTrackById(). The ID can also be used as the fragment part of the URL if the media supports seeking by media fragment per the Media Fragments URI specification.
135  
136 Returns the ID as a L<scalar object|Module::Generic::Scalar>
137  
138 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VideoTrack/id>
139  
140 =head2 kind
141  
142 A string specifying the category into which the track falls. For example, the main video track would have a kind of C<main>.
143  
144 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VideoTrack/kind>
145  
146 =head2 label
147  
148 A string providing a human-readable label for the track. For example, a track whose kind is C<sign> might have a label of "A sign-language interpretation". This string is empty if no label is provided.
149  
150 Example:
151  
152 use Module::Generic::Array;
153 sub getTrackList
154 {
155 my $el = shift( @_ );
156 my $trackList = Module::Generic::Array->new;
157 my $wantedKinds = [qw( main alternative commentary )];
158  
159 $el->videoTracks->forEach(sub
160 {
161 my $track = shift( @_ );
162 if( $wantedKinds->includes( $track->kind ) )
163 {
164 $trackList->push({
165 id => $track->id,
166 kind => $track->kind,
167 label => $track->label
168 });
169 }
170 });
171 return( $trackList );
172 }
173  
174 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VideoTrack/label>
175  
176 =head2 language
177  
178 A string specifying the video track's primary language, or an empty string if unknown. The language is specified as a BCP 47 (L<RFC 5646|https://datatracker.ietf.org/doc/html/rfc5646>) language code, such as C<en-US> or C<ja-JP>.
179  
180 Returns the language as a L<scalar object|Module::Generic::Scalar>
181  
182 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VideoTrack/language>
183  
184 =head2 selected
185  
186 A boolean value which controls whether or not the video track is active. Only a single video track can be active at any given time, so setting this property to true for one track while another track is active will make that other track inactive.
187  
188 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VideoTrack/selected>
189  
190 =head2 sourceBuffer
191  
192 This always returns C<undef> under perl.
193  
194 Normally, under JavaScript, this is the C<SourceBuffer> that created the track. Returns C<undef> if the track was not created by a C<SourceBuffer> or the C<SourceBuffer> has been removed from the C<MediaSource.sourceBuffers> attribute of its parent media source.
195  
196 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VideoTrack/sourceBuffer>
197  
198 =head1 METHODS
199  
200 Inherits methods from its parent L<HTML::Object::EventTarget>
201  
202 =head1 AUTHOR
203  
204 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
205  
206 =head1 SEE ALSO
207  
208 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/VideoTrack>
209  
210 =head1 COPYRIGHT & LICENSE
211  
212 Copyright(c) 2021 DEGUEST Pte. Ltd.
213  
214 All rights reserved
215  
216 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
217  
218 =cut