File Coverage

lib/HTML/Object/DOM/TrackEvent.pm
Criterion Covered Total %
statement 19 24 79.1
branch 0 2 0.0
condition n/a
subroutine 7 9 77.7
pod 2 2 100.0
total 28 37 75.6


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## HTML Object - ~/lib/HTML/Object/DOM/TrackEvent.pm
3             ## Version v0.2.0
4             ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2021/12/29
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::TrackEvent;
15             BEGIN
16             {
17 1     1   6 use strict;
  1         4  
  1         41  
18 1     1   5 use warnings;
  1         3  
  1         30  
19 1     1   8 use parent qw( HTML::Object::Event );
  1         2  
  1         7  
20 1     1   74 use vars qw( $VERSION );
  1         2  
  1         61  
21 1     1   19 our $VERSION = 'v0.2.0';
22             };
23              
24 1     1   6 use strict;
  1         2  
  1         19  
25 1     1   5 use warnings;
  1         2  
  1         111  
26              
27             sub init
28             {
29 0     0 1   my $self = shift( @_ );
30 0           $self->{_init_strict_use_sub} = 1;
31 0 0         $self->SUPER::init( @_ ) || return( $self->pass_error );
32 0           return( $self );
33             }
34              
35             # Note: property read-only
36 0     0 1   sub track { return( shift->_set_get_object_without_init( 'track', '', @_ ) ); }
37              
38             1;
39             # NOTE: POD
40             __END__
41              
42             =encoding utf-8
43              
44             =head1 NAME
45              
46             HTML::Object::DOM::TrackEvent - HTML Object DOM Track Event
47              
48             =head1 SYNOPSIS
49              
50             use HTML::Object::DOM::TrackEvent;
51             my $event = HTML::Object::DOM::TrackEvent->new( $type ) ||
52             die( HTML::Object::DOM::TrackEvent->error, "\n" );
53              
54             =head1 VERSION
55              
56             v0.2.0
57              
58             =head1 DESCRIPTION
59              
60             The C<TrackEvent> interface, which is part of the HTML DOM specification, is used for events which represent changes to a set of available tracks on an HTML L<media element|HTML::Object::DOM::Element::Media>; these events are C<addtrack> and C<removetrack>.
61              
62             Events based on TrackEvent are always sent to one of the media track list types:
63              
64             =over 4
65              
66             =item * Events involving video tracks are always sent to the L<VideoTrackList|HTML::Object::DOM::VideoTrackList> found in L<HTML::Object::DOM::Element::Media/videoTracks>
67              
68             =item * Events involving audio tracks are always sent to the L<AudioTrackList|HTML::Object::DOM::AudioTrackList> specified in L<HTML::Object::DOM::Element::Media/audioTracks>
69              
70             =item * Events affecting text tracks are sent to the L<TextTrackList object|HTML::Object::DOM::TextTrackList> indicated by L<HTML::Object::DOM::Element::Media/textTracks>.
71              
72             =back
73              
74             =head1 INHERITANCE
75              
76             +---------------------+ +-------------------------------+
77             | HTML::Object::Event | --> | HTML::Object::DOM::TrackEvent |
78             +---------------------+ +-------------------------------+
79              
80             =head1 PROPERTIES
81              
82             TrackEvent is based on L<Event|HTML::Object::Event>, so properties of L<Event|HTML::Object::Event> are also available on C<TrackEvent> objects.
83              
84             =head2 track
85              
86             Read-only.
87              
88             This is a DOM track object this event is in reference to. If not C<undef>, this is always an object of one of the media track types: L<AudioTrack|HTML::Object::DOM::AudioTrack>, L<VideoTrack|HTML::Object::DOM::VideoTrack>, or L<TextTrack|HTML::Object::DOM::TextTrack>).
89              
90             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TrackEvent/track>
91              
92             =head1 METHODS
93              
94             TrackEvent has no methods of its own; however, it is based on L<Event|HTML::Object::Event>, so it provides the methods available on L<Event|HTML::Object::Event> objects.
95              
96             =head1 EXAMPLE
97              
98             my $videoElem = $doc->querySelector( 'video' );
99              
100             $videoElem->videoTracks->addEventListener( 'addtrack', \&handleTrackEvent, { capture => 0 });
101             $videoElem->videoTracks->addEventListener( 'removetrack', \&handleTrackEvent, { capture => 0 });
102             $videoElem->audioTracks->addEventListener( 'addtrack', \&handleTrackEvent, { capture => 0 });
103             $videoElem->audioTracks->addEventListener( 'removetrack', \&handleTrackEvent, { capture => 0 });
104             $videoElem->textTracks->addEventListener( 'addtrack', \&handleTrackEvent, { capture => 0 });
105             $videoElem->textTracks->addEventListener( 'removetrack', \&handleTrackEvent, { capture => 0 });
106              
107             sub handleTrackEvent
108             {
109             my $event = shift( @_ );
110             my $trackKind;
111              
112             if( $event->target->isa( 'HTML::Object::DOM::VideoTrackList' ) )
113             {
114             $trackKind = 'video';
115             }
116             elsif( $event->target->isa( 'HTML::Object::DOM::AudioTrackList' ) )
117             {
118             $trackKind = 'audio';
119             }
120             elsif( $event->target->isa( 'HTML::Object::DOM::TextTrackList' ) )
121             {
122             $trackKind = 'text';
123             }
124             else
125             {
126             $trackKind = 'unknown';
127             }
128              
129             my $type = $event->type;
130             if( $type eq 'addtrack' )
131             {
132             say( "Added a $trackKind track" );
133             }
134             elsif( $type eq 'removetrack' )
135             {
136             say( "Removed a $trackKind track" );
137             }
138             }
139              
140             =head1 AUTHOR
141              
142             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
143              
144             =head1 SEE ALSO
145              
146             L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/TrackEvent>
147              
148             =head1 COPYRIGHT & LICENSE
149              
150             Copyright(c) 2021 DEGUEST Pte. Ltd.
151              
152             All rights reserved
153              
154             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
155              
156             =cut