X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FApp%2FMusicExpo.pm;h=7b5f4e2f46d7ba70d0bcb3b7852f03d1b81afb9c;hb=1549062d92de87827a1e0016c898145f5a47eb63;hp=242e0df0cd19d66cba78cc883ad27b3c965edfb6;hpb=c681179f99c8f2a7c501639c19ff65a740a8b7ea;p=app-musicexpo.git diff --git a/lib/App/MusicExpo.pm b/lib/App/MusicExpo.pm index 242e0df..7b5f4e2 100644 --- a/lib/App/MusicExpo.pm +++ b/lib/App/MusicExpo.pm @@ -3,7 +3,7 @@ use v5.14; use strict; use warnings; -our $VERSION = '0.003002'; +our $VERSION = '0.003003'; use Audio::FLAC::Header qw//; use HTML::Template::Compiled qw//; @@ -15,7 +15,7 @@ use DB_File qw//; use File::Basename qw/fileparse/; use Fcntl qw/O_RDWR O_CREAT/; use Getopt::Long; -use JSON; +use JSON::MaybeXS; use Storable qw/thaw freeze/; ################################################## @@ -98,17 +98,17 @@ sub normalizer{ } sub run { - tie my %cache, 'DB_File', $cache, O_RDWR|O_CREAT, 0644 unless $cache eq ''; - memoize 'flacinfo', NORMALIZER => \&normalizer, LIST_CACHE => 'MERGE', SCALAR_CACHE => [HASH => \%cache] unless $cache eq ''; - memoize 'mp3info' , NORMALIZER => \&normalizer, LIST_CACHE => 'MERGE', SCALAR_CACHE => [HASH => \%cache] unless $cache eq ''; - memoize 'vorbisinfo' , NORMALIZER => \&normalizer, LIST_CACHE => 'MERGE', SCALAR_CACHE => [HASH => \%cache] unless $cache eq ''; + 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/; + } my %files; for my $file (@ARGV) { my $info; - $info = thaw flacinfo $file if $file =~ /.flac$/i; - $info = thaw mp3info $file if $file =~ /.mp3$/i; - $info = thaw vorbisinfo $file if $file =~ /.og(?:g|a)$/i; + $info = thaw flacinfo $file if $file =~ /\.flac$/i; + $info = thaw mp3info $file if $file =~ /\.mp3$/i; + $info = thaw vorbisinfo $file if $file =~ /\.og(?:g|a)$/i; next unless defined $info; my $basename = fileparse $file, '.flac', '.mp3', '.ogg', '.oga'; $files{$basename} //= []; @@ -129,7 +129,7 @@ sub run { push @files, \%entry } - my $json = JSON->new->utf8->canonical->encode({files => \@files, prefix => $prefix}); + my $json = JSON::MaybeXS->new(canonical => 1)->encode({files => \@files, prefix => $prefix}); $json =~ s//>/g; $ht->param(files=>[sort { $a->{title} cmp $b->{title} } @files], prefix => $prefix, json => $json);