X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=39eb2897ee93750ce28caed33702dfecb1af1685;hb=e995c634139297d4f211ee2608df03f510a19dc4;hp=68fe551a22e77b2873cb25bff91a5c036e690121;hpb=382d317c39473fe7792a08d071f00883f50ed73b;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 68fe551..39eb289 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -307,40 +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 ) = @_; - 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; - 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; @@ -652,7 +656,14 @@ sub _load_dispatch_types { return @loaded; } -# Dont document this until someone else is happy with beaviour. Ash 2009/03/16 +=head2 $self->dispatch_type( $type ) + +Get the DispatchType object of the relevant type, i.e. passing C<$type> of +C would return a L object (assuming +of course it's being used.) + +=cut + sub dispatch_type { my ($self, $name) = @_;