Remove use of overload
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Chained.pm
index bc12721..5bf3853 100644 (file)
@@ -1,33 +1,36 @@
 package Catalyst::DispatchType::Chained;
 
+use Class::C3;
 use Moose;
+extends 'Catalyst::DispatchType';
+
 use Text::SimpleTable;
 use Catalyst::ActionChain;
 use URI;
 
-extends 'Catalyst::DispatchType';
-
 has _endpoints => (
-                   isa => 'rw',
+                   is => 'rw',
                    isa => 'ArrayRef',
                    required => 1,
                    default => sub{ [] },
                   );
 
 has _actions => (
-                 isa => 'rw',
+                 is => 'rw',
                  isa => 'HashRef',
                  required => 1,
                  default => sub{ {} },
                 );
 
 has _children_of => (
-                     isa => 'rw',
+                     is => 'rw',
                      isa => 'HashRef',
                      required => 1,
                      default => sub{ {} },
                     );
 
+no Moose;
+
 # please don't perltidy this. hairy code within.
 
 =head1 NAME
@@ -119,20 +122,21 @@ Calls C<recurse_match> to see if a chain matches the C<$path>.
 sub match {
     my ( $self, $c, $path ) = @_;
 
-    return 0 if @{$c->req->args};
+    my $request = $c->request;
+    return 0 if @{$request->args};
 
     my @parts = split('/', $path);
 
     my ($chain, $captures, $parts) = $self->recurse_match($c, '/', \@parts);
-    push @{$c->req->args}, @$parts if $parts && @$parts;
+    push @{$request->args}, @$parts if $parts && @$parts;
 
     return 0 unless $chain;
 
     my $action = Catalyst::ActionChain->from_chain($chain);
 
-    $c->req->action("/${action}");
-    $c->req->match("/${action}");
-    $c->req->captures($captures);
+    $request->action("/${action}");
+    $request->match("/${action}");
+    $request->captures($captures);
     $c->action($action);
     $c->namespace( $action->namespace );
 
@@ -197,7 +201,7 @@ sub recurse_match {
                 #    No best action currently
                 # OR This one matches with fewer parts left than the current best action,
                 #    And therefore is a better match
-                # OR No parts and this expects 0
+                # OR No parts and this expects 0 
                 #    The current best action might also be Args(0),
                 #    but we couldn't chose between then anyway so we'll take the last seen
 
@@ -254,7 +258,7 @@ sub register {
 
     $action->attributes->{Chained} = [ $parent ];
 
-    my $children = $self->_children_of->{$parent};
+    my $children = ($self->_children_of->{$parent} ||= {});
 
     my @path_part = @{ $action->attributes->{PathPart} || [] };
 
@@ -264,13 +268,13 @@ sub register {
         $part = $path_part[0];
     } elsif (@path_part > 1) {
         Catalyst::Exception->throw(
-          "Multiple PathPart attributes not supported registering ${action}"
+          "Multiple PathPart attributes not supported registering " . $action->reverse()
         );
     }
 
     if ($part =~ m(^/)) {
         Catalyst::Exception->throw(
-          "Absolute parameters to PathPart not allowed registering ${action}"
+          "Absolute parameters to PathPart not allowed registering " . $action->reverse()
         );
     }
 
@@ -324,9 +328,11 @@ sub uri_for_action {
     return undef if @captures; # fail for too many captures
 
     return join('/', '', @parts);
-
+   
 }
 
+__PACKAGE__->meta->make_immutable;
+
 =head1 USAGE
 
 =head2 Introduction
@@ -485,7 +491,7 @@ this debugging output:
   '-----------------------+------------------------------'
   ...
 
-Here's a more detailed specification of the attributes belonging to
+Here's a more detailed specification of the attributes belonging to 
 C<:Chained>:
 
 =head2 Attributes