Use REST::ForBrowsers action class
[catagits/CatalystX-Routes.git] / lib / CatalystX / Routes.pm
index e284835..1801983 100644 (file)
@@ -42,7 +42,7 @@ sub del {
 sub _add_route {
     my $rest = shift;
     my $meta = shift;
-    my ( $name, $attrs, $sub ) = _process_args(@_);
+    my ( $name, $attrs, $sub ) = _process_args( $meta, @_ );
 
     my $meth_base = '__route__' . $name;
 
@@ -55,10 +55,6 @@ sub _add_route {
     return;
 }
 
-sub path_part ($) {
-    return ( PathPart => [ $_[0] ] );
-}
-
 sub chained ($) {
     return ( Chained => [ $_[0] ] );
 }
@@ -71,11 +67,16 @@ sub capture_args ($) {
     return ( CaptureArgs => [ $_[0] ] );
 }
 
+sub path_part ($) {
+    return ( PathPart => [ $_[0] ] );
+}
+
 sub action ($) {
     return ( ActionClass => [ $_[0] ] );
 }
 
 sub _process_args {
+    my $meta = shift;
     my $path = shift;
     my $sub  = pop;
 
@@ -90,18 +91,22 @@ sub _process_args {
 
     my %p = @_;
 
-    $p{ActionClass} ||= 'REST';
+    $p{ActionClass} ||= 'REST::ForBrowsers';
 
     unless ( exists $p{Chained} ) {
         $p{Chained} = q{/};
 
-        unless ( exists $p{PathPart} ) {
-            ( my $part = $path ) =~ s{^/}{};
+        unless ( $p{PathPart} ) {
+            my $part = $path;
+            unless ( $part =~ s{^/}{} ) {
+                $part = $meta->name()->action_namespace('FakeConfig') . q{/} . $part;
+            }
+
             $p{PathPart} = [$part];
         }
     }
 
-    unless ( exists $p{Args} ) {
+    unless ( $p{Args} || $p{Local} ) {
         $p{Args} = [0];
     }
 
@@ -144,4 +149,14 @@ sub _STRINGLIKE0 ($) {
         && length "$_[0]" );
 }
 
+{
+    # This is a nasty hack around some weird back compat code in
+    # Catalyst::Controller->action_namespace
+    package FakeConfig;
+
+    sub config {
+        return { case_sensitive => 0 };
+    }
+}
+
 1;