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

Joel Roth joelz at pobox.com
Sat Apr 16 15:56:54 CEST 2011


On Sat, Apr 16, 2011 at 06:57:53PM +0900, Takeshi OKURA wrote:
> 2011/4/15 Joel Roth <joelz at pobox.com>:
> 
> > before sub {
> >     if (!session('user') && request->path_info !~ m{^/login}) {
> >         # Pass the original path requested along to the handler:
> >         var requested_path => request->path_info;
> >         request->path_info('/login');
> >     }
> > };
> 
> I think above example is assumed as follows.
> 
> get '/login' => sub {
>   my $requested_path = vars->{requested_path};
>   return <<__EOM__;
> <form action="/login" method="POST">
> <p>
> <input type="hidden" name="requested_path" value="$requested_path">
> Login: <input type="text" name="user" value=""> <br>
> <input type="submit" name="action" value="Login">
> </p>
> </form>
> __EOM__
> };
 
> post '/login' => sub {
>   session user => params->{user};
>   return redirect params->{requested_path};
> };

Thanks, I'll try that.
 
> Regards.
> -- 
> Takeshi OKURA

-- 
Joel Roth


More information about the Dancer-users mailing list