diff --git a/lib/Subtitle/SSA/Style.pm b/lib/Subtitle/SSA/Style.pm index ef2cd70..7947a75 100644 --- a/lib/Subtitle/SSA/Style.pm +++ b/lib/Subtitle/SSA/Style.pm @@ -77,6 +77,26 @@ sub set { return 1; } +sub parse { + my ($self, $fields, $line) = @_; + + return unless $fields and ref($fields) eq 'ARRAY'; + return unless $line and $line =~ m{^Style:}oi; + + chomp $line; + $line =~ s{^style:\s+}{}oi; + my @values = split /,\s*/o, $line; + # check that values count match fields count + return unless scalar @{ $fields } != scalar @values; + + foreach my $field (@{ $fields }) { + my $value = shift @values; + $self->set($field => $value); + } + + return 1; +} + sub to_string { my ($self) = @_; my @fields = $self->fields();