Guest User

Untitled

a guest
Jan 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. diff --git a/lib/CGI/Application/Dispatch.pm b/lib/CGI/Application/Dispatch.pm
  2. index 5a5dab2..0f26b3e 100644
  3. --- a/lib/CGI/Application/Dispatch.pm
  4. +++ b/lib/CGI/Application/Dispatch.pm
  5. @@ -2,7 +2,7 @@ package CGI::Application::Dispatch;
  6. use strict;
  7. use warnings;
  8. use Carp qw(carp cluck);
  9. -use Try:Tiny;
  10. +use Try::Tiny;
  11.  
  12. our $VERSION = '3.04';
  13. our $DEBUG = 0;
  14. @@ -342,7 +342,7 @@ sub dispatch {
  15. $path_info = "/$path_info" unless(index($path_info, '/') == 0);
  16. $path_info = "$path_info/" unless(substr($path_info, -1) eq '/');
  17.  
  18. - my ($module, $rm, $local_prefix, $local_args_to_new);
  19. + my ($module, $rm, $local_prefix, $local_args_to_new, $output);
  20.  
  21. # take args from path
  22. my $named_args;
  23. @@ -350,23 +350,22 @@ sub dispatch {
  24. $named_args = $self->_parse_path($path_info, $args{table})
  25. or throw_not_found("Resource not found");
  26. } catch {
  27. - $e = Exception::Class‐>caught();
  28. - return $self->http_error($e, $args{error_document});
  29. + $output = $self->http_error($_, $args{error_document});
  30. };
  31. + return $output if $output;
  32.  
  33. if($DEBUG) {
  34. require Data::Dumper;
  35. warn "[Dispatch] Named args from match: " . Data::Dumper::Dumper($named_args) . "\n";
  36. }
  37.  
  38. - if(exists($named_args->{PARAMS}) || exists($named_args->{TMPL_PATH})) {
  39. - carp "PARAMS and TMPL_PATH are not allowed here. Did you mean to use args_to_new?";
  40. - throw_error("PARAMS and TMPL_PATH not allowed");
  41. - }
  42. -
  43. # eval and catch any exceptions that might be thrown
  44. - my ($output, @final_dispatch_args);
  45. try {
  46. + if(exists($named_args->{PARAMS}) || exists($named_args->{TMPL_PATH})) {
  47. + carp "PARAMS and TMPL_PATH are not allowed here. Did you mean to use args_to_new?";
  48. + throw_error("PARAMS and TMPL_PATH not allowed");
  49. + }
  50. +
  51. ($module, $local_prefix, $rm, $local_args_to_new) =
  52. delete @{$named_args}{qw(app prefix rm args_to_new)};
  53.  
  54. @@ -402,12 +401,15 @@ sub dispatch {
  55. }
  56.  
  57. # load and run the module
  58. - @final_dispatch_args = ($module, $rm, $local_args_to_new);
  59. $self->require_module($module);
  60. $output = $self->_run_app($module, $rm, $local_args_to_new);
  61. } catch {
  62. - $e = Exception::Class‐>caught();
  63. - return $self->http_error($e, $args{error_document});
  64. + my $e = $_;
  65. + unless ( ref $e ) {
  66. + local $@ = $e;
  67. + $e = Exception::Class->caught();
  68. + }
  69. + $output = $self->http_error($e, $args{error_document});
  70. };
  71. return $output;
  72. }
Add Comment
Please, Sign In to add comment