]> Sergey Matveev's repositories - public-inbox.git/blob - t/common.perl
update copyright headers and email addresses
[public-inbox.git] / t / common.perl
1 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 require IO::File;
4 use POSIX qw/dup/;
5
6 sub stream_to_string {
7         my ($cb) = @_;
8         my $headers;
9         my $io = IO::File->new_tmpfile;
10         my $dup = dup($io->fileno);
11         my $response = sub { $headers = \@_, $io };
12         $cb->($response);
13         $io = IO::File->new;
14         $io->fdopen($dup, 'r+');
15         $io->seek(0, 0);
16         $io->read(my $str, ($io->stat)[7]);
17         $str;
18 }