From 68fcd0fe23e582778ebe482a2afb540554f9d8a1 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 30 Jun 2016 15:13:25 +1000 Subject: [PATCH] + Subtitle::SSA::Record : extract base class for style & event --- lib/Subtitle/SSA/Record.pm | 50 ++++++++++++++++++++++++++++++++++++++ lib/Subtitle/SSA/Style.pm | 43 +------------------------------- 2 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 lib/Subtitle/SSA/Record.pm diff --git a/lib/Subtitle/SSA/Record.pm b/lib/Subtitle/SSA/Record.pm new file mode 100644 index 0000000..f8778a7 --- /dev/null +++ b/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; diff --git a/lib/Subtitle/SSA/Style.pm b/lib/Subtitle/SSA/Style.pm index 0948808..89988b3 100644 --- a/lib/Subtitle/SSA/Style.pm +++ b/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) = @_;