Catalyst-Runtime

 view release on metacpan or  search on metacpan

lib/Catalyst.pm  view on Meta::CPAN

return the default error page (production mode).

=cut

sub finalize_error {
    my $c = shift;
    if($#{$c->error} > 0) {
        $c->engine->finalize_error( $c, @_ );
    } else {
        my ($error) = @{$c->error};
        if ( $c->_handle_http_exception($error) ) {
            # In the case where the error 'knows what it wants', becauses its PSGI
            # aware, just rethow and let middleware catch it
            $error->can('rethrow') ? $error->rethrow : croak $error;
        } else {
            $c->engine->finalize_error( $c, @_ )
        }
    }
}

=head2 $c->finalize_headers

Finalizes headers.

=cut

sub finalize_headers {
    my $c = shift;

    my $response = $c->response; #accessor calls can add up?

    # Check if we already finalized headers
    return if $response->finalized_headers;

    # Handle redirects
    if ( my $location = $response->redirect ) {
        $c->log->debug(qq/Redirecting to "$location"/) if $c->debug;
        $response->header( Location => $location );
    }

    # Remove incorrectly added body and content related meta data when returning
    # an information response, or a response the is required to not include a body

    $c->finalize_cookies;

    # This currently is a NOOP but I don't want to remove it since I guess people
    # might have Response subclasses that use it for something... (JNAP)
    $c->response->finalize_headers();

    # Done
    $response->finalized_headers(1);
}

=head2 $c->finalize_encoding

Make sure your body is encoded properly IF you set an encoding.  By
default the encoding is UTF-8 but you can disable it by explicitly setting the
encoding configuration value to undef.

We can only encode when the body is a scalar.  Methods for encoding via the
streaming interfaces (such as C<write> and C<write_fh> on L<Catalyst::Response>
are available).

See L</ENCODING>.

=cut

sub finalize_encoding {
    my $c = shift;
    my $res = $c->res || return;

    # Warn if the set charset is different from the one you put into encoding.  We need
    # to do this early since encodable_response is false for this condition and we need
    # to match the debug output for backcompat (there's a test for this...) -JNAP
    if(
      $res->content_type_charset and $c->encoding and
      (uc($c->encoding->mime_name) ne uc($res->content_type_charset))
    ) {
        my $ct = lc($res->content_type_charset);
        $c->log->debug("Catalyst encoding config is set to encode in '" .
            $c->encoding->mime_name .
            "', content type is '$ct', not encoding ");
    }

    if(
      ($res->encodable_response) and
      (defined($res->body)) and
      (ref(\$res->body) eq 'SCALAR')
    ) {
        # if you are finding yourself here and your body is already encoded correctly
        # and you want to turn this off, use $c->clear_encoding to prevent encoding
        # at this step, or set encoding to undef in the config to do so for the whole
        # application.  See the ENCODING documentaiton for better notes.
        $c->res->body( $c->encoding->encode( $c->res->body, $c->_encode_check ) );

        # Set the charset if necessary.  This might be a bit bonkers since encodable response
        # is false when the set charset is not the same as the encoding mimetype (maybe
        # confusing action at a distance here..
        # Don't try to set the charset if one already exists or if headers are already finalized
        $c->res->content_type($c->res->content_type . "; charset=" . $c->encoding->mime_name)
          unless($c->res->content_type_charset ||
                ($c->res->_context && $c->res->finalized_headers && !$c->res->_has_response_cb));
    }
}

=head2 $c->finalize_output

An alias for finalize_body.

=head2 $c->finalize_read

Finalizes the input after reading is complete.

=cut

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

=head2 $c->finalize_uploads

Finalizes uploads. Cleans up any temporary files.



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