| 1 | ##---------------------------------------------------------------------------- | ||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/TextTrack.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::TextTrack; | ||
| 15 | BEGIN | ||
| 16 | { | ||
| 17 | use strict; | ||
| 18 | use warnings; | ||
| 19 | warnings::register_categories( 'HTML::Object' ); | ||
| 20 | use parent qw( HTML::Object::DOM::MediaTrack ); | ||
| 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 | $self->{cues} = []; | ||
| 44 | # If set, this should be the same as the id in HTML::Object::DOM::Element::Track | ||
| 45 | $self->{id} = undef; | ||
| 46 | $self->{kind} = $kind; | ||
| 47 | $self->{label} = $label; | ||
| 48 | $self->{language} = $lang; | ||
| 49 | $self->{mode} = 'hidden'; | ||
| 50 | $self->{_init_strict_use_sub} = 1; | ||
| 51 | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||
| 52 | return( $self ); | ||
| 53 | } | ||
| 54 | |||
| 55 | # Note: property | ||
| 56 | sub activeCues { return( shift->_set_get_object( 'activecues', 'HTML::Object::DOM::TextTrackCueList', @_ ) ); } | ||
| 57 | |||
| 58 | sub addCue | ||
| 59 | { | ||
| 60 | my $self = shift( @_ ); | ||
| 61 | my $cue = shift( @_ ) || return( $self->error({ | ||
| 62 | message => "No cue object was provided.", | ||
| 63 | class => 'HTML::Object::TypeError', | ||
| 64 | }) ); | ||
| 65 | # HTML::Object::DOM::VTTCue inherits from HTML::Object::DOM::TextTrackCue | ||
| 66 | return( $self->error({ | ||
| 67 | message => "Cue provided is not a HTML::Object::DOM::TextTrackCue object.", | ||
| 68 | class => 'HTML::Object::TypeError', | ||
| 69 | }) ) if( !$self->_is_a( $cue => 'HTML::Object::DOM::TextTrackCue' ) ); | ||
| 70 | my $cues = $self->cues; | ||
| 71 | my $pos = $cues->pos( $cue ); | ||
| 72 | if( !defined( $cue ) ) | ||
| 73 | { | ||
| 74 | $cue->track( $self ); | ||
| 75 | $cues->push( $cue ); | ||
| 76 | } | ||
| 77 | return( $self ); | ||
| 78 | } | ||
| 79 | |||
| 80 | # Note: property | ||
| 81 | sub cues { return( shift->_set_get_object_array_object( 'cues', 'HTML::Object::DOM::TextTrackCueList', @_ ) ); } | ||
| 82 | |||
| 83 | # Note: property id inherited | ||
| 84 | |||
| 85 | # Note: property | ||
| 86 | sub inBandMetadataTrackDispatchType : lvalue { return( shift->_set_get_scalar_as_object( 'inbandmetadatatrackdispatchtype', @_ ) ); } | ||
| 87 | |||
| 88 | # Note: property kind inherited | ||
| 89 | |||
| 90 | # Note: property label inherited | ||
| 91 | |||
| 92 | # Note: property language inherited | ||
| 93 | |||
| 94 | # Note: property | ||
| 95 | sub mode : lvalue { return( shift->_set_get_scalar_as_object( 'mode', @_ ) ); } | ||
| 96 | |||
| 97 | # Note: method parent is used and inherited from HTML::Object::Element via HTML::Object::EventTarget | ||
| 98 | |||
| 99 | sub removeCue | ||
| 100 | { | ||
| 101 | my $self = shift( @_ ); | ||
| 102 | my $cue = shift( @_ ) || return( $self->error({ | ||
| 103 | message => "No cue object was provided.", | ||
| 104 | class => 'HTML::Object::TypeError', | ||
| 105 | }) ); | ||
| 106 | return( $self->error({ | ||
| 107 | message => "Cue provided is not a HTML::Object::DOM::TextTrackCue object.", | ||
| 108 | class => 'HTML::Object::TypeError', | ||
| 109 | }) ) if( !$self->_is_a( $cue => 'HTML::Object::DOM::TextTrackCue' ) ); | ||
| 110 | my $cues = $self->cues; | ||
| 111 | my $pos = $cues->pos( $cue ); | ||
| 112 | if( defined( $pos ) ) | ||
| 113 | { | ||
| 114 | $cues->splice( $pos, 1 ); | ||
| 115 | $cue->track( undef ); | ||
| 116 | return( $cue ); | ||
| 117 | } | ||
| 118 | return; | ||
| 119 | } | ||
| 120 | |||
| 121 | 1; | ||
| 122 | # NOTE: POD | ||
| 123 | __END__ |