diff --git a/lib/Subtitle/BASE.pm b/lib/Subtitle/BASE.pm new file mode 100644 index 0000000..f120a93 --- /dev/null +++ b/lib/Subtitle/BASE.pm @@ -0,0 +1,34 @@ +package Subtitle::BASE; + +use strict; +use warnings; +use feature qw(switch); +use utf8; + +sub log { + my ($self, $level, $msg) = @_; + + given ($level) { + when ("error") { push @{ $self->{log} }, "E: $msg"; } + when ("warn") { push @{ $self->{log} }, "W: $msg"; } + when ("info") { push @{ $self->{log} }, "I: $msg"; } + when ("debug") { push @{ $self->{log} }, "D: $msg" if $self->{debug}; } + default { warn "Unknown loglevel $level of $msg\n"; } + } + + return 1; +} + +sub chomp { + my ($self, $line) = @_; + return unless defined $line; + return $line =~ s/[\r\n]+$//or; +} + +sub trim { + my ($self, $line) = @_; + return unless defined $line; + return $line =~ s/(^\s+|\s+$)//or; +} + +1;