1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
use strict;
use warnings FATAL => 'all';
use Test::More (
eval { require HTTP::Request::AsCGI }
? 'no_plan'
: (skip_all => 'No HTTP::Request::AsCGI')
);
use HTTP::Request::Common qw(GET POST);
my $app = StreamTest->new;
ok run_request( $app, GET 'http://localhost/' )->is_success;
is run_request( $app, GET 'http://localhost/' )->content, "foo";
sub run_request {
my ( $app, $request ) = @_;
my $c = HTTP::Request::AsCGI->new( $request )->setup;
$app->run;
$c->restore;
return $c->response;
}
{
package StreamTest;
use Web::Simple;
sub dispatch_request {
sub (GET) {
[
sub {
my $respond = shift;
my $writer = $respond->( [ 200, [ "Content-type" => "text/plain" ] ] );
$writer->write( 'f' );
$writer->write( 'o' );
$writer->write( 'o' );
}
];
},;
}
}
|