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 where the parameters are given on the command line, or within a file. Can someone suggest the best/easiest way to do this with Dancer. Thanks, Peter
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. -- Alexis Sukrieh
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.
Le 24/08/2010 11:03, Peter Gordon a écrit :
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.
Hmm, This would be a bit more complicated, because you'll have to fake an incoming HTTP connection... I don't see how to do that if not by using a new Dancer::Handler for this specific purpose. -- Alexis Sukrieh
I just ran into a similar situation. I dealt with a small xml for testing purposes and now took a big real-life xml document. Anyways, if I have to load that xml only when the first request comes it takes a while. If there would be a way to load it during starting the app, i could save that time. What do you think? thanks Maurice On Tue, Aug 24, 2010 at 5:07 AM, Alexis Sukrieh <sukria@sukria.net> wrote:
Le 24/08/2010 11:03, Peter Gordon a écrit :
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.
Hmm,
This would be a bit more complicated, because you'll have to fake an incoming HTTP connection...
I don't see how to do that if not by using a new Dancer::Handler for this specific purpose.
-- Alexis Sukrieh
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
participants (3)
-
Alexis Sukrieh -
Maurice Mengel -
Peter Gordon