Compiler-Parser

 view release on metacpan or  search on metacpan

t/app/Plack/Handler/Apache1.t  view on Meta::CPAN

                                            },
                                            right => branch { '=>',
                                                left => leaf 'psgi.run_once',
                                                right => function_call { 'Plack::Util::FALSE',
                                                    args => [
                                                    ],
                                                },
                                            },
                                        },
                                        right => branch { '=>',
                                            left => leaf 'psgi.streaming',
                                            right => function_call { 'Plack::Util::TRUE',
                                                args => [
                                                ],
                                            },
                                        },
                                    },
                                    right => branch { '=>',
                                        left => leaf 'psgi.nonblocking',
                                        right => function_call { 'Plack::Util::FALSE',
                                            args => [

t/app/Plack/Handler/Apache1.t  view on Meta::CPAN


    my $env = {
        %ENV,
        'psgi.version'        => [ 1, 1 ],
        'psgi.url_scheme'     => ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
        'psgi.input'          => $r,
        'psgi.errors'         => *STDERR,
        'psgi.multithread'    => Plack::Util::FALSE,
        'psgi.multiprocess'   => Plack::Util::TRUE,
        'psgi.run_once'       => Plack::Util::FALSE,
        'psgi.streaming'      => Plack::Util::TRUE,
        'psgi.nonblocking'    => Plack::Util::FALSE,
        'psgix.harakiri'      => Plack::Util::TRUE,
    };

    if (defined(my $HTTP_AUTHORIZATION = $r->headers_in->{Authorization})) {
        $env->{HTTP_AUTHORIZATION} = $HTTP_AUTHORIZATION;
    }

    my $vpath    = $env->{SCRIPT_NAME} . ($env->{PATH_INFO} || '');

t/app/Plack/Handler/Apache2.t  view on Meta::CPAN

                                                    },
                                                    right => branch { '=>',
                                                        left => leaf 'psgi.run_once',
                                                        right => function_call { 'Plack::Util::FALSE',
                                                            args => [
                                                            ],
                                                        },
                                                    },
                                                },
                                                right => branch { '=>',
                                                    left => leaf 'psgi.streaming',
                                                    right => function_call { 'Plack::Util::TRUE',
                                                        args => [
                                                        ],
                                                    },
                                                },
                                            },
                                            right => branch { '=>',
                                                left => leaf 'psgi.nonblocking',
                                                right => function_call { 'Plack::Util::FALSE',
                                                    args => [

t/app/Plack/Handler/Apache2.t  view on Meta::CPAN


    my $env = {
        %ENV,
        'psgi.version'           => [ 1, 1 ],
        'psgi.url_scheme'        => ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
        'psgi.input'             => $r,
        'psgi.errors'            => *STDERR,
        'psgi.multithread'       => Plack::Util::FALSE,
        'psgi.multiprocess'      => Plack::Util::TRUE,
        'psgi.run_once'          => Plack::Util::FALSE,
        'psgi.streaming'         => Plack::Util::TRUE,
        'psgi.nonblocking'       => Plack::Util::FALSE,
        'psgix.harakiri'         => Plack::Util::TRUE,
        'psgix.cleanup'          => Plack::Util::TRUE,
        'psgix.cleanup.handlers' => [],
    };

    if (defined(my $HTTP_AUTHORIZATION = $r->headers_in->{Authorization})) {
        $env->{HTTP_AUTHORIZATION} = $HTTP_AUTHORIZATION;
    }

t/app/Plack/Handler/CGI.t  view on Meta::CPAN

                                                    left => leaf 'psgi.multiprocess',
                                                    right => leaf '1',
                                                },
                                            },
                                            right => branch { '=>',
                                                left => leaf 'psgi.run_once',
                                                right => leaf '1',
                                            },
                                        },
                                        right => branch { '=>',
                                            left => leaf 'psgi.streaming',
                                            right => leaf '1',
                                        },
                                    },
                                    right => branch { '=>',
                                        left => leaf 'psgi.nonblocking',
                                        right => leaf '1',
                                    },
                                },
                                right => dereference { '%{',
                                    expr => leaf '$override_env',

t/app/Plack/Handler/CGI.t  view on Meta::CPAN


    my $env = {
        %ENV,
        'psgi.version'    => [ 1, 1 ],
        'psgi.url_scheme' => ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
        'psgi.input'      => *STDIN,
        'psgi.errors'     => *STDERR,
        'psgi.multithread'  => 0,
        'psgi.multiprocess' => 1,
        'psgi.run_once'     => 1,
        'psgi.streaming'    => 1,
        'psgi.nonblocking'  => 1,
        %{ $override_env },
    };

    delete $env->{HTTP_CONTENT_TYPE};
    delete $env->{HTTP_CONTENT_LENGTH};
    $env->{'HTTP_COOKIE'} ||= $ENV{COOKIE}; # O'Reilly server bug

    if (!exists $env->{PATH_INFO}) {
        $env->{PATH_INFO} = '';

t/app/Plack/Handler/FCGI.t  view on Meta::CPAN

                                                    },
                                                    right => branch { '=>',
                                                        left => leaf 'psgi.run_once',
                                                        right => function_call { 'Plack::Util::FALSE',
                                                            args => [
                                                            ],
                                                        },
                                                    },
                                                },
                                                right => branch { '=>',
                                                    left => leaf 'psgi.streaming',
                                                    right => function_call { 'Plack::Util::TRUE',
                                                        args => [
                                                        ],
                                                    },
                                                },
                                            },
                                            right => branch { '=>',
                                                left => leaf 'psgi.nonblocking',
                                                right => function_call { 'Plack::Util::FALSE',
                                                    args => [

t/app/Plack/Handler/FCGI.t  view on Meta::CPAN

        my $env = {
            %env,
            'psgi.version'      => [1,1],
            'psgi.url_scheme'   => ($env{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
            'psgi.input'        => $self->{stdin},
            'psgi.errors'       => $self->{stderr}, # FCGI.pm redirects STDERR in Accept() loop, so just print STDERR
                                                    # print to the correct error handle based on keep_stderr
            'psgi.multithread'  => Plack::Util::FALSE,
            'psgi.multiprocess' => Plack::Util::TRUE,
            'psgi.run_once'     => Plack::Util::FALSE,
            'psgi.streaming'    => Plack::Util::TRUE,
            'psgi.nonblocking'  => Plack::Util::FALSE,
            'psgix.harakiri'    => defined $proc_manager,
        };

        delete $env->{HTTP_CONTENT_TYPE};
        delete $env->{HTTP_CONTENT_LENGTH};

        # lighttpd munges multiple slashes in PATH_INFO into one. Try recovering it
        my $uri = URI->new("http://localhost" .  $env->{REQUEST_URI});
        $env->{PATH_INFO} = uri_unescape($uri->path);

t/app/Plack/Loader/Shotgun.t  view on Meta::CPAN

                                            ],
                                        },
                                        leaf '$res',
                                        function_call { 'try',
                                            args => [
                                                [
                                                    branch { '=',
                                                        left => branch { '->',
                                                            left => leaf '$env',
                                                            right => hash_ref { '{}',
                                                                data => leaf 'psgi.streaming',
                                                            },
                                                        },
                                                        right => leaf '0',
                                                    },
                                                    branch { '=',
                                                        left => leaf '$res',
                                                        right => branch { '->',
                                                            left => branch { '->',
                                                                left => branch { '->',
                                                                    left => leaf '$self',

t/app/Plack/Loader/Shotgun.t  view on Meta::CPAN

            close $read;
            waitpid($pid, 0);

            return $res;
        } else {
            # child
            close $read;

            my $res;
            try {
                $env->{'psgi.streaming'} = 0;
                $res = $self->{builder}->()->($env);
                my @body;
                Plack::Util::foreach($res->[2], sub { push @body, $_[0] });
                $res->[2] = \@body;
            } catch {
                $env->{'psgi.errors'}->print($_);
                $res = [ 500, [ "Content-Type", "text/plain" ], [ "Internal Server Error" ] ];
            };

            print {$write} Storable::freeze($res);

t/app/Plack/Middleware.t  view on Meta::CPAN

  sub call {
      my($self, $env) = @_;
      # pre-processing $env
      my $res = $self->app->($env);
      # post-processing $res
      return $res;
  }

The tricky thing about post-processing the response is that it could
either be an immediate 3 element array ref, or a code reference that
implements the delayed (streaming) interface.

Dealing with these two types of response in each piece of middleware
is pointless, so you're recommended to use the C<response_cb> wrapper
function in L<Plack::Util> when implementing a post processing
middleware.

  my $res = $app->($env);
  Plack::Util::response_cb($res, sub {
      my $res = shift;
      # do something with $res;

t/app/Plack/Middleware.t  view on Meta::CPAN

do:

  Plack::Util::response_cb($res, sub {
      my $res = shift;
      @$res = ($new_status, $new_headers, $new_body); # THIS WORKS
      return;
  });

The third element of the PSGI response array ref is a body, and it could
be either an arrayref or L<IO::Handle>-ish object. The application could
also make use of the C<$writer> object if C<psgi.streaming> is in
effect. Dealing with these variants is again really painful, and
C<response_cb> can take care of that too, by allowing you to return a
content filter as a code reference.

  # replace all "Foo" in content body with "Bar"
  Plack::Util::response_cb($res, sub {
      my $res = shift;
      return sub {
          my $chunk = shift;
          return unless defined $chunk;

t/app/Plack/Test/Suite.t  view on Meta::CPAN

                                                                                left => leaf '$env',
                                                                                right => function_call { 'shift',
                                                                                    args => [
                                                                                    ],
                                                                                },
                                                                            },
                                                                            branch { 'or',
                                                                                left => branch { '->',
                                                                                    left => leaf '$env',
                                                                                    right => hash_ref { '{}',
                                                                                        data => leaf 'psgi.streaming',
                                                                                    },
                                                                                },
                                                                                right => Test::Compiler::Parser::return { 'return',
                                                                                    body => array_ref { '[]',
                                                                                        data => branch { ',',
                                                                                            left => branch { ',',
                                                                                                left => leaf '501',
                                                                                                right => array_ref { '[]',
                                                                                                    data => branch { ',',
                                                                                                        left => leaf 'Content-Type',

t/app/Plack/Test/Suite.t  view on Meta::CPAN

                                                                        ],
                                                                    },
                                                                },
                                                            },
                                                        },
                                                    },
                                                    right => array_ref { '[]',
                                                        data => branch { ',',
                                                            left => branch { ',',
                                                                left => branch { ',',
                                                                    left => leaf 'coderef streaming',
                                                                    right => function { 'sub',
                                                                        body => [
                                                                            branch { '=',
                                                                                left => leaf '$cb',
                                                                                right => function_call { 'shift',
                                                                                    args => [
                                                                                    ],
                                                                                },
                                                                            },
                                                                            branch { '=',

t/app/Plack/Test/Suite.t  view on Meta::CPAN

                                                                            left => leaf '$env',
                                                                            right => function_call { 'shift',
                                                                                args => [
                                                                                ],
                                                                            },
                                                                        },
                                                                        branch { 'or',
                                                                            left => branch { '->',
                                                                                left => leaf '$env',
                                                                                right => hash_ref { '{}',
                                                                                    data => leaf 'psgi.streaming',
                                                                                },
                                                                            },
                                                                            right => Test::Compiler::Parser::return { 'return',
                                                                                body => array_ref { '[]',
                                                                                    data => branch { ',',
                                                                                        left => branch { ',',
                                                                                            left => leaf '501',
                                                                                            right => array_ref { '[]',
                                                                                                data => branch { ',',
                                                                                                    left => leaf 'Content-Type',

t/app/Plack/Test/Suite.t  view on Meta::CPAN

            my $res = $cb->(GET "http://127.0.0.1/?name=miyagawa");
            return if $res->code == 501;

            is $res->code, 200;
            is $res->message, 'OK';
            is $res->header('content_type'), 'text/plain';
            is $res->content, 'Hello, name=miyagawa';
        },
        sub {
            my $env = shift;
            $env->{'psgi.streaming'} or return [ 501, ['Content-Type','text/plain'], [] ];
            return sub {
                my $respond = shift;
                $respond->([
                    200,
                    [ 'Content-Type' => 'text/plain', ],
                    [ 'Hello, ' . $env->{QUERY_STRING} ],
                ]);
            }
        },
    ],
    [
        'coderef streaming',
        sub {
            my $cb = shift;
            my $res = $cb->(GET "http://127.0.0.1/?name=miyagawa");
            return if $res->code == 501;

            is $res->code, 200;
            is $res->message, 'OK';
            is $res->header('content_type'), 'text/plain';
            is $res->content, 'Hello, name=miyagawa';
        },
        sub {
            my $env = shift;
            $env->{'psgi.streaming'} or return [ 501, ['Content-Type','text/plain'], [] ];

            return sub {
                my $respond = shift;

                my $writer = $respond->([
                    200,
                    [ 'Content-Type' => 'text/plain', ],
                ]);

                $writer->write("Hello, ");



( run in 0.297 second using v1.01-cache-2.11-cpan-a5abf4f5562 )