Catalyst-Runtime

 view release on metacpan or  search on metacpan

lib/Catalyst.pm  view on Meta::CPAN


    $c->response->_context($c);
    $c->stats($class->stats_class->new)->enable($c->use_stats);

    if ( $c->debug || $c->config->{enable_catalyst_header} ) {
        $c->res->headers->header( 'X-Catalyst' => $Catalyst::VERSION );
    }

    try {
        # Allow engine to direct the prepare flow (for POE)
        if ( my $prepare = $c->engine->can('prepare') ) {
            $c->engine->$prepare( $c, @arguments );
        }
        else {
            $c->prepare_request(@arguments);
            $c->prepare_connection;
            $c->prepare_query_parameters;
            $c->prepare_headers; # Just hooks, no longer needed - they just
            $c->prepare_cookies; # cause the lazy attribute on req to build
            $c->prepare_path;

            # Prepare the body for reading, either by prepare_body
            # or the user, if they are using $c->read
            $c->prepare_read;

            # Parse the body unless the user wants it on-demand
            unless ( ref($c)->config->{parse_on_demand} ) {
                $c->prepare_body;
            }
        }
        $c->prepare_action;
    }
    # VERY ugly and probably shouldn't rely on ->finalize actually working
    catch {
        # failed prepare is always due to an invalid request, right?
        # Note we call finalize and then die here, which escapes
        # finalize being called in the enclosing block..
        # It in fact couldn't be called, as we don't return $c..
        # This is a mess - but I'm unsure you can fix this without
        # breaking compat for people doing crazy things (we should set
        # the 400 and just return the ctx here IMO, letting finalize get called
        # above...
        if ( $c->_handle_http_exception($_) ) {
            foreach my $err (@{$c->error}) {
                $c->log->error($err);
            }
            $c->clear_errors;
            $c->log->_flush if $c->log->can('_flush');
            $_->can('rethrow') ? $_->rethrow : croak $_;
        } else {
            $c->response->status(400);
            $c->response->content_type('text/plain');
            $c->response->body('Bad Request');
            $c->finalize;
            die $_;
        }
    };

    $c->log_request;
    $c->{stash} = $c->stash;
    Scalar::Util::weaken($c->{stash});

    return $c;
}

=head2 $c->prepare_action

Prepares action. See L<Catalyst::Dispatcher>.

=cut

sub prepare_action {
    my $c = shift;
    my $ret = $c->dispatcher->prepare_action( $c, @_);

    if($c->encoding) {
        foreach (@{$c->req->arguments}, @{$c->req->captures}) {
          $_ = $c->_handle_param_unicode_decoding($_);
        }
    }

    return $ret;
}


=head2 $c->prepare_body

Prepares message body.

=cut

sub prepare_body {
    my $c = shift;

    return if $c->request->_has_body;

    # Initialize on-demand data
    $c->engine->prepare_body( $c, @_ );
    $c->prepare_parameters;
    $c->prepare_uploads;
}

=head2 $c->prepare_body_chunk( $chunk )

Prepares a chunk of data before sending it to L<HTTP::Body>.

See L<Catalyst::Engine>.

=cut

sub prepare_body_chunk {
    my $c = shift;
    $c->engine->prepare_body_chunk( $c, @_ );
}

=head2 $c->prepare_body_parameters

Prepares body parameters.

=cut



( run in 1.606 second using v1.01-cache-2.11-cpan-39bf76dae61 )