Changeset 8953 for lang/perl/Data-LazyACL
- Timestamp:
- 04/06/08 09:02:15 (5 years ago)
- Location:
- lang/perl/Data-LazyACL/trunk
- Files:
-
- 2 modified
-
README (modified) (1 diff)
-
lib/Data/LazyACL.pm (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Data-LazyACL/trunk/README
r2243 r8953 6 6 or 7 7 8 perl -MCPAN -e 'install Data::LazyACL'8 perl -MCPAN -e'install Data::LazyACL' 9 9 10 -
lang/perl/Data-LazyACL/trunk/lib/Data/LazyACL.pm
r2243 r8953 29 29 30 30 my $digit = 1; 31 for my $access_key ( @{ $access_keys } ) {32 31 for my $access_key ( @{ $access_keys } ) { 32 33 33 if( $access_key eq 'admin' ) { 34 34 croak q{You can not use reserved word 'admin' as access key.}; 35 35 } 36 37 $s->{access_key}{ $access_key } = $digit; 36 37 $s->{access_key}{ $access_key } = $digit; 38 38 $digit++; 39 39 } … … 42 42 43 43 sub has_privilege { 44 my $s = shift;45 my $access_key = shift;44 my $s = shift; 45 my $access_key = shift; 46 46 47 47 return 0 unless defined $s->{token}; … … 53 53 54 54 my $access_digit = $s->{access_key}{ $access_key } ; 55 55 56 56 croak 'can not find access key [' . $access_key . ']' unless $access_digit; 57 57 my $acl = Math::BigInt->new( 2 ); … … 69 69 my $s = shift; 70 70 my $access_keys = shift; 71 71 72 72 my $acl = Math::BigInt->new(); 73 73 … … 76 76 77 77 my $digit = $s->{access_key}{ $access_key } ; 78 78 79 79 croak 'can not find access key [' . $access_key . ']' unless $digit; 80 80 … … 99 99 my $digit = $s->{access_key}{ $key }; 100 100 101 $mb->bpow( $digit - 1 ); 102 101 $mb->bpow( $digit - 1 ); 102 103 103 if( $mb->band( $token ) ) { 104 104 push @access_keys , $key ; 105 105 } 106 107 106 } 108 107 … … 122 121 my $digit = $s->{access_key}{ $key }; 123 122 124 $mb->bpow( $digit - 1 ); 125 123 $mb->bpow( $digit - 1 ); 124 126 125 if( $mb->band( $token ) ) { 127 126 $access_keys->{ $key } = 1; 128 127 } 129 130 128 } 131 129 return $access_keys; … … 140 138 141 139 I am tired of having multiple flags or columns or whatever to implement Access 142 Control List , so I create this module.143 144 This module is simple and easy to use, a user only need to have a token140 Control List, so I create this module. 141 142 This module is simple and easy to use, a user only need to have a token 145 143 to check having access or not. 146 144 147 =head1 SYNOPS YS145 =head1 SYNOPSIS 148 146 149 147 my $acl = Data::LazyACL->new(); … … 164 162 print "Never Dispaly\n"; 165 163 } 166 167 my $access_keys_ref 164 165 my $access_keys_ref 168 166 = $acl->retrieve_access_keys_for( $token ); 169 167 170 168 my $access_keys_hash_ref 171 169 = $acl->retrieve_access_keys_in_hash_for( $token ); … … 180 178 181 179 Set all access keys. You can never change this array of order once you 182 generate token , otherwise you will messup permissins. When you want to add new keys then just append.180 generate token, otherwise you will messup permissins. When you want to add new keys then just append. 183 181 184 182 =head2 $token = generate_token( \@user_access_keys ) … … 188 186 =head2 \@access_keys = get_all_access_keys() 189 187 190 Get access keys which you set with set_all_access_keys() .. means not include188 Get access keys which you set with set_all_access_keys()... means not include 191 189 'admin'. 192 190 … … 196 194 method check privilege based on this token. 197 195 198 If you want to have all access then use reserve keyword 'admin'.196 If you want to have all access then use reserve keyword "admin". 199 197 200 198 my $admin_token = $acl->set_token( 'admin' ); … … 221 219 Tomohiro Teranishi <tomohiro.teranishi+cpan@gmail.com> 222 220 223 =head1 COPYRIGHT221 =head1 LICENSE 224 222 225 223 This program is free software. you can redistribute it and/or modify it under
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)