Browse Source

* Subtitle::Format : add sort_events()

master
Alex 'AdUser' Z 6 years ago
parent
commit
de30f7dc38
  1. 14
      lib/Subtitle/Format.pm
  2. 4
      t/format.t

14
lib/Subtitle/Format.pm

@ -35,6 +35,14 @@ sub events {
return wantarray ? @{ $self->{events} } : $self->{events};
}
sub sort_events {
my ($self) = @_;
my @sorted = sort {
$a->t_start <=> $b->t_start
} @{ $self->events; };
$self->events(\@sorted);
}
sub from_string {
my ($self, $text) = @_;
my @lines = split /\r?\n/o, $text;
@ -102,6 +110,12 @@ Collected messages can be accessed like this:
Access to subtitle events
=head2 C<sort_events>
$obj->sort_events;
Internally sort events by start time (ascending)
=head2 C<build>
=head2 C<parse>

4
t/format.t

@ -1,7 +1,7 @@
use strict;
use warnings;
use Test::More tests => 5;
use Test::More tests => 6;
require_ok('Subtitle::Format');
@ -21,6 +21,8 @@ require_ok('Subtitle::Format');
my $obj = Subtitle::Dummy->new;
isa_ok($obj, 'Subtitle::Dummy');
can_ok($obj, qw(new parse build log events sort_events
from_file to_file from_string to_string));
is(scalar @{ $obj->{log} }, 0);
$obj->log(warn => "something");

Loading…
Cancel
Save