[Dancer-users] Pass to own request

Daniel Pittman daniel at rimspace.net
Mon Oct 4 00:47:08 CEST 2010


igor.bujna at 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 at rimspace.net            ☎ +61 401 155 707
               ♽ made with 100 percent post-consumer electrons


More information about the Dancer-users mailing list