[Catalyst-commits] r10608 - in Catalyst-Runtime/5.80/branches/index_default_fuckage: lib/Catalyst lib/Catalyst/DispatchType t/aggregate

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Sun Jun 21 00:26:22 GMT 2009


Author: caelum
Date: 2009-06-21 00:26:22 +0000 (Sun, 21 Jun 2009)
New Revision: 10608

Modified:
   Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Default.pm
   Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Path.pm
   Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/Dispatcher.pm
   Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_index_or_default.t
Log:
fix root default thingie jayk gave me, sanitize Paths at registration time better

Modified: Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Default.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Default.pm	2009-06-21 00:19:34 UTC (rev 10607)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Default.pm	2009-06-21 00:26:22 UTC (rev 10608)
@@ -41,7 +41,7 @@
 
 sub match {
     my ( $self, $c, $path ) = @_;
-    return if $path =~ m!/!;    # Not at root yet, wait for it ...
+    return if $path ne '';    # Not at root yet, wait for it ...
     my $result = ( $c->get_actions( 'default', $c->req->path ) )[-1];
 
     # Find default on namespace or super

Modified: Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Path.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Path.pm	2009-06-21 00:19:34 UTC (rev 10607)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/DispatchType/Path.pm	2009-06-21 00:26:22 UTC (rev 10608)
@@ -116,6 +116,7 @@
     $path =~ s!^/!!;
     $path = '/' unless length $path;
     $path = URI->new($path)->canonical;
+    $path =~ s{(?<=[^/])/+\z}{};
 
     $self->_paths->{$path} = [
         sort { $a <=> $b } ($action, @{ $self->_paths->{$path} || [] })

Modified: Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/Dispatcher.pm	2009-06-21 00:19:34 UTC (rev 10607)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/lib/Catalyst/Dispatcher.pm	2009-06-21 00:26:22 UTC (rev 10608)
@@ -370,10 +370,8 @@
 
   DESCEND: while (@path) {
         $path = join '/', @path;
-        $path =~ s#^/##;
+        $path =~ s#^/+##;
 
-        $path = '' if $path eq '/';    # Root action
-
         # Check out dispatch types to see if any will handle the path at
         # this level
 
@@ -459,9 +457,6 @@
     }
 
     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)

Modified: Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_index_or_default.t
===================================================================
--- Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_index_or_default.t	2009-06-21 00:19:34 UTC (rev 10607)
+++ Catalyst-Runtime/5.80/branches/index_default_fuckage/t/aggregate/live_component_controller_action_index_or_default.t	2009-06-21 00:26:22 UTC (rev 10608)
@@ -10,7 +10,7 @@
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
-use Test::More tests => 3*$iters;
+use Test::More tests => 6*$iters;
 
 use Catalyst::Test 'TestAppIndexDefault';
 
@@ -27,5 +27,14 @@
 sub run_tests {
     is(get('/indexchained'), 'index_chained', ':Chained overrides index');
     is(get('/indexprivate'), 'index_private', 'index : Private still works');
+
+# test :Path overriding default
     is(get('/one_arg'), 'path_one_arg', ':Path overrides default');
+    is(get('/one_arg/foo/bar'), 'default', 'default still works');
+
+# now the same thing with a namespace, and a trailing / on the :Path
+    is(get('/default/one_arg'), 'default_path_one_arg',
+        ':Path overrides default');
+    is(get('/default/one_arg/foo/bar'), 'default_default',
+        'default still works');
 }




More information about the Catalyst-commits mailing list