[Dancer-users] Debugging with Dancer

Peter Gordon peter at pg-consultants.com
Tue Aug 24 11:03:41 CEST 2010


Thanks for the reply. This goes some way to the answer, but I want
the program to run, without having to invoke curl or any external
program. It could be done by setting up the appropriate packet within 
the program, or by just hacking the request.


On Tue, 2010-08-24 at 10:42 +0200, Alexis Sukrieh wrote:
> Le 24/08/2010 10:09, Peter Gordon a écrit :
> > When debugging a web app, I find it much easier if I can run the app
> > like this:
> >
> > perl -d myApp.pl color=red name=apple
> >    
> Here is a way to go:
> 
> package FooApp;
> use Dancer ':syntax';
> 
> our $VERSION = '0.1';
> 
> before sub {
>      my $args = {};
>      for my $arg (@ARGV) {
>          my ($key, $val) = split(/=/, $arg);
>          $args->{$key} = $val;
>      }
>      request->_set_route_params($args);
>      return 1;
> };
> 
> get '/' => sub {
>      my $params = request->params;
>      to_yaml($params);
> };
> 
> true;
> 
> 
> $ perl -d ./FooApp.pl color=red name=apple
> 
> Loading DB routines from perl5db.pl version 1.32
> Editor support available.
> 
> Enter h or `h h' for help, or `man perldebug' for more help.
> 
> main::(./FooApp.pl:4):    load_app 'FooApp';
>    DB<1> n
> main::(./FooApp.pl:5):    dance;
>    DB<1>
>  >> Dancer server 13461 listening on http://0.0.0.0:3000
> == Entering the development dance floor ...
> 
> $ curl http://0:3000/
> ---
> color: red
> name: apple
> 
> 
> This is indeed a good idea and I think this hack would deserve a plugin, 
> like Dancer::Debug::ParamsFromArgv or something alike.
> 
> Happy dancing.
> 




More information about the Dancer-users mailing list