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

David Golden xdg at xdg.me
Sat Dec 15 19:35:18 GMT 2012


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

I think that might work as-is. (But you should test it, of course.)

David

-- 
David Golden <xdg at xdg.me>
Take back your inbox! → http://www.bunchmail.com/
Twitter/IRC: @xdg


More information about the dancer-users mailing list