[Catalyst] Proposed patch for Catalyst::Plugin::Authorization::Roles

Yuval Kogman nothingmuch at woobling.org
Thu Jun 15 23:52:46 CEST 2006


On Thu, May 11, 2006 at 12:31:47 +0200, Michele Beltrame wrote:
> Hello!
> 
> I'm attaching a patch for Catalyst::Plugin::Authorization::Roles.

Hi,

I missed this, sorry. If i seem to be ignoring patches please slap
me - I get a lot of mail and sometimes things to mailing lists get
lost....


The code looks good, except for the self check thing- since it's an
optimisation the user class should provide a ->check_roles_any
method, otherwise nothing is gained.

For now the entire if/else can be removed, until
Auth::Store::DBIC implements the internals to optimise it.

If you have tests you may commit this yourself- coordinate with us
on #catalyst or #catalyst-dev and we'll give you SVN access.

Thanks a lot for your work!

> +        my $have = Set::Object->new( $user->roles() );
> +        my $role_ok = 0;
> +        for my $role (@_) {
> +            my $need = Set::Object->new(@_);
> +            $role_ok = 1, last if $have->superset($need);
> +        }

This part can be simplified, simply construct a set from the @_
(please give it a name, btw, it makes reading the code easier), then
you can do:

	if ( $have->intersection( $wanted )->size > 0 ) {
		# ok	
	}

thus removing the need for the loop.

-- 
  Yuval Kogman <nothingmuch at woobling.org>
http://nothingmuch.woobling.org  0xEBD27418

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060616/d2c2590d/attachment.pgp 


More information about the Catalyst mailing list