[Catalyst-commits] r14093 - in
Catalyst-Plugin-Unicode-Encoding/branches/decoding_callback:
lib/Catalyst/Plugin/Unicode t/lib
wreis at dev.catalyst.perl.org
wreis at dev.catalyst.perl.org
Tue Sep 6 13:16:20 GMT 2011
Author: wreis
Date: 2011-09-06 13:16:20 +0000 (Tue, 06 Sep 2011)
New Revision: 14093
Modified:
Catalyst-Plugin-Unicode-Encoding/branches/decoding_callback/lib/Catalyst/Plugin/Unicode/Encoding.pm
Catalyst-Plugin-Unicode-Encoding/branches/decoding_callback/t/lib/TestApp.pm
Log:
Allow the app decide what to do regarding uploads too
Modified: Catalyst-Plugin-Unicode-Encoding/branches/decoding_callback/lib/Catalyst/Plugin/Unicode/Encoding.pm
===================================================================
--- Catalyst-Plugin-Unicode-Encoding/branches/decoding_callback/lib/Catalyst/Plugin/Unicode/Encoding.pm 2011-09-06 11:57:51 UTC (rev 14092)
+++ Catalyst-Plugin-Unicode-Encoding/branches/decoding_callback/lib/Catalyst/Plugin/Unicode/Encoding.pm 2011-09-06 13:16:20 UTC (rev 14093)
@@ -102,8 +102,14 @@
for my $value ( values %{ $c->request->uploads } ) {
# skip if it fails for uploads, as we don't usually want uploads touched
# in any way
- try {
- $_->{filename} = $enc->decode( $_->{filename}, $CHECK )
+ $_->{filename} = try {
+ $enc->decode( $_->{filename}, $CHECK )
+ } catch {
+ $c->_handle_unicode_encoding_exception({
+ param_value => $_->{filename},
+ error_msg => $_,
+ encoding_step => 'uploads',
+ });
} for ( ref($value) eq 'ARRAY' ? @{$value} : $value );
}
}
@@ -140,12 +146,35 @@
$value
: $enc->decode( $value, $CHECK );
} catch {
- $self->handle_unicode_encoding_exception($value, $_);
+ $self->_handle_unicode_encoding_exception({
+ param_value => $value,
+ error_msg => $_,
+ encoding_step => 'params',
+ });
};
}
-sub handle_unicode_encoding_exception { die pop }
+sub _handle_unicode_encoding_exception {
+ my ( $self, $exception_ctx ) = @_;
+ my ( $param_value, $error_msg, $encoding_step )
+ = @$exception_ctx{qw(param_value error_msg encoding_step)};
+ my $fallback_action_map = {
+ params => $self->can('handle_unicode_encoding_params_exception'),
+ uploads => $self->can('handle_unicode_encoding_uploads_exception'),
+ };
+ if ( my $do_action = $fallback_action_map->{$encoding_step} ) {
+ return $do_action->($param_value, $error_msg);
+ }
+ else {
+ die $error_msg;
+ }
+}
+
+sub handle_unicode_encoding_params_exception { die pop }
+
+sub handle_unicode_encoding_uploads_exception { shift; return shift }
+
1;
__END__
@@ -200,10 +229,14 @@
Setups C<< $c->encoding >> with encoding specified in C<< $c->config->{encoding} >>.
-=item handle_unicode_encoding_exception
+=item handle_unicode_encoding_params_exception
-Callback method used for failed decoding process.
+Callback method used for failed decoding process for params, args and captures.
+=item handle_unicode_encoding_uploads_exception
+
+Callback method used for failed decoding process for uploads.
+
=back
=head1 SEE ALSO
Modified: Catalyst-Plugin-Unicode-Encoding/branches/decoding_callback/t/lib/TestApp.pm
===================================================================
--- Catalyst-Plugin-Unicode-Encoding/branches/decoding_callback/t/lib/TestApp.pm 2011-09-06 11:57:51 UTC (rev 14092)
+++ Catalyst-Plugin-Unicode-Encoding/branches/decoding_callback/t/lib/TestApp.pm 2011-09-06 13:16:20 UTC (rev 14093)
@@ -12,7 +12,7 @@
__PACKAGE__->setup;
-sub handle_unicode_encoding_exception {
+sub handle_unicode_encoding_params_exception {
my ( $self, $param_value, $error_msg ) = @_;
return $param_value;
}
More information about the Catalyst-commits
mailing list