[Catalyst-commits] r11423 - in trunk/Catalyst-Plugin-Authorization-ACL: . lib/Catalyst/Plugin/Authorization lib/Catalyst/Plugin/Authorization/ACL t

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Sat Sep 26 03:03:32 GMT 2009


Author: caelum
Date: 2009-09-26 03:03:31 +0000 (Sat, 26 Sep 2009)
New Revision: 11423

Removed:
   trunk/Catalyst-Plugin-Authorization-ACL/t/03podcoverage.t
Modified:
   trunk/Catalyst-Plugin-Authorization-ACL/Makefile.PL
   trunk/Catalyst-Plugin-Authorization-ACL/lib/Catalyst/Plugin/Authorization/ACL.pm
   trunk/Catalyst-Plugin-Authorization-ACL/lib/Catalyst/Plugin/Authorization/ACL/Engine.pm
   trunk/Catalyst-Plugin-Authorization-ACL/t/live_app.t
Log:
remove use of $dispatcher->tree

Modified: trunk/Catalyst-Plugin-Authorization-ACL/Makefile.PL
===================================================================
--- trunk/Catalyst-Plugin-Authorization-ACL/Makefile.PL	2009-09-25 12:03:50 UTC (rev 11422)
+++ trunk/Catalyst-Plugin-Authorization-ACL/Makefile.PL	2009-09-26 03:03:31 UTC (rev 11423)
@@ -10,17 +10,21 @@
 all_from 'lib/Catalyst/Plugin/Authorization/ACL.pm';
 
 test_requires 'Test::More';
-test_requires 'Catalyst::Plugin::Authentication';
-test_requires 'Catalyst::Plugin::Authorization::Roles';
 test_requires 'Catalyst::Plugin::Session';
 test_requires 'Catalyst::Plugin::Session::State::Cookie';
+test_requires 'Test::WWW::Mechanize::Catalyst';
 
-requires 'Catalyst::Runtime' => '5.7000';
+requires 'Catalyst::Runtime' => '5.80013';
+requires 'Catalyst::Plugin::Authentication';
+requires 'Catalyst::Plugin::Authorization::Roles';
+requires 'Moose';
+requires 'MRO::Compat';
+requires 'namespace::autoclean';
 requires 'Class::Data::Inheritable';
 requires 'Class::Throwable';
+requires 'Tree::Simple';
 requires 'Tree::Simple::Visitor::FindByPath';
 requires 'Tree::Simple::Visitor::GetAllDescendents';
-requires 'MRO::Compat';
 
 resources repository => 'http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Plugin-Authorization-ACL/';
 

Modified: trunk/Catalyst-Plugin-Authorization-ACL/lib/Catalyst/Plugin/Authorization/ACL/Engine.pm
===================================================================
--- trunk/Catalyst-Plugin-Authorization-ACL/lib/Catalyst/Plugin/Authorization/ACL/Engine.pm	2009-09-25 12:03:50 UTC (rev 11422)
+++ trunk/Catalyst-Plugin-Authorization-ACL/lib/Catalyst/Plugin/Authorization/ACL/Engine.pm	2009-09-26 03:03:31 UTC (rev 11423)
@@ -1,32 +1,71 @@
 package Catalyst::Plugin::Authorization::ACL::Engine;
-use base qw/Class::Accessor::Fast Exporter/;
 
-use strict;
-use warnings;
+use namespace::autoclean;
+use Moose;
+extends qw/Moose::Object Exporter/;
 
 # I heart stevan
 use Class::Throwable;
+use Tree::Simple;
 use Tree::Simple::Visitor::FindByPath;
 use Tree::Simple::Visitor::GetAllDescendents;
 use Carp qw/croak/;
+use List::Util 'first';
 
-BEGIN { __PACKAGE__->mk_accessors(qw/app actions/) }
+has app     => (is => 'rw');
+has actions => (is => 'ro', isa => 'HashRef', default => sub { {} });
+has _app_actions_tree => (is => 'ro', isa => 'Tree::Simple', lazy_build => 1);
 
 our $DENIED  = bless {}, __PACKAGE__ . "::Denied";
 our $ALLOWED = bless {}, __PACKAGE__ . "::Allowed";
 
 our @EXPORT_OK = qw/$DENIED $ALLOWED/;
 
