[Dancer-users] How do I share variables between route handlers ?

Takeshi OKURA okura3 at gmail.com
Fri Apr 15 11:26:23 CEST 2011


In Dancer.pm there is a forward example.
------------------------------------------------------------------------------------
    get qr{ /demo/articles/(.+) }x => sub {
        my ($article_id) = splat;

        # you'll have to implement this next sub yourself :)
        change_the_main_database_to_demo();

        forward '/articles/$article_id';
    };
------------------------------------------------------------------------------------

I want to the same thing.
In order to that, I set the variable in first route and pass it to
forwarded route.

I thought I could be used to dancer's vars variables.
I tried but it did not work.

Set var in before filter and read it in route handler is work fine.
Set var in route handler and read it in passed route handler is work fine.
Set var in route handler and read it in before_template is work fine.
But
Set var in route handler and read it in forwarded route handler did not work.
Set var in route handler and read it in before filter did not work.

Perl's my and our variables outer a route handler does not used
because other user session read it.

I want to variables which shared in route handlers.
Or I want to the filter which is called only once in every user's access.
Before filter is called every time which used forward method.

Waht better way to share variables in route handlers ?

-- 
Takeshi OKURA


More information about the Dancer-users mailing list