Le mardi 11 décembre 2012 à 21:16, David Golden a écrit :
Hm you're right, I had not realized it'd be for *every* route. Indeed weneed more benchmark here :) But I like the attribute style. If it can helpin decision making, catalyst makes use of them as well, and it's ratherelegant.Attribute style might be visually nice, but the implementation ofattributes in Perl is really ugly hackery and many people (myselfincluded) who have gotten into the weeds have concluded that it's justnot worth the trouble.Personally, I would find the style below just as appealing if not morebecause 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 attributeparameters are strings that have to be parsed -- typically split onwhitespace. You *could* parse looking for "@\w+" and then eval() it,but (a) that's gross and (b) you've got timing issues because theattribute is processed at compile time and the array isn't populateduntil runtime.And consider if you want to put your role names in a config fileinstead of the source code. How do you do that with attributes?
Have I convinced the doubters by now? :-)