1 | 1 |
use strict;
|
2 | 2 |
use warnings;
|
3 | 3 |
use Carp qw(carp cluck);
|
4 | |
use Try:Tiny;
|
5 | |
|
6 | |
our $VERSION = '3.05';
|
|
4 |
use Try::Tiny;
|
|
5 |
|
|
6 |
our $VERSION = '3.07';
|
7 | 7 |
our $DEBUG = 0;
|
8 | 8 |
|
9 | 9 |
BEGIN {
|
|
341 | 341 |
$path_info = "/$path_info" unless(index($path_info, '/') == 0);
|
342 | 342 |
$path_info = "$path_info/" unless(substr($path_info, -1) eq '/');
|
343 | 343 |
|
344 | |
my ($module, $rm, $local_prefix, $local_args_to_new);
|
|
344 |
my ($module, $rm, $local_prefix, $local_args_to_new, $output);
|
345 | 345 |
|
346 | 346 |
# take args from path
|
347 | 347 |
my $named_args;
|
|
349 | 349 |
$named_args = $self->_parse_path($path_info, $args{table})
|
350 | 350 |
or throw_not_found("Resource not found");
|
351 | 351 |
} catch {
|
352 | |
$e = Exception::Class‐>caught();
|
353 | |
return $self->http_error($e, $args{error_document});
|
|
352 |
$output = $self->http_error($_, $args{error_document});
|
354 | 353 |
};
|
|
354 |
return $output if $output;
|
355 | 355 |
|
356 | 356 |
if($DEBUG) {
|
357 | 357 |
require Data::Dumper;
|
358 | 358 |
warn "[Dispatch] Named args from match: " . Data::Dumper::Dumper($named_args) . "\n";
|
359 | 359 |
}
|
360 | 360 |
|
361 | |
if(exists($named_args->{PARAMS}) || exists($named_args->{TMPL_PATH})) {
|
362 | |
carp "PARAMS and TMPL_PATH are not allowed here. Did you mean to use args_to_new?";
|
363 | |
throw_error("PARAMS and TMPL_PATH not allowed");
|
364 | |
}
|
365 | |
|
366 | 361 |
# eval and catch any exceptions that might be thrown
|
367 | |
my ($output, @final_dispatch_args);
|
368 | 362 |
try {
|
|
363 |
if(exists($named_args->{PARAMS}) || exists($named_args->{TMPL_PATH})) {
|
|
364 |
carp "PARAMS and TMPL_PATH are not allowed here. Did you mean to use args_to_new?";
|
|
365 |
throw_error("PARAMS and TMPL_PATH not allowed");
|
|
366 |
}
|
|
367 |
|
369 | 368 |
($module, $local_prefix, $rm, $local_args_to_new) =
|
370 | 369 |
delete @{$named_args}{qw(app prefix rm args_to_new)};
|
371 | 370 |
|
|
401 | 400 |
}
|
402 | 401 |
|
403 | 402 |
# load and run the module
|
404 | |
@final_dispatch_args = ($module, $rm, $local_args_to_new);
|
405 | 403 |
$self->require_module($module);
|
406 | 404 |
$output = $self->_run_app($module, $rm, $local_args_to_new);
|
407 | 405 |
} catch {
|
408 | |
$e = Exception::Class‐>caught();
|
409 | |
return $self->http_error($e, $args{error_document});
|
|
406 |
my $e = $_;
|
|
407 |
unless ( ref $e ) {
|
|
408 |
local $@ = $e;
|
|
409 |
$e = Exception::Class->caught();
|
|
410 |
}
|
|
411 |
$output = $self->http_error($e, $args{error_document});
|
410 | 412 |
};
|
411 | 413 |
return $output;
|
412 | 414 |
}
|