Browse Source

+ Subtitle::SSA::Record : extract base class for style & event

master
Alex 'AdUser' Z 8 years ago
parent
commit
68fcd0fe23
  1. 50
      lib/Subtitle/SSA/Record.pm
  2. 43
      lib/Subtitle/SSA/Style.pm

50
lib/Subtitle/SSA/Record.pm

@ -0,0 +1,50 @@
package Subtitle::SSA::Record;
use strict;
use warnings;
use utf8;
use overload => (
'""' => \&to_string,
);
# options:
# * version - 'ssa' for v4 or 'ass' for v4+
sub new {
my ($class, %opts) = @_;
my $self = {
_vers => 'ass',
};
bless($self, $class);
if ($opts{version} and $opts{version} =~ m{^(ass|ssa)$}oi) {
$self->{_vers} = lc($opts{version});
}
my @fields = $self->fields();
foreach my $field (@fields) {
$self->{$field} = ($opts{defaults})
? $FIELDS{$field}->{value}
: undef;
}
return $self;
}
sub fields {
my ($self) = @_;
return ($self->{_vers} eq 'ssa')
? @FIELDS_SSA
: @FIELDS_ASS;
}
sub set {
my ($self, $opt, $value) = @_;
return unless $opt;
$opt = lc($opt);
return unless exists $self->{$opt};
$self->{$opt} = $value;
return 1;
}
1;

43
lib/Subtitle/SSA/Style.pm

@ -4,9 +4,7 @@ use strict;
use warnings;
use utf8;
use overload => (
'""' => \&to_string,
);
use base 'Subtitle::SSA::Record';
my @FIELDS_SSA = qw(name fontname fontsize primarycolour secondarycolour tertiarycolour backcolour bold italic borderstyle outline shadow alignment marginl marginr marginv alphalevel encoding);
my @FIELDS_ASS = qw(name fontname fontsize primarycolour secondarycolour outlinecolour backcolour bold italic underline strikeout scalex scaley spacing angle borderstyle outline shadow alignment marginl marginr marginv encoding);
@ -45,45 +43,6 @@ my %FIELDS = (
encoding => { type => 'd', value => 204, name => 'Encoding' },
);
# options:
# * version - 'ssa' for v4 or 'ass' for v4+
sub new {
my ($class, %opts) = @_;
my $self = {
_vers => 'ass',
};
bless($self, $class);
if ($opts{version} and $opts{version} =~ m{^(ass|ssa)$}oi) {
$self->{_vers} = lc($opts{version});
}
my @fields = $self->fields();
foreach my $field (@fields) {
$self->{$field} = ($opts{defaults})
? $FIELDS{$field}->{value}
: undef;
}
return $self;
}
sub fields {
my ($self) = @_;
return ($self->{_vers} eq 'ssa')
? @FIELDS_SSA
: @FIELDS_ASS;
}
sub set {
my ($self, $opt, $value) = @_;
return unless $opt;
$opt = lc($opt);
return unless exists $self->{$opt};
$self->{$opt} = $value;
return 1;
}
sub parse {
my ($self, $fields, $line) = @_;

Loading…
Cancel
Save