X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=961ce150aa64372982c786c5ffc3ce658c144881;hb=8505565b33db11c9c5059225b5fbb7cd7d79eb94;hp=f1ccb80c76575623ad79ea875a5658e1cc145080;hpb=9e81ba44fc01c668e27370aa3eb0d476316ba589;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index f1ccb80..961ce15 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -372,35 +372,49 @@ sub register { return unless $reg + $priv; my $namespace = $action->namespace; - my $parent = $self->tree; - my $visitor = Tree::Simple::Visitor::FindByPath->new; - - if ($namespace) { - for my $part ( split '/', $namespace ) { - $visitor->setSearchPath($part); - $parent->accept($visitor); - my $child = $visitor->getResult; - - unless ($child) { - - # Create a new tree node and an ActionContainer to form - # its value. - - my $container = - Catalyst::ActionContainer->new( - { part => $part, actions => {} } ); - $child = $parent->addChild( Tree::Simple->new($container) ); - $visitor->setSearchPath($part); - $parent->accept($visitor); - $child = $visitor->getResult; - } - - $parent = $child; - } - } + my $node = $self->find_or_create_namespace_node( $namespace ); # Set the method value - $parent->getNodeValue->actions->{ $action->name } = $action; + $node->getNodeValue->actions->{ $action->name } = $action; +} + +sub find_or_create_namespace_node { + my ( $self, $namespace ) = @_; + + my $tree ||= $self->tree; + my $visitor ||= Tree::Simple::Visitor::FindByPath->new; + + + return $tree unless $namespace; + + my @namespace = split '/', $namespace; + return $self->_find_or_create_namespace_node( $tree, $visitor, @namespace ); +} + +sub _find_or_create_namespace_node { + my ( $self, $parent, $visitor, $part, @namespace ) = @_; + + return $parent unless $part; + + $visitor->setSearchPath($part); + $parent->accept($visitor); + my $child = $visitor->getResult; + + unless ($child) { + + # Create a new tree node and an ActionContainer to form + # its value. + + my $container = + Catalyst::ActionContainer->new( + { part => $part, actions => {} } ); + $child = $parent->addChild( Tree::Simple->new($container) ); + $visitor->setSearchPath($part); + $parent->accept($visitor); + $child = $visitor->getResult; + } + + $self->_find_or_create_namespace_node( $child, $visitor, @namespace ); } =head2 $self->setup_actions( $class, $context )