aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-02 10:37:35 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-02 10:37:35 +1300
commit1faf9f9307c60cc72dcad0fd6ac438b5e440f21b (patch)
tree69f16f26351d5aa3fdcdca4e22ab2cf07c4c69a4
parentMerge branch 'feature/fract-sec' into develop (diff)
parentAdd verbose flag to warn on malformed lines (diff)
downloadMusic-Lyrics-LRC-1faf9f9307c60cc72dcad0fd6ac438b5e440f21b.tar.gz
Music-Lyrics-LRC-1faf9f9307c60cc72dcad0fd6ac438b5e440f21b.zip
Merge branch 'feature/verbose' into develop
* feature/verbose: Add verbose flag to warn on malformed lines
-rw-r--r--lib/Music/Lyrics/LRC.pm27
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/Music/Lyrics/LRC.pm b/lib/Music/Lyrics/LRC.pm
index d9258a0..e995b87 100644
--- a/lib/Music/Lyrics/LRC.pm
+++ b/lib/Music/Lyrics/LRC.pm
@@ -83,13 +83,21 @@ my %parsers = (
# Oldschool constructor
sub new {
- my ($class) = @_;
+ my ( $class, %opts ) = @_;
- # Start with empty tags and lyrics
+ # Declare a hash to build the object around
my %self;
+
+ # Start with empty tags and lyrics
$self{tags} = {};
$self{lyrics} = [];
+ # Read in the "verbose" flag if defined, default to zero
+ $self{verbose} =
+ exists $opts{verbose}
+ ? !!$opts{verbose}
+ : 0;
+
# Perlician, bless thyself
return bless \%self, $class;
}
@@ -177,8 +185,8 @@ sub load {
next LINE;
}
- # This line doesn't match anything we understand, complain but persist
- warn "Unknown format for line $NR\n";
+ # No line format match, warn if verbose
+ warn "Unknown format for line $NR\n" if $self->{verbose};
}
# Check we got to the end of the file
@@ -293,9 +301,16 @@ L<https://en.wikipedia.org/wiki/LRC_(file_format)>
=head1 SUBROUTINES/METHODS
-=head2 C<new()>
+=head2 C<new(%opts)>
-Constructor; no arguments.
+Constructor method. Accepts a hash with one attribute C<verbose>. This
+specifies whether the module will C<warn> explicitly when it cannot parse an
+input line from a file. It defaults to 0.
+
+ my $lrc = MRC::Lyrics::LRC->new();
+ ...
+ my $lrc_verbose = MRC::Lyrics::LRC->new(verbose => 1);
+ ...
=head2 C<lyrics()>