mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-09 03:15:41 -04:00
Revert "Revert "this should make for nicer output with an eval that ends in print""
This reverts commit 89f0dfe4bb
.
This commit is contained in:
parent
e21dc07a8f
commit
0e21373993
1 changed files with 16 additions and 3 deletions
19
lib/eval.pl
19
lib/eval.pl
|
@ -29,6 +29,13 @@ require MooseX::Declare;
|
||||||
eval "use MooseX::Declare; class Foo { has dongs => ( is => ro, isa => 'Int' ); };";
|
eval "use MooseX::Declare; class Foo { has dongs => ( is => ro, isa => 'Int' ); };";
|
||||||
require "utf8_heavy.pl";
|
require "utf8_heavy.pl";
|
||||||
|
|
||||||
|
|
||||||
|
# save the old stdout, we're going to clobber it soon. STDOUT
|
||||||
|
my $oldout;
|
||||||
|
my $outbuffer;
|
||||||
|
my $outputcode;
|
||||||
|
open($oldout, ">&STDOUT") or die "Can't dup STDOUT: $!";
|
||||||
|
|
||||||
no warnings;
|
no warnings;
|
||||||
|
|
||||||
# This sub is defined here so that it is defined before the 'use charnames'
|
# This sub is defined here so that it is defined before the 'use charnames'
|
||||||
|
@ -154,6 +161,9 @@ use Storable qw/nfreeze/; nfreeze([]); #Preload Nfreeze since it's loaded on dem
|
||||||
my $meg = $kilo * $kilo;
|
my $meg = $kilo * $kilo;
|
||||||
my $limit = 150 * $meg;
|
my $limit = 150 * $meg;
|
||||||
|
|
||||||
|
# clobber stdout before we set rlimits. otherwise we can't do anything STDOUT
|
||||||
|
open(STDOUT, ">", \$outbuffer) or die "Can't dup to buffer: $!";
|
||||||
|
|
||||||
(
|
(
|
||||||
setrlimit(RLIMIT_VMEM, 1024*$meg, 1024*$meg)
|
setrlimit(RLIMIT_VMEM, 1024*$meg, 1024*$meg)
|
||||||
and
|
and
|
||||||
|
@ -222,6 +232,8 @@ use Storable qw/nfreeze/; nfreeze([]); #Preload Nfreeze since it's loaded on dem
|
||||||
j_code($code);
|
j_code($code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oldout->print($outbuffer);
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
|
@ -231,8 +243,10 @@ use Storable qw/nfreeze/; nfreeze([]); #Preload Nfreeze since it's loaded on dem
|
||||||
my( $code ) = @_;
|
my( $code ) = @_;
|
||||||
local $@;
|
local $@;
|
||||||
local @INC;
|
local @INC;
|
||||||
|
|
||||||
local $_;
|
local $_;
|
||||||
|
|
||||||
|
# setup STDOUT for use in the eval. I should really try to hide these better but it can't cause any issues
|
||||||
$code = "no strict; no warnings; package main; $code";
|
$code = "no strict; no warnings; package main; $code";
|
||||||
my $ret = eval $code;
|
my $ret = eval $code;
|
||||||
|
|
||||||
|
@ -243,8 +257,7 @@ use Storable qw/nfreeze/; nfreeze([]); #Preload Nfreeze since it's loaded on dem
|
||||||
|
|
||||||
my $out = ref($ret) ? Dumper( $ret ) : "" . $ret;
|
my $out = ref($ret) ? Dumper( $ret ) : "" . $ret;
|
||||||
|
|
||||||
print $out;
|
print $out unless $outbuffer;
|
||||||
|
|
||||||
if( $@ ) { print "ERROR: $@" }
|
if( $@ ) { print "ERROR: $@" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue