Commit | Line | Data |
9c216915 |
1 | #!perl |
2 | |
3 | use Test::More tests => 3; |
4 | |
5 | { |
6 | eval "use PerlIO::scalar"; |
7 | plan skip_all => 'PerlIO::scalar required' if $@; |
8 | } |
9 | |
10 | use strict; |
11 | use warnings; |
12 | |
13 | use HTTP::Request; |
14 | use HTTP::Request::AsCGI; |
15 | |
16 | my $r = HTTP::Request->new( POST => 'http://www.host.com/'); |
17 | $r->content('STDIN'); |
18 | $r->content_length(5); |
19 | $r->content_type('text/plain'); |
20 | |
21 | open( my $stdin, ' +<', \( my $stdin_scalar ) ) |
22 | or die qq/Couldn't open a new PerlIO::scalar/; |
23 | |
24 | open( my $stdout, '+>', \( my $stdout_scalar ) ) |
25 | or die qq/Couldn't open a new PerlIO::scalar/; |
26 | |
27 | open( my $stderr, '+>', \( my $stderr_scalar ) ) |
28 | or die qq/Couldn't open a new PerlIO::scalar/; |
29 | |
30 | my $c = HTTP::Request::AsCGI->new( |
31 | request => $r, |
32 | dup => 0, |
33 | stdin => $stdin, |
34 | stdout => $stdout, |
35 | stderr => $stderr |
36 | ); |
37 | |
38 | $c->setup; |
39 | |
40 | print STDOUT 'STDOUT'; |
41 | print STDERR 'STDERR'; |
42 | |
43 | $c->restore; |
44 | |
45 | is( $c->stdin->getline, 'STDIN', 'STDIN' ); |
46 | is( $c->stdout->getline, 'STDOUT', 'STDOUT' ); |
47 | is( $c->stderr->getline, 'STDERR', 'STDERR' ); |