[dancer-users] Dancer::Plugin::Auth::Extensible - possible backwards-incompatible change
David Golden
xdg at xdg.me
Tue Dec 11 20:16:01 GMT 2012
> Hm you're right, I had not realized it'd be for *every* route. Indeed we
> need more benchmark here :) But I like the attribute style. If it can help
> in decision making, catalyst makes use of them as well, and it's rather
> elegant.
Attribute style might be visually nice, but the implementation of
attributes in Perl is really ugly hackery and many people (myself
included) who have gotten into the weeds have concluded that it's just
not worth the trouble.
Personally, I would find the style below just as appealing if not more
because it's guaranteed to follow Perl's grammar:
get '/beer' => requires_role BeerDrinker => sub { ... };
get '/user/:user_id' => requires_role qw/Admin TeamLeader/ => sub { ... };
Plus, I can do this:
my @power_users = qw/Admin TeamLeader/;
get '/user/:user_id' => requires_role @power_users => sub { ... };
You can't as easily do that with attributes because attribute
parameters are strings that have to be parsed -- typically split on
whitespace. You *could* parse looking for "@\w+" and then eval() it,
but (a) that's gross and (b) you've got timing issues because the
attribute is processed at compile time and the array isn't populated
until runtime.
And consider if you want to put your role names in a config file
instead of the source code. How do you do that with attributes?
Have I convinced the doubters by now? :-)
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