From: John Napiorkowski Date: Tue, 27 Sep 2022 15:56:01 +0000 (-0500) Subject: don't mess with the class attribute X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=191df47efae78dc8ec2f63561be17ece51cd82e0;p=catagits%2FCatalyst-Runtime.git don't mess with the class attribute --- diff --git a/lib/Catalyst/Action.pm b/lib/Catalyst/Action.pm index 6fa9d19..246eca5 100644 --- a/lib/Catalyst/Action.pm +++ b/lib/Catalyst/Action.pm @@ -26,6 +26,7 @@ with 'MooseX::Emulate::Class::Accessor::Fast'; use namespace::clean -except => 'meta'; has class => (is => 'rw'); +has instance => (is=>'ro', required=>0, predicate=>'has_instance'); has namespace => (is => 'rw'); has 'reverse' => (is => 'rw'); has attributes => (is => 'rw'); @@ -361,7 +362,11 @@ no warnings 'recursion'; sub dispatch { # Execute ourselves against a context my ( $self, $c ) = @_; - return $c->execute( $self->class, $self ); + if($self->has_instance) { + return $c->execute( $self->instance, $self ); + } else { + return $c->execute( $self->class, $self ); + } } sub execute { diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index df18275..703efc8 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -150,6 +150,7 @@ sub _command2action { # go to a string path ("/foo/bar/gorch") # or action object + # if (blessed($command) && $command->isa('Catalyst::Action')) { $action = $command; } @@ -338,15 +339,14 @@ sub _invoke_as_component { return $possible_action if $possible_action; } - my $component_to_call = blessed($component_or_class) ? $component_or_class : $component_class; - - if ( my $code = $component_to_call->can($method) ) { + if ( my $code = $component_class->can($method) ) { return $self->_method_action_class->new( { name => $method, code => $code, reverse => "$component_class->$method", - class => $component_to_call, + class => $component_class, + ( blessed($component_or_class) ? (instance => $component_or_class):() ), namespace => Catalyst::Utils::class2prefix( $component_class, ref($c)->config->{case_sensitive} ), diff --git a/t/forward_instances.t b/t/forward_instances.t index 3588d91..c2de2ed 100644 --- a/t/forward_instances.t +++ b/t/forward_instances.t @@ -11,7 +11,7 @@ use Test::More; use base 'Catalyst::Controller'; - sub test :Local Args(0) { + sub test_forward :Local Args(0) { my( $self, $c ) = @_; my $view = $c->view('Test'); $c->forward($view); @@ -32,7 +32,6 @@ use Test::More; sub process { my ($self, $c, @args) = @_; $c->res->body("$self"); - } package MyApp; @@ -44,7 +43,7 @@ use HTTP::Request::Common; use Catalyst::Test 'MyApp'; { - ok my $res = request GET 'root/test'; + ok my $res = request GET 'root/test_forward'; } done_testing(2);