diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-02 10:35:56 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-02 10:35:56 +1300 |
commit | 233a7846c94b5c6b4038e49554861899eda72d8a (patch) | |
tree | e4f76836cdf0a940cb81da4683a87012b57bd565 /lib/Music/Lyrics/LRC.pm | |
parent | Merge branch 'hotfix/v0.06' into develop (diff) | |
download | Music-Lyrics-LRC-233a7846c94b5c6b4038e49554861899eda72d8a.tar.gz Music-Lyrics-LRC-233a7846c94b5c6b4038e49554861899eda72d8a.zip |
Add verbose flag to warn on malformed lines
Passing in a hash to the constructor with `verbose` set to a truthy
value will enable the warnings about malformed lines. Otherwise they'll
simply be skipped (the default).
Diffstat (limited to 'lib/Music/Lyrics/LRC.pm')
-rw-r--r-- | lib/Music/Lyrics/LRC.pm | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/Music/Lyrics/LRC.pm b/lib/Music/Lyrics/LRC.pm index 10204d0..7467f50 100644 --- a/lib/Music/Lyrics/LRC.pm +++ b/lib/Music/Lyrics/LRC.pm @@ -80,13 +80,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; } @@ -174,8 +182,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 @@ -295,9 +303,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()> |