From: Vincent Pit Date: Thu, 9 Apr 2015 14:33:31 +0000 (-0300) Subject: Implement capture_perl() X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=0061dae2bcee89818b69face072da887029ae488;p=perl%2Fmodules%2FVPIT-TestHelpers.git Implement capture_perl() --- diff --git a/lib/VPIT/TestHelpers.pm b/lib/VPIT/TestHelpers.pm index 7dfd15e..6a3655e 100644 --- a/lib/VPIT/TestHelpers.pm +++ b/lib/VPIT/TestHelpers.pm @@ -188,7 +188,10 @@ sub init_capture { load_or_skip_all 'Socket', '0', [ ]; } - return capture => \&capture; + return ( + capture => \&capture, + capture_perl => \&capture_perl, + ); } # Inspired from IPC::Cmd @@ -328,6 +331,19 @@ sub capture { } } +sub capture_perl { + my $code = shift; + + if ($code =~ /"/) { + die 'Double quotes in evaluated code are not portable'; + } + + fresh_perl_env { + my @perl = @_; + capture @perl, '-e', $code; + }; +} + sub init_threads { my ($pkg, $threadsafe, $force_var) = @_;