<div dir="ltr">Hello fellow Dancer users,<div><br></div><div>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:</div>
<div><br></div><div><div>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.</div><div><br></div><div>Example:</div>
<div><br></div><div><div>$ cat bin/<a href="http://app.pl">app.pl</a> </div><div>#!/usr/bin/env perl</div><div>use Dancer;</div><div>use Demo;</div><div>dance;</div><div>__END__</div></div><div><br></div><div><br></div><div>
<div>$ cat lib/Demo.pm </div><div><div>package Demo;</div><div><br></div><div>use Dancer qw( :syntax !load );</div><div>use Module::Load;</div><div><br></div><div>any '/Monitoring/*?' => sub {</div><div> my $module = "Monitoring";</div>
<div><br></div><div> load $module;</div><div><br></div><div> pass();</div><div>};</div><div><br></div><div>true;</div><div>__END__</div></div></div><div><br></div><div><br></div><div><div>$ cat lib/Monitoring.pm </div>
<div>package Monitoring;</div><div><br></div><div>use Dancer ':syntax';</div><div><br></div><div>prefix '/Monitoring';</div><div><br></div><div>get '/' => sub {</div><div> return 'Monitoring Service';</div>
<div>};</div><div><br></div><div>get '/ping' => sub {</div><div> return time;</div><div>};</div><div><br></div><div>true;</div><div>__END__</div></div><div><br></div><div><br></div><div>Calling <a href="http://domain.com/Monitoring/ping">domain.com/Monitoring/ping</a> results in a timestamp as you would expect</div>
<div>Calling <a href="http://domain.com/Monitoring/">domain.com/Monitoring/</a> returns the string "Monitoring Service".</div><div>Calling <a href="http://domain.com/Monitoring/foo">domain.com/Monitoring/foo</a> results in a Runtime Error where I would have expected to receive a 404 error<br>
</div><div><br></div><div>Runtime Error</div><div><br></div><div>runtime error</div><div><br></div><div>Can't call method "run" on an undefined value at /usr/share/perl5/Dancer/Route.pm line 212.</div><div>/usr/share/perl5/Dancer/Route.pm around line 212</div>
<div>209 $response->pass(0);</div><div>210 if ($self->next) {</div><div>211 my $next_route = $self->find_next_matching_route($request);</div><div>212 return $next_route->run($request);</div>
<div>213 }</div><div>214 else {</div><div>215 Dancer::Logger::core('Last matching route passed!');</div><div>Stack</div><div>main in -e l. 0</div><div>main in -e l. 0</div><div>Plack::Handler::Apache2 in /usr/share/perl5/Plack/Handler/Apache2.pm l. 91</div>
<div>Plack::Handler::Apache2 in /usr/share/perl5/Plack/Handler/Apache2.pm l. 66</div><div>Dancer::Handler in /usr/share/perl5/Dancer/Handler.pm l. 123</div><div>Dancer::Handler in /usr/share/perl5/Dancer/Handler.pm l. 76</div>
<div>Dancer::Handler in /usr/share/perl5/Dancer/Handler.pm l. 113</div><div>Try::Tiny in /usr/share/perl5/Try/Tiny.pm l. 100</div><div>Dancer::Exception in /usr/share/perl5/Dancer/Exception.pm l. 47</div><div>Dancer::Exception in /usr/share/perl5/Dancer/Exception.pm l. 35</div>
<div>Dancer::Handler in /usr/share/perl5/Dancer/Handler.pm l. 107</div><div>Dancer::Object in /usr/share/perl5/Dancer/Object.pm l. 16</div><div>Dancer::Error in /usr/share/perl5/Dancer/Error.pm l. 37</div><div>Dancer::Error in /usr/share/perl5/Dancer/Error.pm l. 276</div>
<div><br></div><div><br></div><div>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.</div>
</div><div><br></div><div>I'm using the version of Dancer which comes with Debian 7.</div><div><br></div><div><div>$ apt-cache show libdancer-perl</div><div>Package: libdancer-perl</div><div>Version: 1.3095+dfsg-1</div>
</div><div><br></div><div>I'm using apache2 with Plack::Handler::Apache2 to run the Dancer application.</div><div><br></div><div>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.</div>
<div><br></div><div>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?</div>
<div><br></div><div>Thanks,</div><div><br></div><div>Jonathan</div></div>