NAME
Data::LazyACL - Simple and Easy Access Control List
DESCRIPTION
I am tired of having multiple flags or columns or whatever to implement Access Control List , so I create this module.
This module is simple and easy to use, a user only need to have a token to check having access or not.
SYNOPSYS
my $acl = Data::LazyACL->new();
$acl->set_all_access_keys( [qw/edit insert view/]);
my ( $edit , insert , view ) = $s->get_all_access_keys();
# maybe you want to store this token into user record.
my $token = $acl->generate_token([qw/view insert/]);
$acl->set_token( $token );
if ( $acl->has_privilege( 'view' ) ) {
print "You can view me!!\n";
}
if ( $acl->has_privilege( 'edit' ) ) {
print "Never Dispaly\n";
}
my $access_keys_ref
= $acl->retrieve_access_keys_for( $token );
my $access_keys_hash_ref
= $acl->retrieve_access_keys_in_hash_for( $token );
METHODS
new()
Constractor.
set_all_access_keys( \@access_keys )
Set all access keys. You can never change this array of order once you generate token , otherwise you will messup permissins. When you want to add new keys then just append.
$token = generate_token( \@user_access_keys )
Generate token. You may want to save this token for per user.
\@access_keys = get_all_access_keys()
Get access keys which you set with set_all_access_keys() .. means not include 'admin'.
set_token( $token )
You need to set $token to use has_privilege() method. the has_privilege() method check privilege based on this token.
If you want to have all access then use reserve keyword 'admin' .
my $admin_token = $acl->set_token( 'admin' );
has_privilege( $access_key )
check having privilege or not for the access_key.
$keys_ref = retrieve_access_keys_for( $token )
Get access keys array ref for a token.
$keys_hash_ref = retrieve_access_keys_in_hash_for( $token )
Get access keys as hash key. value is 1.
Token can be big number
Token can be big number when you add a lot of access keys, so I suggest you treat Token as String not Integer when you want to store it into database.
AUTHOR
Tomohiro Teranishi <tomohiro.teranishi+cpan@gmail.com>
COPYRIGHT
This program is free software. you can redistribute it and/or modify it under the same terms as Perl itself.