Merge 'namespace_handling_refactor' into 'trunk'
Rafael Kitover [Thu, 25 Jun 2009 09:49:35 +0000 (09:49 +0000)]
r5367@hlagh (orig r10459):  t0m | 2009-06-06 05:56:50 -0700
Branch for mo namespace handling refactor

r5368@hlagh (orig r10460):  mo | 2009-06-06 06:33:53 -0700
refactor of namespace handling
r5369@hlagh (orig r10461):  mo | 2009-06-06 06:34:42 -0700
TODO fix
r5371@hlagh (orig r10466):  mo | 2009-06-07 04:14:23 -0700
controller actions without attributes which are defined via config
r5372@hlagh (orig r10467):  mo | 2009-06-07 04:49:58 -0700
removed commented code
r5373@hlagh (orig r10468):  mo | 2009-06-07 05:28:53 -0700
Added support for ~ prefix to plugins and action classes
r5374@hlagh (orig r10469):  mo | 2009-06-07 05:36:55 -0700
Changes patches
r5686@hlagh (orig r10655):  caelum | 2009-06-24 19:22:27 -0700
cleanup TODO

1  2 
lib/Catalyst/Dispatcher.pm

@@@ -370,7 -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
@@@ -457,6 -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)
@@@ -526,28 -531,9 +526,28 @@@ sub register 
          }
      }
  
 +    my @dtypes = @{ $self->_dispatch_types };
 +    my @normal_dtypes;
 +    my @low_precedence_dtypes;
 +
 +    for my $type ( @dtypes ) {
 +        if ($type->_is_low_precedence) {
 +            push @low_precedence_dtypes, $type;
 +        } else {
 +            push @normal_dtypes, $type;
 +        }
 +    }
 +
      # Pass the action to our dispatch types so they can register it if reqd.
 -    foreach my $type ( @{ $self->_dispatch_types } ) {
 -        $type->register( $c, $action );
 +    my $was_registered = 0;
 +    foreach my $type ( @normal_dtypes ) {
 +        $was_registered = 1 if $type->register( $c, $action );
 +    }
 +
 +    if (not $was_registered) {
 +        foreach my $type ( @low_precedence_dtypes ) {
 +            $type->register( $c, $action );
 +        }
      }
  
      my $namespace = $action->namespace;
@@@ -654,12 -640,11 +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 $@;
@@@ -681,10 -666,9 +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;