App-Duppy
view release on metacpan or search on metacpan
lib/App/Duppy.pm view on Meta::CPAN
package App::Duppy;
# ABSTRACT: a wrapper around casperjs to pass test configurations as json files
use strict;
use warnings;
use Moo;
use MooX::Options;
use IPC::Run qw/run new_chunker/;
use File::Which;
use IO::All;
use JSON;
use DDP;
use Carp;
use Try::Tiny;
option 'test' => (
is => 'rw',
required => 1,
format => 's@',
doc =>
'Test option: one ore more json file(s) containing the casperjs tests to perform'
);
option 'casper_path' => (
is => 'rw',
format => 's',
doc => 'Path to casperjs, if not standard',
predicate => 'has_casper_path',
);
has 'tests' => ( is => 'lazy', );
has 'buffer_return' => ( is => 'rw', default => sub {''});
has 'silent_run' => (is => 'rw', default => sub { 0 });
sub _build_tests {
my $self = shift;
my $ret = {};
foreach my $file ( @{ $self->test } ) {
if ( io($file)->exists ) {
my $content = io($file)->slurp;
try {
$ret->{$file} = decode_json($content);
}
catch {
carp "'$file' is not valid: $_";
};
}
else {
carp "'$file' does not exist";
}
}
return $ret;
}
sub run_casper {
my $self = shift;
my $full_path;
$self->buffer_return('') if ($self->buffer_return);
if ( $self->has_casper_path ) {
if ( -f $self->casper_path and -x $self->casper_path ) {
$full_path = $self->casper_path;
}
else {
croak sprintf(
q{'%s' is not an executable file},
$self->casper_path
);
}
}
else {
$full_path = which('casperjs');
}
( run in 2.414 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )