for qw/components arguments dispatcher engine log dispatcher_class
engine_loader context_class request_class response_class stats_class
setup_finished _psgi_app loading_psgi_file run_options _psgi_middleware
- _data_handlers _encoding _encode_check/;
+ _data_handlers _encoding _encode_check finalized_default_middleware/;
__PACKAGE__->dispatcher_class('Catalyst::Dispatcher');
__PACKAGE__->request_class('Catalyst::Request');
__PACKAGE__->_encode_check(Encode::FB_CROAK | Encode::LEAVE_SRC);
# Remember to update this in Catalyst::Runtime as well!
-our $VERSION = '5.90079_006';
+our $VERSION = '5.90082';
$VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
sub import {
=head2 encoding
-Sets or gets the application encoding.
+Sets or gets the application encoding. Setting encoding takes either an
+Encoding object or a string that we try to resolve via L<Encode::find_encoding>.
+
+You would expect to get the encoding object back if you attempt to set it. If
+there is a failure you will get undef returned and an error message in the log.
=cut
if(blessed $c) {
$c->encoding(undef);
} else {
- $c->debug->error("You can't clear encoding on the application");
+ $c->log->error("You can't clear encoding on the application");
}
}
my $encoding;
if ( scalar @_ ) {
+
+ # Don't let one change this once we are too far into the response
+ if(blessed $c && $c->res->finalized_headers) {
+ Carp::croak("You may not change the encoding once the headers are finalized");
+ return;
+ }
+
# Let it be set to undef
if (my $wanted = shift) {
$encoding = Encode::find_encoding($wanted)
@middleware_definitions = reverse(@_);
} else {
@middleware_definitions = reverse(@{$class->config->{'psgi_middleware'}||[]})
- unless $class->config->{__configured_from_psgi_middleware};
- $class->config->{__configured_from_psgi_middleware} = 1; # Only do this once, just in case some people call setup over and over...
+ unless $class->finalized_default_middleware;
+ $class->finalized_default_middleware(1); # Only do this once, just in case some people call setup over and over...
}
my @middleware = ();
return eval {
local $/;
$slurped = $fh->getline;
- $parser->can("decode_json")->($slurped);
+ $parser->can("decode_json")->($slurped); # decode_json does utf8 decoding for us
} || Catalyst::Exception->throw(sprintf "Error Parsing POST '%s', Error: %s", (defined($slurped) ? $slurped : 'undef') ,$@);
},
};