I've been programming perl quite a few years now but am starting a new job soon, they use Dancer so I thought I would have a bash at it before I start there. I've been having a play at making something and I'm loving Dancer but I seem to have hit on a problem, I'm not sure if it's a bug in Dancer (it almost never is I know!) or if I am misunderstanding how I should be using pass but here it is anyway:
I'm using Module::Load to load a module (containing routes) at runtime and then calling pass. If there are no matching routes this causes a RuntimeError.
Example:
#!/usr/bin/env perl
use Dancer;
use Demo;
dance;
__END__
$ cat lib/Demo.pm
package Demo;
use Dancer qw( :syntax !load );
use Module::Load;
any '/Monitoring/*?' => sub {
my $module = "Monitoring";
load $module;
pass();
};
true;
__END__
$ cat lib/Monitoring.pm
package Monitoring;
use Dancer ':syntax';
prefix '/Monitoring';
get '/' => sub {
return 'Monitoring Service';
};
get '/ping' => sub {
return time;
};
true;
__END__
Runtime Error
runtime error
Can't call method "run" on an undefined value at /usr/share/perl5/Dancer/Route.pm line 212.
/usr/share/perl5/Dancer/Route.pm around line 212
209 $response->pass(0);
210 if ($self->next) {
211 my $next_route = $self->find_next_matching_route($request);
212 return $next_route->run($request);
213 }
214 else {
215 Dancer::Logger::core('Last matching route passed!');
Stack
main in -e l. 0
main in -e l. 0
Plack::Handler::Apache2 in /usr/share/perl5/Plack/Handler/Apache2.pm l. 91
Plack::Handler::Apache2 in /usr/share/perl5/Plack/Handler/Apache2.pm l. 66
Dancer::Handler in /usr/share/perl5/Dancer/Handler.pm l. 123
Dancer::Handler in /usr/share/perl5/Dancer/Handler.pm l. 76
Dancer::Handler in /usr/share/perl5/Dancer/Handler.pm l. 113
Try::Tiny in /usr/share/perl5/Try/Tiny.pm l. 100
Dancer::Exception in /usr/share/perl5/Dancer/Exception.pm l. 47
Dancer::Exception in /usr/share/perl5/Dancer/Exception.pm l. 35
Dancer::Handler in /usr/share/perl5/Dancer/Handler.pm l. 107
Dancer::Object in /usr/share/perl5/Dancer/Object.pm l. 16
Dancer::Error in /usr/share/perl5/Dancer/Error.pm l. 37
Dancer::Error in /usr/share/perl5/Dancer/Error.pm l. 276
I've not posted all of the RuntimeError since it contains sensitive information about my config file and server. If the rest is needed I can spend some time to run up a clean version without anything important in.
I'm using the version of Dancer which comes with Debian 7.
I'm using apache2 with Plack::Handler::Apache2 to run the Dancer application.
My real application is more complex than this but I knocked this one up so it would demo the problem with as little code as possible.
Does anyone know why this RuntimeError occurs, and perhaps how I can avoid it in the situation where I need to load a module dynamically which contains routes. Alternatively should I report this on the Dancer github and then try and fix it?