[dancer-users] Dancer::Plugin::Auth::Extensible - possible backwards-incompatible change

David Precious davidp at preshweb.co.uk
Tue Dec 11 12:39:35 GMT 2012


On Tue, 11 Dec 2012 11:40:29 +0000
Daniel Perrett <dperrett at cambridge.org> wrote:

> Perhaps I'm missing something but...
> 
> "how requires_login/requires_role would store the fact that the
> provided sub requires auth"
> 
> Simple implementation:
> 
> # given has_role is calculable 
> 
> sub requires_role { 
>         my ($role, $code, $handle_exception) = @_;
>         return sub {
>                 if (has_role($role)){
>                         $code->(@_);
>                 }
>                 else{
>                         if (defined $handle_exception){
>                                 $handle_exception->($role, @_)
>                         }
>                         else {
>                                 default_403_no_role($role, @_)
>                         }
>                 }
>         }
> }

Ah, yes - that's pretty clever.  I think like that approach - it's
simple and solid.

Thanks!



-- 
David Precious ("bigpresh") <davidp at preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github




More information about the dancer-users mailing list