-sub new {
-    my ( $class, $c ) = @_;
+sub BUILDARGS {
+    my ($self, $c) = @_;
+    return +{ app => $c };
+}
 
-    my $self = bless {
-        actions  => {},
-        app      => $c,
-        cxt_info => {},
-    }, $class;
+sub _build__app_actions_tree {
+    my $self = shift;
+    my $root = Tree::Simple->new('/', Tree::Simple->ROOT);
+    my $app  = $self->app;
 
-    $self;
+    my @actions = map {
+        my $controller = $_;
+        map $controller->action_for($_->name), $controller->get_action_methods
+    } grep $_->isa('Catalyst::Controller'), values %{ $app->components };
+
+    for my $action (@actions) {
+        my @path = split '/', $action->reverse;
+        my $name = pop @path;
+
+        if (@path) {
+            my $by_path = Tree::Simple::Visitor::FindByPath->new;
+            $by_path->setSearchPath(@path);
+            $root->accept($by_path);
+
+            if (my $namespace_node = $by_path->getResult) {
+                $namespace_node->addChild(Tree::Simple->new($action));
+                next;
+            }
+        }
+
+        my $node = $root;
+        for my $el (@path) {
+            if (my $found = first { $_->getNodeValue eq $el }
+                @{ $node->getAllChildren }) {
+                $node = $found;
+            }
+            else {
+                $node = Tree::Simple->new($el, $node);
+            }
+        }
+
+        $node->addChild(Tree::Simple->new($action));
+    }
+
+    return $root;
 }
 
 sub add_deny {
@@ -118,7 +157,7 @@
     }
     else {
         my @path = grep { $_ ne "" } split( "/", $path );
-        my $tree = $d->tree;
+        my $tree = $self->_app_actions_tree;
 
         my $subtree = @path
           ? do {
@@ -143,21 +182,21 @@
             "Adding ACL rule from $cxt to all the actions under $path")
           if $self->app->debug;
 
-        foreach my $node ( $subtree, $descendents->getResults ) {
-            my ( $container, $depth ) =
-              ( $node->getNodeValue, $node->getDepth );
+        foreach my $action_node ( $descendents->getResults ) {
+            next unless $action_node->isLeaf;
 
-            foreach my $action ( grep { $filter->($_) }
-                values %{ $container->actions } )
-            {
-                my $sort_index =
-                  1 + ( $depth - $root_depth )
-                  ;    # how far an action is from the origin of the ACL
-                $self->app->log->debug("... $action at sort index $sort_index")
-                  if $self->app->debug;
-                $self->append_rule_to_action( $action, $sort_index, $rule, $cxt,
-                );
-            }
+            my ( $action, $depth ) =
+              ( $action_node->getNodeValue, $action_node->getDepth );
+
+            next unless $filter->($action);
+
+            my $sort_index =
+              1 + ( $depth - $root_depth )
+              ;    # how far an action is from the origin of the ACL
+            $self->app->log->debug("... $action at sort index $sort_index")
+              if $self->app->debug;
+            $self->append_rule_to_action( $action, $sort_index, $rule, $cxt,
+            );
         }
     }
 }

Modified: trunk/Catalyst-Plugin-Authorization-ACL/lib/Catalyst/Plugin/Authorization/ACL.pm
===================================================================
--- trunk/Catalyst-Plugin-Authorization-ACL/lib/Catalyst/Plugin/Authorization/ACL.pm	2009-09-25 12:03:50 UTC (rev 11422)
+++ trunk/Catalyst-Plugin-Authorization-ACL/lib/Catalyst/Plugin/Authorization/ACL.pm	2009-09-26 03:03:31 UTC (rev 11423)
@@ -14,7 +14,7 @@
 
 BEGIN { __PACKAGE__->mk_classdata("_acl_engine") }
 
-our $VERSION = '0.12';
+our $VERSION = '0.13';
 
 my $FORCE_ALLOW = bless {}, __PACKAGE__ . "::Exception";
 
@@ -459,12 +459,16 @@
 L<Catalyst::Plugin::Authentication>, L<Catalyst::Plugin::Authorization::Roles>,
 L<http://catalyst.perl.org/calendar/2005/24>
 
-=head1 AUTHORS
+=head1 AUTHOR
 
 Yuval Kogman E<lt>nothingmuch at woobling.orgE<gt>
 
-Jess Robinson
+=head1 CONTRIBUTORS
 
+castaway: Jess Robinson
+
+caelum: Rafael Kitover E<lt>rkitover at cpan.orgE<gt>
+
 =head1 COPYRIGHT & LICENSE
 
 Copyright (c) 2008 the aforementioned authors.

Deleted: trunk/Catalyst-Plugin-Authorization-ACL/t/03podcoverage.t
===================================================================
--- trunk/Catalyst-Plugin-Authorization-ACL/t/03podcoverage.t	2009-09-25 12:03:50 UTC (rev 11422)
+++ trunk/Catalyst-Plugin-Authorization-ACL/t/03podcoverage.t	2009-09-26 03:03:31 UTC (rev 11423)
@@ -1,7 +0,0 @@
-use Test::More;
-
-eval "use Test::Pod::Coverage 1.04";
-plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
-plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
-
-all_pod_coverage_ok();

Modified: trunk/Catalyst-Plugin-Authorization-ACL/t/live_app.t
===================================================================
--- trunk/Catalyst-Plugin-Authorization-ACL/t/live_app.t	2009-09-25 12:03:50 UTC (rev 11422)
+++ trunk/Catalyst-Plugin-Authorization-ACL/t/live_app.t	2009-09-26 03:03:31 UTC (rev 11423)
@@ -17,7 +17,7 @@
     } or plan 'skip_all' => "A bunch of plugins are required for this test... Look in the source if you really care... $@";
     plan tests => 97;
 }
-	
+
 use Test::WWW::Mechanize::Catalyst 'ACLTestApp';
 
 my $m = Test::WWW::Mechanize::Catalyst->new;




More information about the Catalyst-commits mailing list