Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

stderr

  • Loading branch information...
commit 9d93929ef4c593bd7839e0494209b92b68ba6220 1 parent a839819
@sergot authored
Showing with 44 additions and 3 deletions.
  1. +25 −2 lib/IO/Capture/Simple.pm
  2. +1 −1  t/t0.p6
  3. +18 −0 t/t1.p6
View
27 lib/IO/Capture/Simple.pm
@@ -1,6 +1,7 @@
module IO::Capture::Simple;
my $stdout = $*OUT;
+my $stderr = $*ERR;
multi sub capture(Block $code) is export {
...
@@ -29,13 +30,35 @@ multi sub capture_stdout($target is rw) {
}
multi sub capture_stderr(Block $code) is export {
- ...
+ my $result;
+
+ my $*ERR = class {
+ method print(*@args) {
+ $result ~= @args.join;
+ }
+ }
+
+ $code.();
+
+ $result;
+}
+
+multi sub capture_stderr($target is rw) is export {
+ $*ERR = class {
+ method print(*@args) {
+ $target ~= @args.join;
+ }
+ }
}
multi sub capture_stdin(Block $code) is export {
...
}
-sub stdout_off is export {
+sub capture_stdout_off is export {
$*OUT = $stdout;
}
+
+sub capture_stderr_off is export {
+ $*ERR = $stderr;
+}
View
2  t/t0.p6
@@ -12,5 +12,5 @@ $r = '';
capture_stdout($r);
print $test;
-stdout_off;
+capture_stdout_off;
ok $r ~~ $test;
View
18 t/t1.p6
@@ -0,0 +1,18 @@
+use IO::Capture::Simple;
+use Test;
+
+plan 2;
+
+my $test = "OH HAI!";
+
+my $r = capture_stderr { note $test }
+
+ok $r ~~ /$test/;
+
+$r = '';
+
+capture_stderr($r);
+note $test;
+capture_stderr_off;
+
+ok $r ~~ /$test/;
Please sign in to comment.
Something went wrong with that request. Please try again.