Commits

peroumal1  committed b070429

added a silent run option so that the run_casper method returns its output in a string

  • Participants
  • Parent commits 1d9321e

Comments (0)

Files changed (1)

File lib/App/Duppy.pm

 );
 
 option 'casper_path' => (
-    is     => 'rw',
-    format => 's',
+    is      => 'rw',
+    format  => 's',
     doc     => 'Path to casperjs, if not standard',
     default => sub { '' }
 );
     my $full_path = can_run( $self->casper_path . 'casperjs' )
       or croak
 'Cannot find casperjs on your system. Please make sure it is installed or the path provided is ok';
-    foreach my $test (keys %{$self->tests}) { 
-        my $param_spec = $self->transform_arg_spec($self->tests->{$test});
-        unshift @{$param_spec->{cmd}},$full_path;
-        push @{$param_spec->{cmd}}, "test", join(" ",@{$param_spec->{paths}});
-        my ($ok,$err,$full_buff) = run(command =>  \@{$param_spec->{cmd}}); 
-        print join("\n", @$full_buff);
+    my $silent_run = shift;
+    foreach my $test ( keys %{ $self->tests } ) {
+        my $param_spec = $self->transform_arg_spec( $self->tests->{$test} );
+        unshift @{ $param_spec->{cmd} }, $full_path;
+        push @{ $param_spec->{cmd} }, "test",
+          join( " ", @{ $param_spec->{paths} } );
+        my ( $ok, $err, $full_buff ) =
+          run( command => \@{ $param_spec->{cmd} } );
+        my $buff_return = join( "\n", @$full_buff );
+        if ($silent_run) {
+            return $buff_return;
+        }
+        else {
+            print $buff_return;
+            return;
+        }
     }
 }
 
-sub transform_arg_spec { 
-    my $self = shift; 
-    my $params = shift; 
-    my $ret = { };
+sub transform_arg_spec {
+    my $self   = shift;
+    my $params = shift;
+    my $ret    = {};
     $ret->{paths} = delete $params->{paths};
-    while (my ($k,$v) = each %{$params}) { 
-        if (ref($v) eq 'ARRAY') { 
-            $v = join(',',@{$v});
+    while ( my ( $k, $v ) = each %{$params} ) {
+        if ( ref($v) eq 'ARRAY' ) {
+            $v = join( ',', @{$v} );
         }
-        else { 
-            $v = "true" if ($v eq '1');
-            $v = "false" if ($v eq '0');
+        else {
+            $v = "true"  if ( $v eq '1' );
+            $v = "false" if ( $v eq '0' );
         }
-        push @{$ret->{cmd}},"--$k=$v";
+        push @{ $ret->{cmd} }, "--$k=$v";
     }
     return $ret;
 }