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.
50 lines
720 B
50 lines
720 B
6 years ago
|
package Subtitle::Format::SSA::Header;
|
||
9 years ago
|
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
use utf8;
|
||
|
|
||
8 years ago
|
use overload
|
||
|
'""' => \&to_string,
|
||
|
;
|
||
|
|
||
9 years ago
|
sub new {
|
||
8 years ago
|
my ($class) = @_;
|
||
8 years ago
|
my $self = {
|
||
8 years ago
|
name => undef,
|
||
|
value => '',
|
||
8 years ago
|
};
|
||
|
return bless($self, $class);
|
||
|
}
|
||
|
|
||
|
sub hash_key {
|
||
8 years ago
|
my ($self) = @_;
|
||
|
my $key = lc($self->{name});
|
||
|
$key =~ s{\s+}{}go;
|
||
|
return $key;
|
||
8 years ago
|
}
|
||
|
|
||
|
sub parse {
|
||
|
my ($self, $line) = @_;
|
||
|
|
||
|
return unless $line;
|
||
8 years ago
|
return if $line =~ m{^ \s* ;}xo; # comment
|
||
8 years ago
|
|
||
|
chomp $line;
|
||
|
$line =~ s{^\s+}{}o;
|
||
|
$line =~ s{\s+$}{}o;
|
||
|
my ($name, $value) = split /\s*:\s*/, $line, 2;
|
||
|
|
||
8 years ago
|
$self->{name} = $name;
|
||
|
$self->{value} = $value;
|
||
8 years ago
|
return 1;
|
||
|
}
|
||
|
|
||
|
sub to_string {
|
||
|
my ($self) = @_;
|
||
|
|
||
8 years ago
|
return $self->{name} . ': ' . $self->{value};
|
||
9 years ago
|
}
|
||
|
|
||
|
1;
|