From: Matt S Trout Date: Tue, 1 Nov 2005 06:07:18 +0000 (+0000) Subject: - Punted get_action to ActionContainer X-Git-Tag: 5.7099_04~1064 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=79a3189aaa44faea53317e3166ccd36d7603add8 - Punted get_action to ActionContainer --- diff --git a/lib/Catalyst/ActionContainer.pm b/lib/Catalyst/ActionContainer.pm index 337fdf6..14a2fcc 100644 --- a/lib/Catalyst/ActionContainer.pm +++ b/lib/Catalyst/ActionContainer.pm @@ -26,10 +26,20 @@ See L. =over 4 -=item part +=item get_action + +=cut + +sub get_action { + my ( $self, $c, $name ) = @_; + return $self->actions->{$name} if defined $self->actions->{$name}; + return; +} =item actions +=item part + =back =head1 AUTHOR diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index cd56ad4..ee513e7 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -198,19 +198,18 @@ sub prepare_action { =cut sub get_action { - my ( $self, $c, $action, $namespace ) = @_; - return [] unless $action; + my ( $self, $c, $name, $namespace ) = @_; + return unless $name; $namespace ||= ''; $namespace = '' if $namespace eq '/'; my @match = $self->get_containers($namespace); - my $node = $match[-1]->actions; # Only bother looking at the last one + return unless @match; - if ( defined $node->{$action} - && ( $node->{$action}->namespace eq $namespace ) ) + if ( my $action = $match[-1]->get_action( $c, $name ) ) { - return $node->{$action}; + return $action if $action->namespace eq $namespace; } } @@ -226,11 +225,7 @@ sub get_actions { my @match = $self->get_containers($namespace); - return - map { $_->{$action} } - grep { defined $_->{$action} } # If it exists in the container - map { $_->actions } # Get action hash for container - @match + return map { $_->get_action($c, $action) } @match; } =item $self->get_containers( $namespace ) @@ -320,8 +315,28 @@ sub set_action { } return unless keys %attributes; - my $parent = $self->tree; - my $visitor = Tree::Simple::Visitor::FindByPath->new; + my $reverse = $namespace ? "$namespace/$method" : $method; + + my $action = Catalyst::Action->new( + { + name => $method, + code => $code, + reverse => $reverse, + namespace => $namespace, + class => $class, + attributes => \%attributes, + } + ); + + $self->register($c, $action); +} + +sub register { + my ( $self, $c, $action ) = @_; + + my $namespace = $action->namespace; + my $parent = $self->tree; + my $visitor = Tree::Simple::Visitor::FindByPath->new; if ($namespace) { for my $part ( split '/', $namespace ) { @@ -347,21 +362,8 @@ sub set_action { } } - my $reverse = $namespace ? "$namespace/$method" : $method; - - my $action = Catalyst::Action->new( - { - name => $method, - code => $code, - reverse => $reverse, - namespace => $namespace, - class => $class, - attributes => \%attributes, - } - ); - # Set the method value - $parent->getNodeValue->actions->{$method} = $action; + $parent->getNodeValue->actions->{$action->name} = $action; # Pass the action to our dispatch types so they can register it if reqd. foreach my $type ( @{ $self->dispatch_types } ) {