X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=6e182fa847146307b06fbd792fda2da07287740b;hp=2786b2ef52fee60d3a1f04e4d6c387e93417a261;hb=02298d3acbba3136f6c216651373a479f171e50e;hpb=0f0d5870f79757617666432d22312e2823c1e1af diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 2786b2e..6e182fa 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -307,43 +307,44 @@ sub _invoke_as_path { } } -sub _find_component_class { +sub _find_component { my ( $self, $c, $component ) = @_; - return ref($component) - || ref( $c->component($component) ) - || $c->component($component); + # fugly, why doesn't ->component('MyApp') work? + return $c if ($component eq blessed($c)); + + return blessed($component) + ? $component + : $c->component($component); } sub _invoke_as_component { - my ( $self, $c, $component, $method ) = @_; + my ( $self, $c, $component_or_class, $method ) = @_; - #FIXME - Is this resolving needed/should it just return the instance - # directly - my $class = $self->_find_component_class( $c, $component ) || return 0; + my $component = $self->_find_component($c, $component_or_class); + my $component_class = blessed $component || return 0; - my $component_instance = $c->component($class); - if (my $code = $component_instance->can('action_for')) { - my $possible_action = $component_instance->$code($method); + if (my $code = $component_class->can('action_for')) { + my $possible_action = $component->$code($method); return $possible_action if $possible_action; } - if ( my $code = $class->can($method) ) { + if ( my $code = $component_class->can($method) ) { return $self->_method_action_class->new( { name => $method, code => $code, - reverse => "$class->$method", - class => $class, + reverse => "$component_class->$method", + class => $component_class, namespace => Catalyst::Utils::class2prefix( - $class, $c->config->{case_sensitive} + $component_class, $c->config->{case_sensitive} ), } ); } else { my $error = - qq/Couldn't forward to "$class". Does not implement "$method"/; + qq/Couldn't forward to "$component_class". Does not implement "$method"/; $c->error($error); $c->log->debug($error) if $c->debug;