From cab4bc2500ed0c0c27dce1ea3524e296fd8e722c Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Tue, 24 Jul 2018 02:47:14 +1000 Subject: [PATCH] + Subtitle::Event --- lib/Subtitle/Event.pm | 43 +++++++++++++++++++++++++++++++++++++++++++ t/event.t | 19 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 lib/Subtitle/Event.pm create mode 100644 t/event.t diff --git a/lib/Subtitle/Event.pm b/lib/Subtitle/Event.pm new file mode 100644 index 0000000..938dcde --- /dev/null +++ b/lib/Subtitle/Event.pm @@ -0,0 +1,43 @@ +package Subtitle::Event; + +use strict; +use warnings; + +sub new { + my $class = shift; + my $self = { + start => 0.0, + end => 0.0, + text => '', + }; + return bless($self, $class); +} + +sub t_start { + my ($self, $t) = @_; + $self->{start} = $t + if defined $t and $t >= 0.0; + return $self->{start}; +} +sub t_end { + my ($self, $t) = @_; + $self->{end} = $t + if defined $t and $t >= 0.0; + return $self->{end}; +} +sub text { + my ($self, $t) = @_; + $self->{text} = $t + if defined $t; + return $self->{text}; +} + +1; + +=pod + +=head1 NAME + +Subtitle::Event - base class for subtitle events + +=cut diff --git a/t/event.t b/t/event.t new file mode 100644 index 0000000..26ca450 --- /dev/null +++ b/t/event.t @@ -0,0 +1,19 @@ +use strict; +use warnings; + +use Test::More tests => 7; + +use Subtitle::Event; + +my $e = Subtitle::Event->new; +is(ref $e, 'Subtitle::Event'); +can_ok($e, qw(new t_start t_end text)); + +is($e->t_start, 0.0); +is($e->t_start(17.2), 17.2); +is($e->t_start(-5.4), 17.2); + +is($e->text, ''); +is($e->text('test'), 'test'); + +1;