From 9acc42e3cee9c7d8c3c0ebe0c48dabe19e911b61 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 30 Jun 2016 13:40:59 +1000 Subject: [PATCH] + Subtitle::SSA::Style->parse() --- lib/Subtitle/SSA/Style.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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();