From 65af21e096d10fd7f3c922d02de1947df16aadf3 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Wed, 6 Jul 2016 17:31:52 +1000 Subject: [PATCH] * Subtitle::SSA::* : global rename: version -> type --- lib/Subtitle/SSA/Event.pm | 14 +++++++------- lib/Subtitle/SSA/Record.pm | 2 +- lib/Subtitle/SSA/Style.pm | 14 +++++++------- t/format-ssa-event.t | 8 ++++---- t/format-ssa-style.t | 8 ++++---- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/Subtitle/SSA/Event.pm b/lib/Subtitle/SSA/Event.pm index 5a20ea4..ca158a6 100644 --- a/lib/Subtitle/SSA/Event.pm +++ b/lib/Subtitle/SSA/Event.pm @@ -25,26 +25,26 @@ my %FIELDS = ( ); # options: -# * version - 'ssa' for v4 or 'ass' for v4+ +# * type - 'ssa' for v4 or 'ass' for v4+ sub new { my ($class, %opts) = @_; my $self = { - _vers => 'ass', + _type => 'ass', _fields => \%FIELDS, _format => \@FIELDS_ASS, _prefix => 'Dialogue', }; - if (my $v = $opts{version}) { - if ($v =~ m{^(ass|ssa)$}oi) { - $self->{_vers} = lc($v); + if (my $t = $opts{type}) { + if ($t =~ m{^(ass|ssa)$}oi) { + $self->{_type} = lc($t); } else { - die("unsupported event version $v"); + die("unsupported event type $t"); } } $self->{_format} = \@FIELDS_SSA - if $self->{_vers} eq 'ssa'; + if $self->{_type} eq 'ssa'; my @fields = @{ $self->{_format} }; $self->{$_} = $FIELDS{$_}->{value} diff --git a/lib/Subtitle/SSA/Record.pm b/lib/Subtitle/SSA/Record.pm index 138aa4d..8eaae29 100644 --- a/lib/Subtitle/SSA/Record.pm +++ b/lib/Subtitle/SSA/Record.pm @@ -100,7 +100,7 @@ sub to_string { foreach my $field (@{ $self->{_format} }) { my $d = $self->{_fields}->{$field}; my $v = $self->{$field} // $d->{value}; - if ($d->{type} eq 'x' and $self->{_vers} eq 'ass') { + if ($d->{type} eq 'x' and $self->{_type} eq 'ass') { $v = sprintf '&H%08X', $v; } elsif ($d->{type} eq 'f') { $v = sprintf "%.2f", $v; diff --git a/lib/Subtitle/SSA/Style.pm b/lib/Subtitle/SSA/Style.pm index 9137074..da0ac17 100644 --- a/lib/Subtitle/SSA/Style.pm +++ b/lib/Subtitle/SSA/Style.pm @@ -39,26 +39,26 @@ my %FIELDS = ( ); # options: -# * version - 'ssa' for v4 or 'ass' for v4+ +# * type - 'ssa' for v4 or 'ass' for v4+ sub new { my ($class, %opts) = @_; my $self = { - _vers => 'ass', + _type => 'ass', _fields => \%FIELDS, _format => \@FIELDS_ASS, _prefix => 'Style', }; - if (my $v = $opts{version}) { - if ($v =~ m{^(ass|ssa)$}oi) { - $self->{_vers} = lc($v); + if (my $t = $opts{type}) { + if ($t =~ m{^(ass|ssa)$}oi) { + $self->{_type} = lc($t); } else { - die("unsupported event version $v"); + die("unsupported event type $t"); } } $self->{_format} = \@FIELDS_SSA - if $self->{_vers} eq 'ssa'; + if $self->{_type} eq 'ssa'; my @fields = @{ $self->{_format} }; $self->{$_} = $FIELDS{$_}->{value} diff --git a/t/format-ssa-event.t b/t/format-ssa-event.t index 2702106..fa93416 100644 --- a/t/format-ssa-event.t +++ b/t/format-ssa-event.t @@ -10,7 +10,7 @@ my ($fields, @fields, $format, $sample, $event, $output); # SSA format line $format = 'Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text'; @fields = qw(marked start end style name marginl marginr marginv effect text); -$event = Subtitle::SSA::Event->new(version => 'ssa'); +$event = Subtitle::SSA::Event->new(type => 'ssa'); $fields = $event->parse_format_line($format); is(ref $fields, 'ARRAY'); is_deeply($fields, \@fields); @@ -18,13 +18,13 @@ is_deeply($fields, \@fields); # ASS format line $format = 'Format:Layer,Start,End,Style,Name,MarginL,MarginR,MarginV,Effect,Text'; @fields = qw(layer start end style name marginl marginr marginv effect text); -$event = Subtitle::SSA::Event->new(version => 'ass'); +$event = Subtitle::SSA::Event->new(type => 'ass'); $fields = $event->parse_format_line($format); is(ref $fields, 'ARRAY'); is_deeply($fields, \@fields); $sample = 'Dialogue: Marked=0,0:01:50.15,0:01:54.15,Main,,0000,0000,0050,,Наступило новое утро'; -$event = Subtitle::SSA::Event->new(version => 'ssa'); +$event = Subtitle::SSA::Event->new(type => 'ssa'); ok($event->parse($sample), "SSA event parsing test"); is($event->{marked} => 'Marked=0'); is($event->{start} => 110.15); @@ -41,7 +41,7 @@ ok($output = $event->to_string(), 'converting SSA event to string'); is($output => $sample); $sample = 'Dialogue: 1,0:01:06.68,0:01:07.49,text three,,0000,0000,0000,,Я счастлив.'; -$event = Subtitle::SSA::Event->new(version => 'ass'); +$event = Subtitle::SSA::Event->new(type => 'ass'); ok($event->parse($sample), "ASS event parsing test"); is($event->{layer} => 1); is($event->{start} => 66.68); diff --git a/t/format-ssa-style.t b/t/format-ssa-style.t index 470e92b..edb3800 100644 --- a/t/format-ssa-style.t +++ b/t/format-ssa-style.t @@ -10,7 +10,7 @@ my ($fields, @fields, $format, $sample, $style, $output); # SSA format line $format = 'Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding'; @fields = qw(name fontname fontsize primarycolour secondarycolour tertiarycolour backcolour bold italic borderstyle outline shadow alignment marginl marginr marginv alphalevel encoding); -$style = Subtitle::SSA::Style->new(version => 'ssa'); +$style = Subtitle::SSA::Style->new(type => 'ssa'); $fields = $style->parse_format_line($format); is(ref $fields, 'ARRAY'); is_deeply($fields, \@fields); @@ -18,13 +18,13 @@ is_deeply($fields, \@fields); # ASS format line $format = 'Format:Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding'; @fields = qw(name fontname fontsize primarycolour secondarycolour outlinecolour backcolour bold italic underline strikeout scalex scaley spacing angle borderstyle outline shadow alignment marginl marginr marginv encoding); -$style = Subtitle::SSA::Style->new(version => 'ass'); +$style = Subtitle::SSA::Style->new(type => 'ass'); $fields = $style->parse_format_line($format); is(ref $fields, 'ARRAY'); is_deeply($fields, \@fields); $sample = 'Style: Default,Arial,20,11259130,33023,12582847,32,-1,0,1,2,1,2,10,10,2,0,204'; -$style = Subtitle::SSA::Style->new(version => 'ssa'); +$style = Subtitle::SSA::Style->new(type => 'ssa'); ok($style->parse($sample), "SSA style parsing test"); is($style->{name} => 'Default'); is($style->{fontname} => 'Arial'); @@ -49,7 +49,7 @@ ok($output = $style->to_string(), 'converting SSA style to string'); is($output, $sample); $sample = 'Style: Default,Georgia,50,&H00F0F4F6,&H008D7127,&H00414B4C,&H00000000,0,0,0,0,100,95,0,0,1,3.5,0,2,11,11,13,204'; -$style = Subtitle::SSA::Style->new(version => 'ass'); +$style = Subtitle::SSA::Style->new(type => 'ass'); ok($style->parse($sample), "ASS style parsing test"); is($style->{name} => 'Default'); is($style->{fontname} => 'Georgia');