Browse Source

* Subtitle::BASE : strip BOM, add events()

master
Alex 'AdUser' Z 6 years ago
parent
commit
9923dd5203
  1. 24
      lib/Subtitle/BASE.pm

24
lib/Subtitle/BASE.pm

@ -4,6 +4,8 @@ use strict;
use warnings; use warnings;
use utf8; use utf8;
use Subtitle::Utils 'strip_bom';
sub log { sub log {
my ($self, $level, $msg) = @_; my ($self, $level, $msg) = @_;
@ -25,6 +27,14 @@ sub log {
sub parse { return "Unimplemented by subclass"; } sub parse { return "Unimplemented by subclass"; }
sub build { return "Unimplemented by subclass"; } sub build { return "Unimplemented by subclass"; }
sub events {
my ($self, $events) = @_;
if ($events and ref($events) eq 'ARRAY') {
$self->{events} = $events;
}
return wantarray ? @{ $self->{events} } : $self->{events};
}
sub from_string { sub from_string {
my ($self, $text) = @_; my ($self, $text) = @_;
my @lines = split /\r?\n/o, $text; my @lines = split /\r?\n/o, $text;
@ -38,7 +48,7 @@ sub from_file {
my @lines = <$FH>; my @lines = <$FH>;
close $FH; close $FH;
return unless @lines; # empty file? return unless @lines; # empty file?
$lines[0] =~ s[^\x{EF}\x{BB}\x{BF}][]; # strip BOM strip_bom($lines[0]);
return $self->parse(\@lines); return $self->parse(\@lines);
} }
@ -84,8 +94,16 @@ Collected messages can be accessed like this:
my @log = @{ $obj->{log} }; my @log = @{ $obj->{log} };
=head C<build> =head2 C<events>
=head C<parse>
my @events = $obj->events; # array
my $events = $obj->events; # arrayref
$obj->events([$e1, $e2, $e3]);
Access to subtitle events
=head2 C<build>
=head2 C<parse>
Stubs for subclasses. Stubs for subclasses.
Should return -1 on error, >= 0 on success (parsed events count). Should return -1 on error, >= 0 on success (parsed events count).

Loading…
Cancel
Save