You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
830 B
51 lines
830 B
8 years ago
|
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;
|