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

Takeshi OKURA okura3 at gmail.com
Sat Apr 16 11:57:53 CEST 2011


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};
};

Regards.
-- 
Takeshi OKURA


More information about the Dancer-users mailing list