Fix C::Request disparity between _body and body accessors, TODO test now passes.
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Dispatcher.pm
index 575b1a6..0b26232 100644 (file)
@@ -2,6 +2,7 @@ package Catalyst::Dispatcher;
 
 use Moose;
 use Class::MOP;
+with 'MooseX::Emulate::Class::Accessor::Fast';
 
 use Catalyst::Exception;
 use Catalyst::Utils;
@@ -32,6 +33,14 @@ has postload_dispatch_types => (is => 'rw', required => 1, lazy => 1, default =>
 has _action_hash => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
 has _container_hash => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
 
+# Wrap accessors so you can assign a list and it will capture a list ref.
+around qw/preload_dispatch_types postload_dispatch_types/ => sub {
+    my $orig = shift;
+    my $self = shift;
+    return $self->$orig([@_]) if (scalar @_ && ref $_[0] ne 'ARRAY');
+    return $self->$orig(@_);
+};
+
 no Moose;
 
 =head1 NAME
@@ -133,8 +142,13 @@ sub _command2action {
     my $action;
 
     # go to a string path ("/foo/bar/gorch")
-    # or action object which stringifies to that
-    $action = $self->_invoke_as_path( $c, "$command", \@args );
+    # or action object
+    if (Scalar::Util::blessed($command) && $command->isa('Catalyst::Action')) {
+        $action = $command;
+    }
+    else {
+        $action = $self->_invoke_as_path( $c, "$command", \@args );
+    }
 
     # go to a component ( "MyApp::*::Foo" or $c->component("...")
     # - a path or an object)