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 utf8;
use Subtitle::Utils 'strip_bom';
sub log {
my ($self, $level, $msg) = @_;
@ -25,6 +27,14 @@ sub log {
sub parse { 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 {
my ($self, $text) = @_;
my @lines = split /\r?\n/o, $text;
@ -38,7 +48,7 @@ sub from_file {
my @lines = <$FH>;
close $FH;
return unless @lines; # empty file?
$lines[0] =~ s[^\x{EF}\x{BB}\x{BF}][]; # strip BOM
strip_bom($lines[0]);
return $self->parse(\@lines);
}
@ -84,8 +94,16 @@ Collected messages can be accessed like this:
my @log = @{ $obj->{log} };
=head C<build>
=head C<parse>
=head2 C<events>
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.
Should return -1 on error, >= 0 on success (parsed events count).

Loading…
Cancel
Save