Capture-Tiny
view release on metacpan or search on metacpan
t/18-custom-capture.t view on Meta::CPAN
my $err_fh = IO::File->new($temp_err, "w+");
capture {
print STDOUT "foo\n";
print STDERR "bar\n";
} stdout => $out_fh, stderr => $err_fh;
$out_fh->close;
$err_fh->close;
is( scalar do {local (@ARGV,$/) = $temp_out; <>} , "foo\n",
"captured STDOUT to custom handle (IO::File)"
);
is( scalar do {local (@ARGV,$/) = $temp_err; <>} , "bar\n",
"captured STDERR to custom handle (IO::File)"
);
unlink $_ for $temp_out, $temp_err;
#--------------------------------------------------------------------------#
# capture to GLOB handle
#--------------------------------------------------------------------------#
$temp_out = tmpnam();
t/18-custom-capture.t view on Meta::CPAN
open $err_fh, "+>", $temp_err;
capture {
print STDOUT "foo\n";
print STDERR "bar\n";
} stdout => $out_fh, stderr => $err_fh;
$out_fh->close;
$err_fh->close;
is( scalar do {local (@ARGV,$/) = $temp_out; <>} , "foo\n",
"captured STDOUT to custom handle (GLOB)"
);
is( scalar do {local (@ARGV,$/) = $temp_err; <>} , "bar\n",
"captured STDERR to custom handle (GLOB)"
);
unlink $_ for $temp_out, $temp_err;
#--------------------------------------------------------------------------#
# append to custom IO::File
#--------------------------------------------------------------------------#
$temp_out = tmpnam();
( run in 1.421 second using v1.01-cache-2.11-cpan-49f99fa48dc )