about summary refs log tree commit homepage
path: root/t/common.perl
diff options
context:
space:
mode:
Diffstat (limited to 't/common.perl')
-rw-r--r--t/common.perl16
1 files changed, 16 insertions, 0 deletions
diff --git a/t/common.perl b/t/common.perl
new file mode 100644
index 00000000..a3585bf6
--- /dev/null
+++ b/t/common.perl
@@ -0,0 +1,16 @@
+require IO::File;
+use POSIX qw/dup/;
+
+sub stream_to_string {
+        my ($cb) = @_;
+        my $headers;
+        my $io = IO::File->new_tmpfile;
+        my $dup = dup($io->fileno);
+        my $response = sub { $headers = \@_, $io };
+        $cb->($response);
+        $io = IO::File->new;
+        $io->fdopen($dup, 'r+');
+        $io->seek(0, 0);
+        $io->read(my $str, ($io->stat)[7]);
+        $str;
+}