running a route from another route within Dancer
Is something like the following possible (see the line marked />+/)? Or, even advisable? get '/foo.:format' => sub { my $a = param 'a'; my $b = param 'b'; my $res = query_db($a, $b); return to_json $res; } get '/bar.:format' => sub { my $a = param 'a'; my $b = param 'b'; >>>>>> my $res_foo = <somehow call /foo.json?a=$a&b=$b>; my $res = do_something($res_foo); return to_json $res; } -- Puneet Kishor
On 10/25/2011 03:40 PM, Puneet Kishor wrote:
Is something like the following possible (see the line marked />+/)? Or, even advisable?
get '/foo.:format' => sub { my $a = param 'a'; my $b = param 'b';
my $res = query_db($a, $b); return to_json $res; }
get '/bar.:format' => sub { my $a = param 'a'; my $b = param 'b';
> my $res_foo =<somehow call /foo.json?a=$a&b=$b>; my $res = do_something($res_foo); return to_json $res; }
I suggest to make a function like that: sub abjson { my ($a, $b) = @_; my $res = query_db($a, $b); return to_json $res; } You can call this function from both routes. Regards Racke -- LinuXia Systems => http://www.linuxia.de/ Expert Interchange Consulting and System Administration ICDEVGROUP => http://www.icdevgroup.org/ Interchange Development Team
Dude... this is what functions are for. You're stretching Dancer in incorrect ways, which gives you grief. You should be opting for simple elegant coding solutions, and that's something you can easily do using refactored subroutines. get '/json/....' => sub { my_json_parsing_function(@_) }; get '/bar/:format' => sub { ...... my $result = my_json_parsing_function("stuff"); [# do something with result...] }; Seriously... :) On Tue, Oct 25, 2011 at 3:40 PM, Puneet Kishor <punk.kish@gmail.com> wrote:
Is something like the following possible (see the line marked />+/)? Or, even advisable?
get '/foo.:format' => sub { my $a = param 'a'; my $b = param 'b';
my $res = query_db($a, $b); return to_json $res; }
get '/bar.:format' => sub { my $a = param 'a'; my $b = param 'b';
>>>>>> my $res_foo = <somehow call /foo.json?a=$a&b=$b>; my $res = do_something($res_foo); return to_json $res; }
-- Puneet Kishor _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
On Oct 25, 2011, at 8:52 AM, sawyer x wrote:
Dude... this is what functions are for.
You're stretching Dancer in incorrect ways, which gives you grief.
Not to worry... I hadn't yet stretched Dancer in incorrect ways, but did flirt with the idea of doing so, so asked before venturing forward. Fwiw, I have already have had the program implemented as you suggested below, but for my own edification, and for future architectural purposes, I was contemplating doing a tango move on a ballroom dancer.
You should be opting for simple elegant coding solutions, and that's something you can easily do using refactored subroutines.
get '/json/....' => sub { my_json_parsing_function(@_) }; get '/bar/:format' => sub { ...... my $result = my_json_parsing_function("stuff"); [# do something with result...] };
Seriously... :)
On Tue, Oct 25, 2011 at 3:40 PM, Puneet Kishor <punk.kish@gmail.com> wrote:
Is something like the following possible (see the line marked />+/)? Or, even advisable?
get '/foo.:format' => sub { my $a = param 'a'; my $b = param 'b';
my $res = query_db($a, $b); return to_json $res; }
get '/bar.:format' => sub { my $a = param 'a'; my $b = param 'b';
>> my $res_foo = <somehow call /foo.json?a=$a&b=$b>; my $res = do_something($res_foo); return to_json $res; }
-- Puneet Kishor _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
On Tue, Oct 25, 2011 at 4:01 PM, Puneet Kishor <punk.kish@gmail.com> wrote:
Not to worry... I hadn't yet stretched Dancer in incorrect ways, but did flirt with the idea of doing so, so asked before venturing forward.
If you say so...
Fwiw, I have already have had the program implemented as you suggested below, but for my own edification, and for future architectural purposes, I was contemplating doing a tango move on a ballroom dancer.
I have no idea what that means. It sounds kinky, it sounds like fun, but I should warn you that trying to dance on your ears will undoubtedly have you falling on the floor, aching. Legs are meant for dancing, not ears. :)
participants (3)
-
Puneet Kishor -
sawyer x -
Stefan Hornburg (Racke)