Prancer

 view release on metacpan or  search on metacpan

lib/Prancer/Response.pm  view on Meta::CPAN

    $self->{'_response'}->headers($headers);

    if (ref($self->{'_callback'}) &&
        ref($self->{'_callback'}) eq "CODE") {

        # the extra array ref brackets around the sub are because Web::Simple,
        # which we use as the router, will not do a callback without them. by
        # returning an array ref we are telling Web::Simple that we are giving
        # it a PSGI response. from the Web::Simple docs:
        #
        #     Well, a sub is a valid PSGI response too (for ultimate streaming
        #     and async cleverness). If you want to return a PSGI sub you have
        #     to wrap it into an array ref.
        #
        return [ sub {
            my $responder = shift;

            # this idiom here borrows heavily from the documentation on this
            # blog post, by tatsuhiko miyagawa:
            #
            #   http://bulknews.typepad.com/blog/2009/10/psgiplack-streaming-is-now-complete.html
            #
            # this effectively allows the user of this api to stream data to
            # the client.

            # finalize will always return a three element array. the third
            # element is supposed to be the body. because we don't have a body
            # yet (it's in the callback), this uses splice to exclude the third
            # element (aka the body) and just return the status code and the
            # list of headers.
            my $writer = $responder->([splice(@{$self->{'_response'}->finalize()}, 0, 2)]);

lib/Prancer/Response.pm  view on Meta::CPAN


=item body

Send buffered output to the client. Anything sent to the client with this
method will be buffered until C<finalize> is called. For example:

    $response->body("hello");
    $response->body("goodbye", "world");

If a buffered response is not desired then the body may be a callback to send a
streaming response to the client. Any headers or response codes set in the
callback will be ignored as they must all be set beforehand. Any body set
before a callback is set will also be ignored. For example:

    $response->body(sub {
        my $writer = shift;
        $writer->write("Hello, world!");
        $writer->close();
        return;
    });

t/101.request.t  view on Meta::CPAN

          'SCRIPT_NAME' => '',
          'SERVER_NAME' => 0,
          'SERVER_PORT' => 5000,
          'SERVER_PROTOCOL' => 'HTTP/1.0',
          'psgi.input' => undef,
          'psgi.errors' => undef,
          'psgi.multiprocess' => '',
          'psgi.multithread' => '',
          'psgi.nonblocking' => '',
          'psgi.run_once' => '',
          'psgi.streaming' => 1,
          'psgi.url_scheme' => 'http',
          'psgi.version' => [ 1, 1 ],
          'psgix.harakiri' => 1,
          'psgix.input.buffered' => 1,
    });

    isa_ok($req, 'Prancer::Request');
    is($req->uri(), 'http://localhost:5000/asdf');
    is($req->base(), 'http://localhost:5000/');
    is($req->method(), 'GET');

t/101.request.t  view on Meta::CPAN

          'SCRIPT_NAME' => '',
          'SERVER_NAME' => 0,
          'SERVER_PORT' => 5000,
          'SERVER_PROTOCOL' => 'HTTP/1.0',
          'psgi.input' => undef,
          'psgi.errors' => undef,
          'psgi.multiprocess' => '',
          'psgi.multithread' => '',
          'psgi.nonblocking' => '',
          'psgi.run_once' => '',
          'psgi.streaming' => 1,
          'psgi.url_scheme' => 'http',
          'psgi.version' => [ 1, 1 ],
          'psgix.harakiri' => 1,
          'psgix.input.buffered' => 1,
    });

    {
        my @keys = $req->param();
        is_deeply([ sort @keys ], [ 'baz', 'foo', 'qwerty' ]);



( run in 0.247 second using v1.01-cache-2.11-cpan-4d50c553e7e )