Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

&capture, &capture_on, &capture_off

  • Loading branch information...
commit 5a486d80c1bd54b299926acea1a47a9adaf7db2b 1 parent 7e47e7d
@sergot authored
Showing with 23 additions and 3 deletions.
  1. +6 −0 examples/e2.p6
  2. +17 −3 lib/IO/Capture/Simple.pm
View
6 examples/e2.p6
@@ -0,0 +1,6 @@
+use v6;
+use IO::Capture::Simple;
+
+my ($out, $err, $in) = capture { print "OUT"; note "ERR"; }
+
+say $out, $err, $in;
View
20 lib/IO/Capture/Simple.pm
@@ -5,11 +5,19 @@ my $stderr = $*ERR;
my $stdin = $*IN;
sub capture(Callable $code) is export {
- ...
+ my ($out, $err, $in);
+
+ capture_on($out, $err, $in);
+ $code.();
+ capture_off;
+
+ $out, $err, $in;
}
-sub capture_on($target is rw) is export {
- ...
+sub capture_on($out is rw, $err is rw, $in is rw) is export {
+ capture_stdout_on($out);
+ capture_stderr_on($err);
+ capture_stdin_on($in);
}
sub capture_stdout(Callable $code) is export {
@@ -75,3 +83,9 @@ sub capture_stderr_off is export {
sub capture_stdin_off is export {
$*IN = $stdin;
}
+
+sub capture_off is export {
+ $*OUT = $stdout;
+ $*ERR = $stderr;
+ $*IN = $stdin;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.