use Plack::Util;
use Class::Load 'load_class';
use Encode 2.21 'decode_utf8', 'encode_utf8';
+use Scalar::Util;
BEGIN { require 5.008003; }
__PACKAGE__->_encode_check(Encode::FB_CROAK | Encode::LEAVE_SRC);
# Remember to update this in Catalyst::Runtime as well!
-our $VERSION = '5.90106';
+our $VERSION = '5.90113';
$VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
sub import {
};
$c->log_request;
+ $c->{stash} = $c->stash;
+ Scalar::Util::weaken($c->{stash});
return $c;
}
=head2 handle_unicode_encoding_exception
-Hook to let you customize how encoding errors are handled. By default
+Hook to let you customize how encoding errors are handled. By default
we just throw an exception and the default error page will pick it up.
-Receives a hashref of debug information. Example of call:
+Receives a hashref of debug information. Example of call (from the
+Catalyst internals):
- $c->handle_unicode_encoding_exception({
+ my $decoded_after_fail = $c->handle_unicode_encoding_exception({
param_value => $value,
error_msg => $_,
encoding_step => 'params',
- });
+ });
-It expects to receive a decoded string.
+The calling code expects to receive a decoded string or an exception.
You can override this for custom handling of unicode errors. By
default we just die. If you want a custom response here, one approach
return $value if blessed($value); #don't decode when the value is an object.
my $enc = $self->encoding;
+
+ return $value unless $enc; # don't decode if no encoding is specified
+
$check ||= $self->_encode_check;
return try {
$enc->decode( $value, $check);