B-Stats
view release on metacpan or search on metacpan
}
else {
$runperl .= qq ( -e '$prog' );
}
}
} elsif (defined $args{progfile}) {
$runperl .= qq( "$args{progfile}");
} else {
# You probaby didn't want to be sucking in from the upstream stdin
die "test.pl:runperl(): none of prog, progs, progfile, args, "
. " switches or stdin specified"
unless defined $args{args} or defined $args{switches}
or defined $args{stdin};
}
if (defined $args{stdin}) {
# so we don't try to put literal newlines and crs onto the
# command line.
$args{stdin} =~ s/\n/\\n/g;
$args{stdin} =~ s/\r/\\r/g;
if ($is_mswin || $is_netware || $is_vms) {
$runperl = qq{$^X -e "print qq(} .
$args{stdin} . q{)" | } . $runperl;
}
elsif ($is_macos) {
# MacOS can only do two processes under MPW at once;
# the test itself is one; we can't do two more, so
# write to temp file
my $stdin = qq{$^X -e 'print qq(} . $args{stdin} . qq{)' > teststdin; };
if ($args{verbose}) {
my $stdindisplay = $stdin;
$stdindisplay =~ s/\n/\n\#/g;
print STDERR "# $stdindisplay\n";
}
`$stdin`;
$runperl .= q{ < teststdin };
}
else {
$runperl = qq{$^X -e 'print qq(} .
$args{stdin} . q{)' | } . $runperl;
}
}
if (defined $args{args}) {
_quote_args(\$runperl, $args{args});
}
$runperl .= ' 2>&1' if $args{stderr} && !$is_mswin && !$is_macos;
$runperl .= " \xB3 Dev:Null" if !$args{stderr} && $is_macos;
if ($args{verbose}) {
my $runperldisplay = $runperl;
$runperldisplay =~ s/\n/\n\#/g;
print STDERR "# $runperldisplay\n";
}
return $runperl;
}
sub runperl {
die "test.pl:runperl() does not take a hashref"
if ref $_[0] and ref $_[0] eq 'HASH';
my $runperl = &_create_runperl;
# ${^TAINT} is invalid in perl5.00505
my $tainted;
eval '$tainted = ${^TAINT};' if $] >= 5.006;
my %args = @_;
exists $args{switches} && grep m/^-T$/, @{$args{switches}} and $tainted = $tainted + 1;
if ($tainted) {
# We will assume that if you're running under -T, you really mean to
# run a fresh perl, so we'll brute force launder everything for you
my $sep;
eval "require Config; Config->import";
if ($@) {
warn "test.pl had problems loading Config: $@";
$sep = ':';
} else {
$sep = $Config{path_sep};
}
my @keys = grep {exists $ENV{$_}} qw(CDPATH IFS ENV BASH_ENV);
local @ENV{@keys} = ();
# Untaint, plus take out . and empty string:
local $ENV{'DCL$PATH'} = $1 if $is_vms && ($ENV{'DCL$PATH'} =~ /(.*)/s);
$ENV{PATH} =~ /(.*)/s;
local $ENV{PATH} =
join $sep, grep { $_ ne "" and $_ ne "." and -d $_ and
($is_mswin or $is_vms or !(stat && (stat _)[2]&0022)) }
split quotemeta ($sep), $1;
$ENV{PATH} .= "$sep/bin" if $is_cygwin; # Must have /bin under Cygwin
$runperl =~ /(.*)/s;
$runperl = $1;
my ($err,$result,$stderr) = run_cmd($runperl, $args{timeout});
$result =~ s/\n\n/\n/ if $is_vms; # XXX pipes sometimes double these
return $result;
} else {
my ($err,$result,$stderr) = run_cmd($runperl, $args{timeout});
$result =~ s/\n\n/\n/ if $is_vms; # XXX pipes sometimes double these
return $result;
}
}
*run_perl = \&runperl; # Nice alias.
sub DIE {
print STDERR "# @_\n";
exit 1;
}
# A somewhat safer version of the sometimes wrong $^X.
my $Perl;
sub which_perl {
unless (defined $Perl) {
$Perl = $^X;
# VMS should have 'perl' aliased properly
return $Perl if $^O eq 'VMS';
my $exe;
eval "require Config; Config->import";
if ($@) {
warn "test.pl had problems loading Config: $@";
$exe = '';
} else {
$exe = $Config{exe_ext};
}
$exe = '' unless defined $exe;
# This doesn't absolutize the path: beware of future chdirs().
# We could do File::Spec->abs2rel() but that does getcwd()s,
# which is a bit heavyweight to do here.
if ($Perl =~ /^perl\Q$exe\E$/i) {
my $perl = "perl$exe";
eval "require File::Spec";
if ($@) {
warn "test.pl had problems loading File::Spec: $@";
$Perl = "./$perl";
} else {
$Perl = File::Spec->catfile(File::Spec->curdir(), $perl);
}
( run in 1.987 second using v1.01-cache-2.11-cpan-39bf76dae61 )