ACL-Lite
view release on metacpan or search on metacpan
0.0004 Sat Dec 14 10:49:04 2013 CET
[BUG FIXES]
* Prevent Perl warning on undefined permissions parameter.
0.0003 Wed Dec 4 13:13:00 2013 CET
[API CHANGES]
* Add default permissions ("authenticated" or "anonymous") depending
whether you pass uid or not.
0.0002 Wed May 22 15:57:12 2013 CEST
[BUG FIXES]
* Execute POD tests only during release testing.
[ENHANCEMENTS]
{
"abstract" : "Liteweight and flexible ACL checks",
"author" : [
"Stefan Hornburg (Racke) <racke@linuxia.de>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.120921",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
---
abstract: 'Liteweight and flexible ACL checks'
author:
- 'Stefan Hornburg (Racke) <racke@linuxia.de>'
build_requires:
ExtUtils::MakeMaker: 0
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.120921'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
if ($ret = $acl->check([qw/baz bar/])) {
print "Check successful with permission $ret\n";
}
unless ($acl->check('baz')) {
print "Permission denied\n";
}
$acl = ACL::Lite->new(uid => 666);
$acl->check('authenticated');
DESCRIPTION
`ACL::Lite' is a simple permission checker without any prerequisites.
`ACL' stands for "Access Control Lists".
DEFAULT PERMISSION
The default permission depends on whether you pass a `uid'
(authenticated) or not (anonymous).
CONSTRUCTOR
new
Creates an ACL::Lite object by passing the following parameters:
uid User identifier for authenticated users.
permissions
Granted permissions.
separator
Separator used to parse permission strings. Defaults to `,'.
check $permissions, $uid
Checks whether any of the permissions in $permissions is granted.
Returns first permission which grants access.
lib/ACL/Lite.pm view on Meta::CPAN
if ($ret = $acl->check([qw/baz bar/])) {
print "Check successful with permission $ret\n";
}
unless ($acl->check('baz')) {
print "Permission denied\n";
}
$acl = ACL::Lite->new(uid => 666);
$acl->check('authenticated');
=head1 DESCRIPTION
C<ACL::Lite> is a simple permission checker without any prerequisites.
C<ACL> stands for "Access Control Lists".
=head2 DEFAULT PERMISSION
The default permission depends on whether you pass a C<uid> (authenticated)
or not (anonymous).
=head1 CONSTRUCTOR
=head2 new
Creates an ACL::Lite object by passing the following parameters:
=over 4
=item uid
User identifier for authenticated users.
=item permissions
Granted permissions.
=item separator
Separator used to parse permission strings. Defaults to C<,>.
=back
lib/ACL/Lite.pm view on Meta::CPAN
$perm =~ s/\s+$//;
next unless length($perm);
$self->{permissions}->{$perm} = 1;
}
}
}
# add default permissions
if ($self->{uid}) {
$self->{permissions}->{authenticated} = 1;
}
else {
$self->{permissions}->{anonymous} = 1;
}
return $self;
}
=head2 check $permissions, $uid
t/01-simple.t view on Meta::CPAN
isa_ok($acl, 'ACL::Lite');
ok($acl->check('foo') eq 'foo');
ok($acl->check('bar') eq 'bar');
ok($acl->check(['foo', 'bar']) eq 'foo');
ok(! defined($acl->check('baz')));
test_return_of_permissions($acl);
# anonymous and authenticated permissions
$acl = ACL::Lite->new(permissions => '', uid => undef);
isa_ok($acl, 'ACL::Lite');
$ret = $acl->check('anonymous');
ok(defined $ret && $ret eq 'anonymous', 'Check for anonymous permission of anonymous user.')
|| diag "Return value: $ret:";
$ret = $acl->check('authenticated');
ok(! defined($ret), 'Check for authenticated permission of anonymous user.')
|| diag "Return value: $ret.";
$acl = ACL::Lite->new(permissions => '', uid => 666);
isa_ok($acl, 'ACL::Lite');
$ret = $acl->check('authenticated');
ok(defined $ret && $ret eq 'authenticated', 'Check for authenticated permission of authenticated user.')
|| diag "Return value: $ret:";
$ret = $acl->check('anonymous');
ok(! defined($ret), 'Check for anonymous permission of authenticated user.')
|| diag "Return value: $ret.";
sub test_return_of_permissions {
my $acl = shift;
@parr = $acl->permissions;
is_deeply([sort @parr], ['anonymous', 'bar', 'foo'], "Test return value of permissions method (array).");
$pref = $acl->permissions;
( run in 2.205 seconds using v1.01-cache-2.11-cpan-5c0b1e786e0 )