Permalink
Browse files

support coderef

  • Loading branch information...
tokuhirom committed Sep 4, 2009
1 parent f1107e3 commit 16ff47fadb01d602f259e9f47160a825030e72cb
Showing with 47 additions and 1 deletion.
  1. +5 −0 lib/PSGIRef/Interface/CGI.pm
  2. +5 −0 lib/PSGIRef/Interface/ServerSimple.pm
  3. +37 −1 lib/PSGIRef/Test.pm
@@ -26,6 +26,11 @@ sub run {
if (ref $res->[2] eq 'GLOB') {
my $fh = $res->[2];
print $_ while <$fh>;
+ } elsif (ref $res->[2] eq 'CODE') {
+ my $code = $res->[2];
+ while (defined(my $buf = $code->())) {
+ print $buf;
+ }
} else {
print $res->[2];
}
@@ -34,6 +34,11 @@ use PSGIRef::Interface::CGI;
if (ref $res->[2] eq 'GLOB') {
my $fh = $res->[2];
print $_ while <$fh>;
+ } elsif (ref $res->[2] eq 'CODE') {
+ my $code = $res->[2];
+ while (defined(my $buf = $code->())) {
+ print $buf;
+ }
} else {
print $res->[2];
}
View
@@ -98,6 +98,31 @@ my @TEST = (
like $res->content, qr/^package /;
}
],
+ [
+ 'return coderef',
+ sub {
+ my $port = $_[0] || 80;
+ HTTP::Request->new(GET => "http://127.0.0.1:$port/");
+ },
+ sub {
+ my ($env, $start_response) = @_;
+ my $req = PSGIRef::Request->new( $env );
+ my $count = 0;
+ return [
+ 200,
+ { 'Content-Type' => 'text/plain', },
+ sub {
+ $count < 4 ? $count++ : undef;
+ },
+ ];
+ },
+ sub {
+ my $res = shift;
+ is $res->code, 200;
+ is $res->header('content_type'), 'text/plain';
+ is $res->content, '0123';
+ }
+ ],
);
sub count { scalar @TEST }
@@ -112,9 +137,20 @@ __END__
=head1 SYNOPSIS
- my ($name, $handler, $response) = PSGIRef::Test->get_test(0);
+ see tests.
=head1 DESCRIPTION
Test suite for the PSGI spec. This will rename to the PSGI::TestSuite or something.
+=head1 METHODS
+
+=over 4
+
+=item count
+
+count the test cases.
+
+=item my ($name, $reqgen, $handler, $test) = PSGIRef::Test->get_test($i)
+
+=back

0 comments on commit 16ff47f

Please sign in to comment.