Hi,<br><br>The only drawback is performance : there is an additional indirection, and code dereferencing might be costly. The optimization of the route caching stops wher your route code starts, so it won't be optimized. You don't get performance hits ( or less, at least I think) with attributes.<br>
<br>Hm, it could be solved by calling got &$code actually. But be careful about argument passing.<br><div class="gmail_extra"><br><br><div class="gmail_quote">On 11 December 2012 13:39, David Precious <span dir="ltr"><<a href="mailto:davidp@preshweb.co.uk" target="_blank">davidp@preshweb.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Tue, 11 Dec 2012 11:40:29 +0000<br>
Daniel Perrett <<a href="mailto:dperrett@cambridge.org">dperrett@cambridge.org</a>> wrote:<br>
<br>
> Perhaps I'm missing something but...<br>
><br>
> "how requires_login/requires_role would store the fact that the<br>
> provided sub requires auth"<br>
><br>
> Simple implementation:<br>
><br>
> # given has_role is calculable<br>
><br>
> sub requires_role {<br>
> my ($role, $code, $handle_exception) = @_;<br>
> return sub {<br>
> if (has_role($role)){<br>
> $code->(@_);<br>
> }<br>
> else{<br>
> if (defined $handle_exception){<br>
> $handle_exception->($role, @_)<br>
> }<br>
> else {<br>
> default_403_no_role($role, @_)<br>
> }<br>
> }<br>
> }<br>
> }<br>
<br>
</div>Ah, yes - that's pretty clever. I think like that approach - it's<br>
simple and solid.<br>
<br>
Thanks!<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
--<br>
David Precious ("bigpresh") <<a href="mailto:davidp@preshweb.co.uk">davidp@preshweb.co.uk</a>><br>
<a href="http://www.preshweb.co.uk/" target="_blank">http://www.preshweb.co.uk/</a> <a href="http://www.preshweb.co.uk/twitter" target="_blank">www.preshweb.co.uk/twitter</a><br>
<a href="http://www.preshweb.co.uk/linkedin" target="_blank">www.preshweb.co.uk/linkedin</a> <a href="http://www.preshweb.co.uk/facebook" target="_blank">www.preshweb.co.uk/facebook</a><br>
<a href="http://www.preshweb.co.uk/cpan" target="_blank">www.preshweb.co.uk/cpan</a> <a href="http://www.preshweb.co.uk/github" target="_blank">www.preshweb.co.uk/github</a><br>
<br>
<br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</div></div></blockquote></div><br></div>