Hi, I'm found in documentation 'pass' function which make procesing of next request. But i want in some my code to put other request but request not from next matching route. Something like that: get '/index' => sub { ....... }; get '/some/route' => sub { if (...) { # How can I put this code to '/index' route not use redirect. } } Thank for yours answer and sorry for my english :( I must learn
igor.bujna@post.cz writes:
I'm found in documentation 'pass' function which make procesing of next request. But i want in some my code to put other request but request not from next matching route. Something like that:
get '/index' => sub { ....... };
get '/some/route' => sub { if (...) { # How can I put this code to '/index' route not use redirect. } }
Thank for yours answer and sorry for my english :( I must learn
Please, don't apologise. Your English is quite reasonable. The easy way is this: sub _index { # whatever } get '/index' => \&_index; get '/some/route' => sub { if (...) { goto \&_index; # or return _index() } } You can use a regular subroutine reference as the route handler, or call it from there, just like in regular Perl code. Regards, Daniel -- ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707 ♽ made with 100 percent post-consumer electrons
------------ Původní zpráva ------------ Od: Daniel Pittman <daniel@rimspace.net> Předmět: Re: [Dancer-users] Pass to own request Datum: 04.10.2010 00:47:34 ---------------------------------------- igor.bujna@post.cz writes:
I'm found in documentation 'pass' function which make procesing of next request. But i want in some my code to put other request but request not from next matching route. Something like that:
get '/index' => sub { ....... };
get '/some/route' => sub { if (...) { # How can I put this code to '/index' route not use redirect. } }
Thank for yours answer and sorry for my english :( I must learn
Please, don't apologise. Your English is quite reasonable.
The easy way is this:
sub _index { # whatever } get '/index' => \&_index; get '/some/route' => sub { if (...) { goto \&_index; # or return _index() } }
You can use a regular subroutine reference as the route handler, or call it from there, just like in regular Perl code.
Now I have similar code as you write. I think, better idea will be if 'pass()' has 2 options. 1) such as now. call pass() process next route. 2) put to 'pass' route method, which I want to next process, such as "pass('/index')" I found some methods which make what I want, but I think that idea of 'pass' method which has 2 options its better. sub pass_own { my $name = shift || return; foreach my $app ( Dancer::App->applications ) { my $routes = $app->{registry}->{routes}; # push the static get routes into an array. foreach my $k ( @{ $routes->{get} } ) { if (ref($k->{pattern}) !~ m/HASH/i && ($k->{pattern} eq $name)) { return $k->{code}(); } } } } Cheers Igor
Regards, Daniel -- ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707 ♽ made with 100 percent post-consumer electrons _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
participants (2)
-
Daniel Pittman -
igor.bujna@post.cz