minor changes
Rafael Kitover [Sat, 20 Jun 2009 17:18:53 +0000 (17:18 +0000)]
lib/Catalyst/Action.pm
lib/Catalyst/DispatchType/Path.pm
t/aggregate/live_component_controller_action_index_or_default.t
t/lib/TestAppIndexDefault/Controller/Root.pm [moved from t/lib/TestAppIndexDefault/Controller/DefaultAndPath.pm with 71% similarity]

index 0eb9942..97b9235 100644 (file)
@@ -124,6 +124,14 @@ context and arguments
 Check Args attribute, and makes sure number of args matches the setting.
 Always returns true if Args is omitted.
 
+=head2 sort_order
+
+Returns the value of the C<Args> attribute, or C<~0> if it has no value.
+
+=head2 compare
+
+Returns C<< $a->sort_order <=> $b->sort_order >> .
+
 =head2 namespace
 
 Returns the private namespace this action lives in.
index 50fbf84..5c1e4ed 100644 (file)
@@ -74,7 +74,9 @@ sub match {
 
     $path = '/' if !defined $path || !length $path;
 
-    foreach my $action ( @{ $self->_paths->{$path} || [] } ) {
+    my @actions = @{ $self->_paths->{$path} || [] };
+
+    foreach my $action ( @actions ) {
         next unless $action->match($c);
         $c->req->action($path);
         $c->req->match($path);
@@ -115,9 +117,9 @@ sub register_path {
     $path = '/' unless length $path;
     $path = URI->new($path)->canonical;
 
-    unshift( @{ $self->_paths->{$path} ||= [] }, $action);
-
-    $self->_paths->{$path} = [ sort @{ $self->_paths->{$path} } ];
+    $self->_paths->{$path} = [
+        sort { $a <=> $b } ($action, @{ $self->_paths->{$path} || [] })
+    ];
 
     return 1;
 }
index d385add..fada74b 100644 (file)
@@ -27,6 +27,5 @@ else {
 sub run_tests {
     is(get('/indexchained'), 'index_chained', ':Chained overrides index');
     is(get('/indexprivate'), 'index_private', 'index : Private still works');
-    is(get('/defaultandpath/path_one_arg'), 'path_one_arg',
-        'Path overrides default');
+    is(get('/one_arg'), 'path_one_arg', ':Path overrides default');
 }
@@ -1,7 +1,9 @@
-package TestAppIndexDefault::Controller::DefaultAndPath;
+package TestAppIndexDefault::Controller::Root;
 
 use base 'Catalyst::Controller';
 
+__PACKAGE__->config->{namespace} = '';
+
 sub default : Private {
     my ($self, $c) = @_;
     $c->res->body('default');