App-Env
view release on metacpan or search on metacpan
0.24 2010-06-07T17:14:37-0400
* the SysFatal option will now be passed on to cloned environments
created with the Temp option.
0.23 2010-06-07T16:44:26-0400
* capture() is no longer just an alias for qexec; it can now
return both stderr and stdout.
0.22 2010-06-03T12:44:43-0400
* if CacheID is the string 'AppID', the cache id does not take
into account the contents of the AppOpts hash.
* new feature from v. 0.20 2015-05-20T16:52:10-0400 AppOpts hash)
now actually works.
0.21 2010-06-02T10:28:42-0400
README.mkdn view on Meta::CPAN
split into lines.
If the **SysFatal** flag is set for this environment,
**IPC::System::Simple::capture** is called, which will cause this
method to throw an exception if the command returned a non-zero exit
value. It also avoid invoking a shell to run the command if possible.
- capture
$stdout = $env->capture( $command, @args );
($stdout, $stderr) = $env->capture( $command, @args );
Execute the passed command in the environment defined by **$env** and
returns content of its standard output and (optionally) standard error
streams.
If the **SysFatal** flag is set for this environment,
**IPC::System::Simple::capture** is called, which will cause this
method to throw an exception if the command returned a non-zero exit
value. It also avoid invoking a shell to run the command if possible.
lib/App/Env.pm view on Meta::CPAN
my $self = shift;
my @args = @_;
local %ENV = %{$self};
my $wantarray = wantarray; ## no critic (Community::Wantarray)
require Capture::Tiny;
require IPC::System::Simple;
my ( $stdout, $stderr );
my $sub
= $self->_opt->{SysFatal}
? sub { IPC::System::Simple::system( @args ) }
: sub { CORE::system( @args ) };
# Capture::Tiny::capture is prototyped as (&;@). App::Env
# lazy-loads Capture::Tiny and thus nominally avoids the prototype
# check. However, if Capture::Tiny is explicitly loaded prior to
# App::Env, the prototype check will be performed when App::Env is
# compiled. In that case the following calls to capture are
# singled out, as while the calls are correct, the prototype
# requires an explicit block or sub{}. So, explicitly
# ignore prototypes.
eval {
## no critic (Subroutines::ProhibitAmpersandSigils,Community::AmpersandSubCalls )
if ( $wantarray ) {
( $stdout, $stderr ) = &Capture::Tiny::capture( $sub );
}
else {
$stdout = &Capture::Tiny::capture( $sub );
}
1;
} // App::Env::_Util::croak( $@ );
return $wantarray ? ( $stdout, $stderr ) : $stdout;
}
#-------------------------------------------------------
sub exec { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
my $self = shift;
local %ENV = %{$self};
exec( @_ );
}
lib/App/Env.pm view on Meta::CPAN
split into lines.
If the B<SysFatal> flag is set for this environment,
B<IPC::System::Simple::capture> is called, which will cause this
method to throw an exception if the command returned a non-zero exit
value. It also avoid invoking a shell to run the command if possible.
=item capture
$stdout = $env->capture( $command, @args );
($stdout, $stderr) = $env->capture( $command, @args );
Execute the passed command in the environment defined by B<$env> and
returns content of its standard output and (optionally) standard error
streams.
If the B<SysFatal> flag is set for this environment,
B<IPC::System::Simple::capture> is called, which will cause this
method to throw an exception if the command returned a non-zero exit
value. It also avoid invoking a shell to run the command if possible.
t/00-compile.t view on Meta::CPAN
use File::Spec;
use IPC::Open3;
use IO::Handle;
open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
my @warnings;
for my $lib (@module_files)
{
# see L<perlfaq8/How can I capture STDERR from an external command?>
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-e', "require q[$lib]"))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { +require blib; blib->VERSION('1.01') };
if (@_warnings)
{
warn @_warnings;
push @warnings, @_warnings;
t/00-compile.t view on Meta::CPAN
{ SKIP: {
open my $fh, '<', $file or warn("Unable to open $file: $!"), next;
my $line = <$fh>;
close $fh and skip("$file isn't perl", 1) unless $line =~ /^#!\s*(?:\S*perl\S*)((?:\s+-\w*)*)(?:\s*#.*)?$/;
@switches = (@switches, split(' ', $1)) if $1;
close $fh and skip("$file uses -T; not testable with PERL5LIB", 1)
if grep { $_ eq '-T' } @switches and $ENV{PERL5LIB};
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-c', $file))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-c', $file);
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$file compiled ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { +require blib; blib->VERSION('1.01') };
# in older perls, -c output is simply the file portion of the path being tested
if (@_warnings = grep { !/\bsyntax OK$/ }
grep { chomp; $_ ne (File::Spec->splitpath($file))[2] } @_warnings)
{
t/capture.t view on Meta::CPAN
use File::Temp;
use File::Spec::Functions qw[ catfile ];
use App::Env;
my $script = catfile( qw [ t bin capture.pl ] );
{
my $app1 = App::Env->new( 'App1', { Cache => 0 } );
my ( $stdout, $stderr ) = $app1->capture( $^X, $script );
is( $?, 0, 'successful system call' );
is( $stdout, "STDOUT\n", 'success: STDOUT' );
is( $stderr, "STDERR\n", 'success: STDERR' );
}
{
my $app1 = App::Env->new( 'App1', { Cache => 0 } );
$app1->capture( $^X, $script, 'exit' );
isnt( $?, 0, 'unsuccessful system call' );
}
{
( run in 0.421 second using v1.01-cache-2.11-cpan-26ccb49234f )