[Catalyst-commits] r10953 - in Catalyst-Runtime/5.80/branches/contextual_uri_for: lib lib/Catalyst t

pjfl at dev.catalyst.perl.org pjfl at dev.catalyst.perl.org
Wed Jul 22 23:39:54 GMT 2009


Author: pjfl
Date: 2009-07-22 23:39:52 +0000 (Wed, 22 Jul 2009)
New Revision: 10953

Modified:
   Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst.pm
   Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst/Action.pm
   Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst/Dispatcher.pm
   Catalyst-Runtime/5.80/branches/contextual_uri_for/t/unit_core_contextual_uri_for.t
Log:
- Added POD for contextual uri_for

Modified: Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst/Action.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst/Action.pm	2009-07-22 22:48:51 UTC (rev 10952)
+++ Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst/Action.pm	2009-07-22 23:39:52 UTC (rev 10953)
@@ -90,47 +90,6 @@
     return $a1_args <=> $a2_args;
 }
 
-=head2 $self->splice_cpatures_from( $c, $args )
-
-=cut
-
-sub splice_captures_from {
-    my ($self, $c, $cdr) = @_;
-
-    my @captures = ();
-    my $attrs    = $self->attributes || {};
-    my @chain    = @{ $c->dispatcher->expand_action( $self )->chain };
-    my $params   = $cdr && $cdr->[0] && ref $cdr->[-1] eq q(HASH)
-                 ? pop @{ $cdr } : undef;
-
-    if ($attrs->{CaptureArgs}) {
-        my $error = 'Action '.$self->reverse.' is a midpoint';
-
-        $c->log->debug( $error ) if ($c->debug);
-
-        return;
-    }
-
-    pop @chain;
-
-    # Now start from the root of the chain, populate captures
-    for my $num_caps (map { $_->attributes->{CaptureArgs}->[0] } @chain) {
-        if ($num_caps > scalar @{ $cdr }) {
-            my $error = 'Action '.$self->reverse.' insufficient args';
-
-            $c->log->debug( $error ) if ($c->debug);
-
-            return;
-        }
-
-        push @captures, splice @{ $cdr }, 0, $num_caps;
-    }
-
-    push @{ $cdr }, $params if ($params); # Restore query parameters
-
-    return \@captures;
-}
-
 __PACKAGE__->meta->make_immutable;
 
 1;
@@ -192,9 +151,6 @@
 
 Provided by Moose
 
-=head2 splice_captures_from
-
-
 =head1 AUTHORS
 
 Catalyst Contributors, see Catalyst.pm

Modified: Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst/Dispatcher.pm	2009-07-22 22:48:51 UTC (rev 10952)
+++ Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst/Dispatcher.pm	2009-07-22 23:39:52 UTC (rev 10953)
@@ -391,6 +391,8 @@
       if ( $c->debug && @args );
 }
 
+# ' Emacs highlight fix. Remove before commit
+
 =head2 $self->get_action( $action, $namespace )
 
 returns a named action from a given namespace.
@@ -419,25 +421,6 @@
     $self->_action_hash->{$path};
 }
 
-=head2 $self->get_action_by_type( @args )
-
-Returns the action object for the specified args if one exists, otherwise
-returns C<undef>. Calls L</get_action_with_defaults> and if that does not
-return an action, calls L</get_action_by_controller>
-
-=cut
-
-sub get_action_by_type {
-    # Return an action object or undef
-    my ($self, $c, $car, $cdr) = @_; my $action;
-
-    return $action if ($action = $car and blessed( $car ));
-    return $action if ($action = $self->get_action_with_defaults( $c, $car ));
-    return $action
-       if ($action = $self->get_action_by_controller( $c, $car, $cdr ));
-    return;
-}
-
 =head2 $self->get_action_by_controller( qw(Controller::Class method_name) );
 
 Returns the action associated with the given controller and method. Provides
@@ -446,38 +429,37 @@
 =cut
 
 sub get_action_by_controller {
-   # Return an action object if parameters are a controller class and method
-   my ($self, $c, $cname, $cdr) = @_;
+    # Return an action object if parameters are a controller class and method
+    my ($self, $c, $cname, $cdr) = @_; my ($action, $controller); $cdr ||= [];
 
-   my ($action, $controller); my $sep = q(/); $cdr ||= [];
+    return unless ($cname and $controller = $c->controller( $cname ));
 
-   return unless ($cname and $controller = $c->controller( $cname ));
+    my $sep  = q(/);
+    my $path = $controller->action_namespace.$sep.($cdr->[0] || q());
 
-   my $path = $controller->action_namespace.$sep.($cdr->[0] || q());
+    $path = q(root) if ($path eq $sep);
 
-   $path = q(root) if ($path eq $sep);
+    return unless ($action = $self->get_action_by_private_path( $c, $path ));
 
-   return unless ($action = $self->get_action_with_defaults( $c, $path ));
+    shift @{ $cdr }; # Loose the controller method name
 
-   shift @{ $cdr }; # Loose the controller method name
-
-   return $action;
+    return $action;
 }
 
