Only register private actions when needed
Sebastian Riedel [Thu, 10 Nov 2005 00:34:05 +0000 (00:34 +0000)]
lib/Catalyst/AttrContainer.pm
lib/Catalyst/DispatchType/Path.pm
lib/Catalyst/DispatchType/Regex.pm
lib/Catalyst/Dispatcher.pm

index b330adc..35741e4 100644 (file)
@@ -13,7 +13,6 @@ __PACKAGE__->_action_cache( [] );
 # note - see attributes(3pm)
 sub MODIFY_CODE_ATTRIBUTES {
     my ( $class, $code, @attrs ) = @_;
-    return if ( ( $attrs[0] eq 'lvalue' ) && ( @attrs == 1 ) );
     $class->_attr_cache( { %{ $class->_attr_cache }, $code => [@attrs] } );
     $class->_action_cache(
         [ @{ $class->_action_cache }, [ $code, [@attrs] ] ] );
index cffe66b..ccff553 100644 (file)
@@ -62,7 +62,7 @@ sub register {
     my @register;
 
     foreach my $r ( @{ $attrs->{Path} || [] } ) {
-        unless ( $r ) {
+        unless ($r) {
             $r = $action->namespace;
         }
         elsif ( $r !~ m!^/! ) {    # It's a relative path
@@ -81,7 +81,9 @@ sub register {
         # Register sub name as a relative path
     }
 
-    $self->register_path($c, $_, $action) for @register;
+    $self->register_path( $c, $_, $action ) for @register;
+    return 1 if @register;
+    return 0;
 }
 
 =item $self->register_path($c, $path, $action)
@@ -89,7 +91,7 @@ sub register {
 =cut
 
 sub register_path {
-    my ($self, $c, $path, $action) = @_;
+    my ( $self, $c, $path, $action ) = @_;
     $path =~ s!^/!!;
     $self->{paths}{$path} = $action;
 }
index def40e8..38b2513 100644 (file)
@@ -26,7 +26,7 @@ sub list {
     my ( $self, $c ) = @_;
     my $re = Text::SimpleTable->new( [ 36, 'Regex' ], [ 37, 'Private' ] );
     for my $regex ( @{ $self->{compiled} } ) {
-        my $action   = $regex->{action};
+        my $action = $regex->{action};
         $re->row( $regex->{path}, "/$action" );
     }
     $c->log->debug( "Loaded Regex actions:\n" . $re->draw )
@@ -77,6 +77,8 @@ sub register {
         $self->register_path( $c, $r, $action );
         $self->register_regex( $c, $r, $action );
     }
+    return 1 if @register;
+    return 0;
 }
 
 =item $self->register_regex($c, $re, $action)
index 5fc33c0..b9bc30f 100644 (file)
@@ -271,6 +271,27 @@ sub get_containers {
 sub register {
     my ( $self, $c, $action ) = @_;
 
+    my $registered = $self->registered_dispatch_types;
+
+    my $priv = 0;
+    foreach my $key ( keys %{ $action->attributes } ) {
+        $priv++ if $key eq 'Private';
+        my $class = "Catalyst::DispatchType::$key";
+        unless ( $registered->{$class} ) {
+            eval "require $class";
+            push( @{ $self->dispatch_types }, $class->new ) unless $@;
+            $registered->{$class} = 1;
+        }
+    }
+
+    # Pass the action to our dispatch types so they can register it if reqd.
+    my $reg = 0;
+    foreach my $type ( @{ $self->dispatch_types } ) {
+        $reg++ if $type->register( $c, $action );
+    }
+
+    return unless $reg + $priv;
+
     my $namespace = $action->namespace;
     my $parent    = $self->tree;
     my $visitor   = Tree::Simple::Visitor::FindByPath->new;
@@ -301,22 +322,6 @@ sub register {
 
     # Set the method value
     $parent->getNodeValue->actions->{ $action->name } = $action;
-
-    my $registered = $self->registered_dispatch_types;
-
-    foreach my $key ( keys %{ $action->attributes } ) {
-        my $class = "Catalyst::DispatchType::$key";
-        unless ( $registered->{$class} ) {
-            eval "require $class";
-            push( @{ $self->dispatch_types }, $class->new ) unless $@;
-            $registered->{$class} = 1;
-        }
-    }
-
-    # Pass the action to our dispatch types so they can register it if reqd.
-    foreach my $type ( @{ $self->dispatch_types } ) {
-        $type->register( $c, $action );
-    }
 }
 
 =item $self->setup_actions( $class, $component )