> This sounds like someone has to maintain some code which involves translating
> 01011010101101010101
> into a coherent permission system. I'd rather not have to be that
> person. :)

Nah, that sounds simple enough.  (just don't lose the documentation :)).
Certainly simpler than a true expansion of permissions. (which, granted,
is more powerful).

If you're going the binary route, why not use binary operators and bit
shifting so that instead of "101101" (for example) you store "45"?  You
can find out if a permission is in the number with something like:

$has_permission = $user_permission & $permissions{'Edit'} > 1;
(where $user_permission is the "45" or whatever value, and %permissions is
a hash having the binary "location" of each permission bit.  e.g.
%permissions = (
  Edit => 1,
  Create => 2,
  View => 4,
);

Or, you could rewrite this as:
my %permissions;
{
  my $index = 1;
  #create a list of permission types and binary values
  %permissions = map { $_ => 2 ** $index++}
    #always add new permissions to the end of this list
    qw( Edit Create View );
}

Which does obfuscate your purpose a bit, but reduces the danger of typos
or poor "multiply by 2" skills.




---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to