Use the mojolicious plugin instead of rolling our own config loader.
Fix Perl::Critic complaints about eval
#!/usr/bin/env perl
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Mojo::Base -strict;
use lib 'lib';
use Mojo::JSON;
use Mojo::Util qw(decode slurp);
use Mojo::Loader;
use File::Basename;
use Mojolicious;
use Mojo::Home;
if(scalar @ARGV == 0) {
say "Usage: $0 <processed json files>";
exit 1;
}
sub load_config {
my $app = Mojolicious->new;
$app->home(Mojo::Home->new("$FindBin::Bin/../"));
$app->moniker("CrashTest");
return $app->plugin('Config');
}
my $config = load_config();
my $loader = Mojo::Loader->new;
my $storage_class = $config->{Storage}->{Type};
if (my $e = $loader->load($storage_class)) {
die ref $e ? "Exception: $e" : 'Not found!';
}
my $storage = $storage_class->new(config => $config->{Storage});
foreach my $arg (@ARGV) {
my $json = Mojo::JSON->new();
my $pjson = $json->decode(slurp $arg);
my($filename, $dirs, $suffix) = fileparse($arg, qr/\.[^.]*/);
my $uuid = $filename;
$storage->_db_insert_processed_data($uuid, $pjson);
}