# HG changeset patch # User Vincent Tondellier # Date 1408485091 -7200 # Node ID 6070307efd381e8c3eb0b1b60fe790fd36f2bb43 # Parent 604ffca3aec119de9346ef7d5e33c9746e011280 Use the mojolicious plugin instead of rolling our own config loader. Fix Perl::Critic complaints about eval diff -r 604ffca3aec1 -r 6070307efd38 bin/fs_to_db.pl --- a/bin/fs_to_db.pl Mon Aug 18 23:01:26 2014 +0200 +++ b/bin/fs_to_db.pl Tue Aug 19 23:51:31 2014 +0200 @@ -14,24 +14,37 @@ # along with this program. If not, see . use Mojo::Base -strict; +use lib 'lib'; -use lib 'lib'; -use CrashTest::Storage::Sql; 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 "; + exit 1; +} sub load_config { - my ($file) = @_; - my $code = decode('UTF-8', slurp $file); - return eval($code); + my $app = Mojolicious->new; + $app->home(Mojo::Home->new("$FindBin::Bin/../")); + $app->moniker("CrashTest"); + return $app->plugin('Config'); } -my $config = load_config("CrashTest.conf"); +my $config = load_config(); + +my $loader = Mojo::Loader->new; -eval "require $config->{Storage}->{Type}"; -my $storage = $config->{Storage}->{Type}->new($config->{Storage}); +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(); diff -r 604ffca3aec1 -r 6070307efd38 bin/gearman_decode_worker.pl --- a/bin/gearman_decode_worker.pl Mon Aug 18 23:01:26 2014 +0200 +++ b/bin/gearman_decode_worker.pl Tue Aug 19 23:51:31 2014 +0200 @@ -13,20 +13,25 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -use Gearman::Worker; +use Mojo::Base -strict; +use lib 'lib'; + use Mojo::JSON; use Mojo::Util qw(decode slurp); use Mojo::Loader; use File::Temp; -use lib 'lib'; +use Gearman::Worker; +use Mojolicious; +use Mojo::Home; sub load_config { - my ($file) = @_; - my $code = decode('UTF-8', slurp $file); - return eval($code); + my $app = Mojolicious->new; + $app->home(Mojo::Home->new("$FindBin::Bin/../")); + $app->moniker("CrashTest"); + return $app->plugin('Config'); } -my $config = load_config($ARGV[0]); +my $config = load_config(); my $loader = Mojo::Loader->new; @@ -39,7 +44,6 @@ my $worker = Gearman::Worker->new(job_servers => $config->{DecodeQueue}->{GearmanServers}); - $worker->register_function("dump_decode", 60, sub { my $args = $_[0]->arg;