From 06d2f2057f8e879787a19fef00b409c936e2959f Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 19 Feb 2015 22:30:31 +1000 Subject: [PATCH] + Subtitle::BASE --- lib/Subtitle/BASE.pm | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/Subtitle/BASE.pm 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;