X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=2933de909c30bf0a92a0bb0b37b7c2397a6f9be1;hb=c71165175d6b8e7e722d0ef1c58ddddf14c6a4c1;hp=cc40dc1f20a8c60309803472644c8b48cb945f5e;hpb=15e9b5ddb1d1368677b9dfd59ec5625d9b3459e1;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index cc40dc1..2933de9 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -19,6 +19,7 @@ __PACKAGE__->mk_accessors( qw/tree dispatch_types registered_dispatch_types method_action_class action_container_class preload_dispatch_types postload_dispatch_types + action_hash / ); @@ -58,6 +59,7 @@ sub new { # set the default pre- and and postloads $obj->preload_dispatch_types( \@PRELOAD ); $obj->postload_dispatch_types( \@POSTLOAD ); + $obj->action_hash({}); return $obj; } @@ -271,13 +273,7 @@ sub get_action { $namespace ||= ''; $namespace = '' if $namespace eq '/'; - my @match = $self->get_containers($namespace); - - return unless @match; - - if ( my $action = $match[-1]->get_action($name) ) { - return $action if $action->namespace eq $namespace; - } + return $self->action_hash->{ "$namespace/$name" }; } =head2 $self->get_actions( $c, $action, $namespace ) @@ -372,43 +368,52 @@ sub register { return unless $reg + $priv; my $namespace = $action->namespace; + my $name = $action->name; + my $node = $self->find_or_create_namespace_node( $namespace ); # Set the method value - $node->getNodeValue->actions->{ $action->name } = $action; + $node->getNodeValue->actions->{ $name } = $action; + + my $path = "$namespace/$name"; + + if ( exists $self->action_hash->{$path} and $self->action_hash->{$path} != $action ) { + warn "inconsistency: $path is already registered"; + } + + $self->action_hash->{$path} = $action; } sub find_or_create_namespace_node { - my ( $self, $namespace, $parent, $visitor ) = @_; + my ( $self, $namespace ) = @_; + + my $tree ||= $self->tree; - $parent ||= $self->tree; - $visitor ||= Tree::Simple::Visitor::FindByPath->new; + return $tree unless $namespace; - if ($namespace) { - for my $part ( split '/', $namespace ) { - $visitor->setSearchPath($part); - $parent->accept($visitor); - my $child = $visitor->getResult; + my @namespace = split '/', $namespace; + return $self->_find_or_create_namespace_node( $tree, @namespace ); +} - unless ($child) { +sub _find_or_create_namespace_node { + my ( $self, $parent, $part, @namespace ) = @_; - # Create a new tree node and an ActionContainer to form - # its value. + return $parent unless $part; - my $container = - Catalyst::ActionContainer->new( - { part => $part, actions => {} } ); - $child = $parent->addChild( Tree::Simple->new($container) ); - $visitor->setSearchPath($part); - $parent->accept($visitor); - $child = $visitor->getResult; - } + my $child = ( grep { $_->getNodeValue->part eq $part } $parent->getAllChildren )[0]; - $parent = $child; - } - } + unless ($child) { + # Create a new tree node and an ActionContainer to form + # its value. + + my $container = + Catalyst::ActionContainer->new( + { part => $part, actions => {} } ); + + $parent->addChild( $child = Tree::Simple->new($container) ); + } - return $parent; + $self->_find_or_create_namespace_node( $child, @namespace ); } =head2 $self->setup_actions( $class, $context )