From bfa2083a249a96212b397dc002cec0730d1b70ed Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Tue, 24 Jul 2018 02:36:56 +1000 Subject: [PATCH] * move all formats under Subtitle::Format namespace --- bin/ssa-info | 4 ++-- bin/ssa-retime | 4 ++-- lib/Subtitle/{ => Format}/MSub.pm | 2 +- lib/Subtitle/{ => Format}/SRT.pm | 2 +- lib/Subtitle/{ => Format}/SSA.pm | 24 ++++++++++++------------ lib/Subtitle/{ => Format}/SSA/Event.pm | 4 ++-- lib/Subtitle/{ => Format}/SSA/File.pm | 2 +- lib/Subtitle/{ => Format}/SSA/Header.pm | 2 +- lib/Subtitle/{ => Format}/SSA/Record.pm | 2 +- lib/Subtitle/{ => Format}/SSA/Style.pm | 4 ++-- t/format-msub.t | 6 +++--- t/format-srt.t | 6 +++--- t/format-ssa-event.t | 10 +++++----- t/format-ssa-file.t | 8 ++++---- t/format-ssa-header.t | 4 ++-- t/format-ssa-style.t | 10 +++++----- 16 files changed, 47 insertions(+), 47 deletions(-) rename lib/Subtitle/{ => Format}/MSub.pm (99%) rename lib/Subtitle/{ => Format}/SRT.pm (99%) rename lib/Subtitle/{ => Format}/SSA.pm (89%) rename lib/Subtitle/{ => Format}/SSA/Event.pm (95%) rename lib/Subtitle/{ => Format}/SSA/File.pm (99%) rename lib/Subtitle/{ => Format}/SSA/Header.pm (94%) rename lib/Subtitle/{ => Format}/SSA/Record.pm (98%) rename lib/Subtitle/{ => Format}/SSA/Style.pm (97%) diff --git a/bin/ssa-info b/bin/ssa-info index dc3919c..cfa7276 100755 --- a/bin/ssa-info +++ b/bin/ssa-info @@ -5,7 +5,7 @@ use warnings; use lib 'lib'; use utf8; -use Subtitle::SSA; +use Subtitle::Format::SSA; sub usage { my ($msg) = @_; @@ -29,7 +29,7 @@ unless (@ARGV and -f $ARGV[0]) { warn "no file given\n"; usage(); } -my $ssa = Subtitle::SSA->new(debug => 0); +my $ssa = Subtitle::Format::SSA->new(debug => 0); if ($ssa->from_file($ARGV[0]) < 0) { warn "Can't parse input file: $ARGV[0]\n"; exit 1; diff --git a/bin/ssa-retime b/bin/ssa-retime index 6f4e2aa..4f97422 100755 --- a/bin/ssa-retime +++ b/bin/ssa-retime @@ -6,7 +6,7 @@ use lib 'lib'; use utf8; use Getopt::Long; -use Subtitle::SSA; +use Subtitle::Format::SSA; sub usage { my ($msg) = @_; @@ -102,7 +102,7 @@ if ($mode eq 'framerate') { usage("Incorrect mode: $mode (see help below)"); } -my $ssa = Subtitle::SSA->new(debug => !!$opts{loglevel}); +my $ssa = Subtitle::Format::SSA->new(debug => !!$opts{loglevel}); unless ($ssa->from_file($opts{infile})) { foreach my $line (@{ $ssa->{log} }) { print $line, "\n"; diff --git a/lib/Subtitle/MSub.pm b/lib/Subtitle/Format/MSub.pm similarity index 99% rename from lib/Subtitle/MSub.pm rename to lib/Subtitle/Format/MSub.pm index 2e96b27..cc1c70b 100644 --- a/lib/Subtitle/MSub.pm +++ b/lib/Subtitle/Format/MSub.pm @@ -1,4 +1,4 @@ -package Subtitle::MSub; +package Subtitle::Format::MSub; use strict; use warnings; diff --git a/lib/Subtitle/SRT.pm b/lib/Subtitle/Format/SRT.pm similarity index 99% rename from lib/Subtitle/SRT.pm rename to lib/Subtitle/Format/SRT.pm index c5ddff8..d06a8e6 100644 --- a/lib/Subtitle/SRT.pm +++ b/lib/Subtitle/Format/SRT.pm @@ -1,4 +1,4 @@ -package Subtitle::SRT; +package Subtitle::Format::SRT; use strict; use warnings; diff --git a/lib/Subtitle/SSA.pm b/lib/Subtitle/Format/SSA.pm similarity index 89% rename from lib/Subtitle/SSA.pm rename to lib/Subtitle/Format/SSA.pm index 17efa76..0b1a398 100644 --- a/lib/Subtitle/SSA.pm +++ b/lib/Subtitle/Format/SSA.pm @@ -1,13 +1,13 @@ -package Subtitle::SSA; +package Subtitle::Format::SSA; use strict; use warnings; use utf8; -use Subtitle::SSA::Header; -use Subtitle::SSA::Style; -use Subtitle::SSA::Event; -use Subtitle::SSA::File; +use Subtitle::Format::SSA::Header; +use Subtitle::Format::SSA::Style; +use Subtitle::Format::SSA::Event; +use Subtitle::Format::SSA::File; use Subtitle::Utils qw(:string); @@ -71,7 +71,7 @@ sub parse { if ($section eq 'fonts') { if (index($line, 'fontname:') == 0) { $line =~ m/^fontname:\s*(.*)/o; - $font = Subtitle::SSA::File->new; + $font = Subtitle::Format::SSA::File->new; $font->type('font'); $font->name($1); push @{ $self->{fonts} }, $font; @@ -89,7 +89,7 @@ sub parse { # skip comments next if $line =~ m{^ \s* ;}xo; if ($section eq 'header') { - my $header = Subtitle::SSA::Header->new; + my $header = Subtitle::Format::SSA::Header->new; unless ($header->parse($line)) { $self->log(error => "Can't parse header at line $linenum: $line"); next; @@ -113,7 +113,7 @@ sub parse { $self->log(debug => "Set style format from line $linenum"); next; } - my $style = Subtitle::SSA::Style->new(type => $self->{type}); + my $style = Subtitle::Format::SSA::Style->new(type => $self->{type}); if ($style->parse($line)) { push @{ $self->{styles} }, $style; } else { @@ -127,7 +127,7 @@ sub parse { $self->log(debug => "Set event format from line $linenum"); next; } - my $event = Subtitle::SSA::Event->new(type => $self->{type}); + my $event = Subtitle::Format::SSA::Event->new(type => $self->{type}); if ($event->parse($line)) { push @{ $self->{events} }, $event; } else { @@ -148,7 +148,7 @@ sub build { # headers push @lines, "[Script Info]"; - push @lines, "; generated with Subtitle::SSA"; + push @lines, "; generated with Subtitle::Format::SSA"; foreach my $key (@{ $self->{h_order} }) { my $h = $self->{headers}->{$key}; push @lines, $h->to_string(); @@ -161,7 +161,7 @@ sub build { } else { push @lines, "[V4 Styles]"; } - push @lines, Subtitle::SSA::Style->new(type => $self->{type})->get_format_line(); + push @lines, Subtitle::Format::SSA::Style->new(type => $self->{type})->get_format_line(); foreach my $s (@{ $self->{styles} }) { push @lines, $s->to_string(); } @@ -169,7 +169,7 @@ sub build { # events push @lines, "[Events]"; - push @lines, Subtitle::SSA::Event->new(type => $self->{type})->get_format_line(); + push @lines, Subtitle::Format::SSA::Event->new(type => $self->{type})->get_format_line(); foreach my $e (@{ $self->{events} }) { push @lines, $e->to_string(); } diff --git a/lib/Subtitle/SSA/Event.pm b/lib/Subtitle/Format/SSA/Event.pm similarity index 95% rename from lib/Subtitle/SSA/Event.pm rename to lib/Subtitle/Format/SSA/Event.pm index 75b8807..3cc2e67 100644 --- a/lib/Subtitle/SSA/Event.pm +++ b/lib/Subtitle/Format/SSA/Event.pm @@ -1,10 +1,10 @@ -package Subtitle::SSA::Event; +package Subtitle::Format::SSA::Event; use strict; use warnings; use utf8; -use base 'Subtitle::SSA::Record'; +use base 'Subtitle::Format::SSA::Record'; my @FIELDS_SSA = qw(marked start end style name marginl marginr marginv effect text); my @FIELDS_ASS = qw(layer start end style name marginl marginr marginv effect text); diff --git a/lib/Subtitle/SSA/File.pm b/lib/Subtitle/Format/SSA/File.pm similarity index 99% rename from lib/Subtitle/SSA/File.pm rename to lib/Subtitle/Format/SSA/File.pm index 019fd88..e0e91b2 100644 --- a/lib/Subtitle/SSA/File.pm +++ b/lib/Subtitle/Format/SSA/File.pm @@ -1,4 +1,4 @@ -package Subtitle::SSA::File; +package Subtitle::Format::SSA::File; use strict; use warnings; diff --git a/lib/Subtitle/SSA/Header.pm b/lib/Subtitle/Format/SSA/Header.pm similarity index 94% rename from lib/Subtitle/SSA/Header.pm rename to lib/Subtitle/Format/SSA/Header.pm index b7e2eca..9e7f1a9 100644 --- a/lib/Subtitle/SSA/Header.pm +++ b/lib/Subtitle/Format/SSA/Header.pm @@ -1,4 +1,4 @@ -package Subtitle::SSA::Header; +package Subtitle::Format::SSA::Header; use strict; use warnings; diff --git a/lib/Subtitle/SSA/Record.pm b/lib/Subtitle/Format/SSA/Record.pm similarity index 98% rename from lib/Subtitle/SSA/Record.pm rename to lib/Subtitle/Format/SSA/Record.pm index f358be8..35818a8 100644 --- a/lib/Subtitle/SSA/Record.pm +++ b/lib/Subtitle/Format/SSA/Record.pm @@ -1,4 +1,4 @@ -package Subtitle::SSA::Record; +package Subtitle::Format::SSA::Record; use strict; use warnings; diff --git a/lib/Subtitle/SSA/Style.pm b/lib/Subtitle/Format/SSA/Style.pm similarity index 97% rename from lib/Subtitle/SSA/Style.pm rename to lib/Subtitle/Format/SSA/Style.pm index da0ac17..654cd1a 100644 --- a/lib/Subtitle/SSA/Style.pm +++ b/lib/Subtitle/Format/SSA/Style.pm @@ -1,10 +1,10 @@ -package Subtitle::SSA::Style; +package Subtitle::Format::SSA::Style; use strict; use warnings; use utf8; -use base 'Subtitle::SSA::Record'; +use base 'Subtitle::Format::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); diff --git a/t/format-msub.t b/t/format-msub.t index 631cd9a..4556d25 100644 --- a/t/format-msub.t +++ b/t/format-msub.t @@ -3,10 +3,10 @@ use warnings; use Test::More tests => 9; -use Subtitle::MSub; +use Subtitle::Format::MSub; -my $msub = Subtitle::MSub->new(debug => 1); -is(ref $msub, 'Subtitle::MSub'); +my $msub = Subtitle::Format::MSub->new(debug => 1); +is(ref $msub, 'Subtitle::Format::MSub'); can_ok($msub, qw(new parse)); my $sample = <<"EOF"; diff --git a/t/format-srt.t b/t/format-srt.t index 017c03b..073d7ff 100644 --- a/t/format-srt.t +++ b/t/format-srt.t @@ -3,10 +3,10 @@ use warnings; use Test::More tests => 9; -use Subtitle::SRT; +use Subtitle::Format::SRT; -my $srt = Subtitle::SRT->new(debug => 1); -is(ref $srt, 'Subtitle::SRT'); +my $srt = Subtitle::Format::SRT->new(debug => 1); +is(ref $srt, 'Subtitle::Format::SRT'); can_ok($srt, qw(new parse)); my $sample = <<"EOF"; diff --git a/t/format-ssa-event.t b/t/format-ssa-event.t index fa93416..f4c826d 100644 --- a/t/format-ssa-event.t +++ b/t/format-ssa-event.t @@ -3,14 +3,14 @@ use warnings; use Test::More tests => 30; -use Subtitle::SSA::Event; +use Subtitle::Format::SSA::Event; 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(type => 'ssa'); +$event = Subtitle::Format::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(type => 'ass'); +$event = Subtitle::Format::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(type => 'ssa'); +$event = Subtitle::Format::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(type => 'ass'); +$event = Subtitle::Format::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-file.t b/t/format-ssa-file.t index cb665a4..b728020 100644 --- a/t/format-ssa-file.t +++ b/t/format-ssa-file.t @@ -3,7 +3,7 @@ use warnings; use Test::More tests => 62; -use Subtitle::SSA::File; +use Subtitle::Format::SSA::File; sub random_data { my $data = ''; @@ -15,14 +15,14 @@ sub random_data { return $data; } -my $file = Subtitle::SSA::File->new; -is(ref $file, 'Subtitle::SSA::File'); +my $file = Subtitle::Format::SSA::File->new; +is(ref $file, 'Subtitle::Format::SSA::File'); can_ok($file, qw(new error size type name from_binary add_uue_line to_binary uue_string uue_block)); undef $file; for (my $i = 0; $i < 15; $i++) { my $bin = random_data(); - $file = Subtitle::SSA::File->new; + $file = Subtitle::Format::SSA::File->new; $file->from_binary($bin); is($file->size => length $bin); my $uue = $file->uue_string; diff --git a/t/format-ssa-header.t b/t/format-ssa-header.t index 1c0e6ab..342d1d2 100644 --- a/t/format-ssa-header.t +++ b/t/format-ssa-header.t @@ -3,7 +3,7 @@ use warnings; use Test::More tests => 43; -use Subtitle::SSA::Header; +use Subtitle::Format::SSA::Header; my $sample = <<"EOF"; [Script Info] @@ -29,7 +29,7 @@ my @headers; my @lines = split /\n/, $sample; splice @lines, 0, 3; # skip section header and comments foreach my $line (@lines) { - my $header = Subtitle::SSA::Header->new; + my $header = Subtitle::Format::SSA::Header->new; ok($header->parse($line), "line parsing"); my ($name, $value) = split(": ", $line, 2); is($header->{name} => $name); diff --git a/t/format-ssa-style.t b/t/format-ssa-style.t index edb3800..1318e87 100644 --- a/t/format-ssa-style.t +++ b/t/format-ssa-style.t @@ -3,14 +3,14 @@ use warnings; use Test::More tests => 51; -use Subtitle::SSA::Style; +use Subtitle::Format::SSA::Style; 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(type => 'ssa'); +$style = Subtitle::Format::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(type => 'ass'); +$style = Subtitle::Format::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(type => 'ssa'); +$style = Subtitle::Format::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(type => 'ass'); +$style = Subtitle::Format::SSA::Style->new(type => 'ass'); ok($style->parse($sample), "ASS style parsing test"); is($style->{name} => 'Default'); is($style->{fontname} => 'Georgia');