-=head2 $self->get_action_with_defaults( q(namespace/method_name) );
+=head2 $self->get_action_by_private_path( q(namespace/method_name) );
 
 Returns the action associated with the private action path. Provides
-defaults for namespace and method name. A namespace of I<root>
-is mapped to I</>
+defaults for namespace and method name. The namespace defaults to that
+of the current action, a namespace of I<root> is mapped to I</>.  The
+method name defaults to C<< $c->config->{dispatcher_default_action} >>
+if set, 'default' otherwise
 
 =cut
 
-sub get_action_with_defaults {
+sub get_action_by_private_path {
     # Return an action object. Provide defaults for a call to get_action
     my ($self, $c, $path) = @_; my $sep = q(/);
 
-    return unless ($path or $c->config->{dispatcher_defaults_to_action});
-
     # Normalise the path. It must contain a sep char
     $path ||= $sep;
     $path  .= $sep if (0 > index $path, $sep);
@@ -496,6 +478,46 @@
     return $self->get_action( $name, $namespace );
 }
 
+=head2 $self->splice_captures_from( $c, $action, $args )
+
+Gets the action chain for the supplied action. Calculates the number
+of capture args and returns and array ref spliced off the front of the
+supplied args
+
+=cut
+
+sub splice_captures_from {
+    my ($self, $c, $action, $cdr) = @_; my $attrs = $action->attributes || {};
+
+    if ($attrs->{CaptureArgs}) {
+        $c->log->debug( 'Action '.$action->reverse.' is a midpoint' )
+            if ($c->debug);
+
+        return;
+    }
+
+    my @captures = ();
+    my @chain    = @{ $self->expand_action( $action )->chain }; pop @chain;
+    my $params   = $cdr && $cdr->[0] && ref $cdr->[-1] eq q(HASH)
+                 ? pop @{ $cdr } : undef;
+
+    # Now start from the root of the chain, populate captures
+    for my $num_caps (map { $_->attributes->{CaptureArgs}->[0] } @chain) {
+        if ($num_caps > scalar @{ $cdr }) {
+            $c->log->debug( 'Action '.$action->reverse.' insufficient args' )
+                if ($c->debug);
+
+            return;
+        }
+
+        push @captures, splice @{ $cdr }, 0, $num_caps;
+    }
+
+    push @{ $cdr }, $params if ($params); # Restore query parameters
+
+    return \@captures;
+}
+
 =head2 $self->get_actions( $c, $action, $namespace )
 
 =cut

Modified: Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst.pm	2009-07-22 22:48:51 UTC (rev 10952)
+++ Catalyst-Runtime/5.80/branches/contextual_uri_for/lib/Catalyst.pm	2009-07-22 23:39:52 UTC (rev 10953)
@@ -1252,22 +1252,39 @@
     $res;
 }
 
-=head2 $c->_get_action_and_flatten_args
+# ' Emacs highlight fix. Remove before commit
 
+=head2 $c->_get_action_and_flatten_args( $c, $action, \@args )
+
+=head2 $c->_get_action_and_flatten_args( $c, $controller_name, \@args )
+
+=head2 $c->_get_action_and_flatten_args( $c, $private_action_path, \@args )
+
+Get an action object from the first one or two supplied args. Splice
+the capture args from the supplied args if required
+
 =cut
 
 sub _get_action_and_flatten_args {
     my ($c, $car, $cdr) = @_; my $action;
 
-    unless ($action = $c->dispatcher->get_action_by_type( $c, $car, $cdr )) {
-       return;
+    return $action if ($action = $car and blessed( $car ));
+
+    return unless ($c->config->{contextual_uri_for});
+
+    $action = $c->dispatcher->get_action_by_controller( $c, $car, $cdr );
+
+    unless ($action) {
+        $action = $c->dispatcher->get_action_by_private_path( $c, $car );
     }
 
+    return unless ($action);
+
     my $attrs = $action->attributes || {};
 
     return $action unless ($attrs->{Chained});
 
-    my $captures = $action->splice_captures_from( $c, $cdr );
+    my $captures = $c->dispatcher->splice_captures_from( $c, $action, $cdr );
 
     unshift @{ $cdr }, $captures if ($captures);
 

Modified: Catalyst-Runtime/5.80/branches/contextual_uri_for/t/unit_core_contextual_uri_for.t
===================================================================
--- Catalyst-Runtime/5.80/branches/contextual_uri_for/t/unit_core_contextual_uri_for.t	2009-07-22 22:48:51 UTC (rev 10952)
+++ Catalyst-Runtime/5.80/branches/contextual_uri_for/t/unit_core_contextual_uri_for.t	2009-07-22 23:39:52 UTC (rev 10953)
@@ -15,8 +15,8 @@
 
 my $context = TestApp->new( { request => $request } );
 
-$context->config( dispatcher_defaults_to_action => 1,
-                  dispatcher_default_action     => q(default_endpoint), );
+$context->config( contextual_uri_for        => 1,
+                  dispatcher_default_action => q(default_endpoint), );
 
 is( $context->uri_for,
     q(http://127.0.0.1/),




More information about the Catalyst-commits mailing list