Merge 'namespace_handling_refactor' into 'trunk'
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Dispatcher.pm
index cb22e63..be7787a 100644 (file)
@@ -370,9 +370,7 @@ sub prepare_action {
 
   DESCEND: while (@path) {
         $path = join '/', @path;
-        $path =~ s#^/##;
-
-        $path = '' if $path eq '/';    # Root action
+        $path =~ s#^/+##;
 
         # Check out dispatch types to see if any will handle the path at
         # this level
@@ -459,9 +457,6 @@ sub get_containers {
     }
 
     return reverse grep { defined } @containers, $self->_container_hash->{''};
-
-    #return (split '/', $namespace); # isnt this more clear?
-    my @parts = split '/', $namespace;
 }
 
 =head2 $self->uri_for_action($action, \@captures)
@@ -535,9 +530,8 @@ sub register {
     my @normal_dtypes;
     my @low_precedence_dtypes;
 
-    while (my $type = shift @dtypes) {
-        if ($type->isa('Catalyst::DispatchType::Index') ||  
-            $type->isa('Catalyst::DispatchType::Default')) {
+    for my $type ( @dtypes ) {
+        if ($type->_is_low_precedence) {
             push @low_precedence_dtypes, $type;
         } else {
             push @normal_dtypes, $type;
@@ -660,12 +654,11 @@ sub _load_dispatch_types {
     my ( $self, @types ) = @_;
 
     my @loaded;
-
     # Preload action types
     for my $type (@types) {
-        my $class =
-          ( $type =~ /^\+(.*)$/ ) ? $1 : "Catalyst::DispatchType::${type}";
-
+        # first param is undef because we cannot get the appclass
+        my $class = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $type);
+        
         eval { Class::MOP::load_class($class) };
         Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ )
           if $@;
@@ -687,10 +680,9 @@ of course it's being used.)
 
 sub dispatch_type {
     my ($self, $name) = @_;
-
-    unless ($name =~ s/^\+//) {
-        $name = "Catalyst::DispatchType::" . $name;
-    }
+    
+    # first param is undef because we cannot get the appclass
+    $name = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $name);
 
     for (@{ $self->_dispatch_types }) {
         return $_ if ref($_) eq $name;