[dancer-users] Dancer::Plugin::Auth::Extensible - removing sub attributes - ready to try out

David Precious davidp at preshweb.co.uk
Sat Dec 15 20:16:21 GMT 2012


On Sat, 15 Dec 2012 14:35:18 -0500
David Golden <xdg at xdg.me> wrote:

> On Sat, Dec 15, 2012 at 2:20 PM, David Precious
> <davidp at preshweb.co.uk> wrote:
> > Yeah, that's true.  I was thinking that require_role could accept an
> > arrayref of roles instead of a straightforward role, if desired, so
> > you could also say e.g.:
> >
> >     get '/foo' => requires_role ['Foo','Bar'] => sub { ... };
> >
> > (requires_roles could be added as an alias, so code could read
> > better.)
> >
> > I imagine the common requirement will be to say "any of these
> > roles", not "all of these roles".  I was considering whether
> > requires_role should be for "must have this role" or "must have all
> > of these roles", and e.g. a new requires_any_role keyword would be
> > added to ensure a user had all the specified roles; I'm not sure
> > how valuable that would be, though.
> 
> OK,  I see.
> 
> In that case, I think you'd be better off keeping the API as it is
> (taking a single "comparator") and letting users use
> Syntax::Keyword::Junction to be clear about their intent.
> 
> All you really need to say is that the first argument to
> 'require_role' must be comparable with the "eq" operator and then give
> an example of using Syntax::Keyword::Junction for any more complex
> logic.
> 
>   use Syntax::Keyword::Junction qw/any all/;
>   get '/foo' => requires_role any(qw/Foo Bar/) => sub { ... };
>   get '/bar' => requires_role all(qw/Foo Bar/) => sub { ... };

Hmm, that would be nice, but any() is already a Dancer keyword; I could
import any() as a different name, I believe, courtesy of Sub::Exporter,
but that involves a fairly big dependency chain.

For the time being, I've added two new keywords to handle matching
multiple roles - requires_any_role and requires_all_roles, which do as
their names would suggest.

I think that's nice and clear, and will capably handle most user's
requirements easily.


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