<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package PrimitiveCapture;
use strict;
use warnings;

if ("$]" &gt;= 5.008000) {
  eval "#line @{[__LINE__+1]} ".q{"lib/PrimitiveCapture.pm"
    sub capture_stdout {
      my $sub = shift;
      my $stdout;
      open my $oldout, "&gt;&amp;STDOUT" or die "Can't dup STDOUT: $!";
      close STDOUT;
      open STDOUT, '&gt;', \$stdout or die "Can't open STDOUT: $!";
      $sub-&gt;();
      close STDOUT;
      open STDOUT, "&gt;&amp;", $oldout or die "Can't dup \$oldout: $!";
      return $stdout;
    }
    sub capture_stderr {
      my $sub = shift;
      my $stderr;
      open my $olderr, "&gt;&amp;STDERR" or die "Can't dup STDERR: $!";
      close STDERR;
      open STDERR, '&gt;', \$stderr or die "Can't open STDERR: $!";
      $sub-&gt;();
      close STDERR;
      open STDERR, "&gt;&amp;", $olderr or die "Can't dup \$olderr: $!";
      return $stderr;
    }
  }; die $@ unless $@ eq "";
} else {
  eval "#line @{[__LINE__+1]} ".q{"lib/PrimitiveCapture.pm"
    use File::Spec;
    use File::Temp;
    my $tmpdir;
    my $i = 0;
    sub _tmpfile {
      $tmpdir ||= File::Temp::tempdir(CLEANUP =&gt; 1, TMPDIR =&gt; 1);
      return File::Spec-&gt;catfile($tmpdir, $i++);
    }
    sub _slurp {
      my $filename = shift;
      open my $fh, "&lt;", $filename or die "Can't read $filename: $!";
      local $/ = undef;
      my $content = &lt;$fh&gt;;
      defined $content or die "Can't read $filename: $!";
      return $content;
    }
    sub capture_stdout {
      my $sub = shift;
      my $tmpfile = _tmpfile();
      local *OLDSTDOUT;
      open OLDSTDOUT, "&gt;&amp;STDOUT" or die "Can't dup STDOUT: $!";
      close STDOUT;
      open STDOUT, '&gt;', $tmpfile or die "Can't open STDOUT: $!";
      $sub-&gt;();
      close STDOUT;
      open STDOUT, "&gt;&amp;OLDSTDOUT" or die "Can't dup OLDSTDOUT: $!";
      close OLDSTDOUT;
      return _slurp($tmpfile);
    }
    sub capture_stderr {
      my $sub = shift;
      my $tmpfile = _tmpfile();
      local *OLDSTDERR;
      open OLDSTDERR, "&gt;&amp;STDERR" or die "Can't dup STDERR: $!";
      close STDERR;
      open STDERR, '&gt;', $tmpfile or die "Can't open STDERR: $!";
      $sub-&gt;();
      close STDERR;
      open STDERR, "&gt;&amp;OLDSTDERR" or die "Can't dup OLDSTDERR: $!";
      close OLDSTDERR;
      return _slurp($tmpfile);
    }
  }; die $@ unless $@ eq "";
}

1;
</pre></body></html>