From: Sebastian Riedel Date: Thu, 10 Nov 2005 00:34:05 +0000 (+0000) Subject: Only register private actions when needed X-Git-Tag: 5.7099_04~983 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=694d15f1f6031de10d1ecb047b9e66dd0982e3a3 Only register private actions when needed --- diff --git a/lib/Catalyst/AttrContainer.pm b/lib/Catalyst/AttrContainer.pm index b330adc..35741e4 100644 --- a/lib/Catalyst/AttrContainer.pm +++ b/lib/Catalyst/AttrContainer.pm @@ -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] ] ] ); diff --git a/lib/Catalyst/DispatchType/Path.pm b/lib/Catalyst/DispatchType/Path.pm index cffe66b..ccff553 100644 --- a/lib/Catalyst/DispatchType/Path.pm +++ b/lib/Catalyst/DispatchType/Path.pm @@ -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; } diff --git a/lib/Catalyst/DispatchType/Regex.pm b/lib/Catalyst/DispatchType/Regex.pm index def40e8..38b2513 100644 --- a/lib/Catalyst/DispatchType/Regex.pm +++ b/lib/Catalyst/DispatchType/Regex.pm @@ -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) diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 5fc33c0..b9bc30f 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -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 )