paranoid acl -> no permission checks inside of controllers :)
[blog.pm.git] / lib / Catalyst / Plugin / Authorization / ACL / Paranoid / Engine.pm
blobd3fd4f3a59b6ff0b583e5cdaedfc35b98c0ccc9e
1 package Catalyst::Plugin::Authorization::ACL::Paranoid::Engine;
3 use strict;
4 use warnings;
6 sub new {
7 my ( $class, $c ) = @_;
9 my $self = bless { rules => {} }, $class;
11 return $self;
14 sub rules {
15 my ( $self, $rules ) = @_;
17 $self->{ rules } = {};
19 while ( my ( $action, $check ) = each %$rules ) {
20 $action =~ s/^\///o unless $action eq '/';
22 $self->{ rules }->{ $action } =
23 ref $check eq 'CODE' ? $check : sub { $check }
27 sub is_allowed {
28 my ( $self, $c, $class, $action ) = @_;
30 # skip internal links
31 if (
32 $action
33 && ( $action =~ m/\/?(?:_[A-Z]+|auto|begin|end)$/o
34 || $action =~ m/(?:->process$|^default$)/o )
37 return 1;
40 if ( my $check = $self->{ rules }->{ $action } ) {
41 my $ret = $check->( $c );
43 return $ret;
46 if ( my $check = $self->{ rules }->{ '*' } ) {
47 return $check->( $c );
50 return 0;
53 =head1 AUTHOR
55 vti
57 =head1 COPYRIGHT
59 This program is free software, you can redistribute it and/or modify it under
60 the same terms as Perl itself.
62 =cut