From: Marius Gavrilescu Date: Sat, 1 Aug 2015 15:46:36 +0000 (+0300) Subject: Simplify code X-Git-Tag: 1.000~10 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=3f12a3221f4b752a93dc4bb3780708b0201ddd6e;p=app-musicexpo.git Simplify code --- diff --git a/lib/App/MusicExpo.pm b/lib/App/MusicExpo.pm index 3bdef01..a55b53c 100644 --- a/lib/App/MusicExpo.pm +++ b/lib/App/MusicExpo.pm @@ -119,6 +119,16 @@ sub mp4info{ }; } +my %info = ( + '.flac' => \&flacinfo, + '.mp3' => \&mp3info, + '.ogg' => \&vorbisinfo, + '.oga' => \&vorbisinfo, + '.mp4' => \&mp4info, + '.aac' => \&mp4info, + '.m4a' => \&mp4info, +); + sub normalizer{ "$_[0]|".(stat $_[0])[9] } @@ -126,22 +136,17 @@ sub normalizer{ sub make_fragment{ join '-', map { lc =~ y/a-z0-9/_/csr } @_ } sub run { + my %info = %info; if ($cache) { tie my %cache, 'DB_File', $cache, O_RDWR|O_CREAT, 0644; - memoize $_, NORMALIZER => \&normalizer, LIST_CACHE => 'MERGE', SCALAR_CACHE => [HASH => \%cache] for qw/flacinfo mp3info vorbisinfo mp4info/; + $info{$_} = memoize $info{$_}, INSTALL => undef, NORMALIZER => \&normalizer, LIST_CACHE => 'FAULT', SCALAR_CACHE => [HASH => \%cache] for keys %info; } my %files; for my $file (@ARGV) { - my $info; - $info = thaw scalar flacinfo $file if $file =~ /\.flac$/i; - $info = thaw scalar mp3info $file if $file =~ /\.mp3$/i; - $info = thaw scalar vorbisinfo $file if $file =~ /\.og(?:g|a)$/i; - $info = thaw scalar mp4info $file if $file =~ /\.mp4|\.aac|\.m4a$/i; - next unless defined $info; - my $basename = fileparse $file, '.flac', '.mp3', '.ogg', '.oga', '.mp4', '.aac', '.m4a'; + my ($basename, undef, $suffix) = fileparse $file, keys %info; $files{$basename} //= []; - push @{$files{$basename}}, $info; + push @{$files{$basename}}, thaw scalar $info{$suffix}->($file); } my $ht=HTML::Template::Compiled->new(