X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=32ccd67d6e191e2ee679a2965126d1ae444ad4b2;hb=47ce945eb2137ee3851d44eff2e5b640157867c8;hp=01f4bedf1ed9a5a245f6c7a4dbd80acf2e00d4c2;hpb=99fe1710ff4af72d62979c1b64092c0777660a4d;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 01f4bed..32ccd67 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -2,7 +2,7 @@ package Catalyst::Dispatcher; use strict; use base 'Class::Data::Inheritable'; -use Memoize; +use Catalyst::Utils; use Text::ASCIITable; use Tree::Simple; use Tree::Simple::Visitor::FindByPath; @@ -17,11 +17,9 @@ __PACKAGE__->actions( # We use a tree __PACKAGE__->tree( Tree::Simple->new( 0, Tree::Simple->ROOT ) ); -memoize('_class2prefix'); - =head1 NAME -Catalyst::Dispatch - The Catalyst Dispatcher +Catalyst::Dispatcher - The Catalyst Dispatcher =head1 SYNOPSIS @@ -48,7 +46,8 @@ sub dispatch { unless ($namespace) { if ( my $result = $c->get_action($action) ) { - $namespace = _class2prefix( $result->[0]->[0]->[0] ); + $namespace = + Catalyst::Utils::class2prefix( $result->[0]->[0]->[0] ); } } @@ -128,18 +127,19 @@ sub forward { $namespace = $1 || '/'; $command = $2 || $command; $command =~ s/^\///; - warn "NAMESPACE: $namespace COMMAND: $command"; } - else { $namespace = _class2prefix($caller) || '/' } + else { $namespace = Catalyst::Utils::class2prefix($caller) || '/' } my $results = $c->get_action( $command, $namespace ); unless ( @{$results} ) { my $class = $command || ''; + my $path = $class . '.pm'; + $path =~ s/::/\//g; - if ( $class =~ /[^\w\:]/ ) { - my $error = qq/Couldn't forward to "$class"/; + unless ( $INC{ $path } ) { + my $error = qq/Couldn't forward to "$class". Invalid or not loaded./; $c->error($error); $c->log->debug($error) if $c->debug; return 0; @@ -153,7 +153,7 @@ sub forward { } else { - my $error = qq/Couldn't forward to "$class"/; + my $error = qq/Couldn't forward to "$class". Does not implement "$method"/; $c->error($error); $c->log->debug($error) if $c->debug; @@ -237,13 +237,7 @@ sub get_action { my $name = $c->actions->{compiled}->[$i]->[0]; my $regex = $c->actions->{compiled}->[$i]->[1]; - if ( $action =~ $regex ) { - my @snippets; - for my $i ( 1 .. 9 ) { - no strict 'refs'; - last unless ${$i}; - push @snippets, ${$i}; - } + if ( my @snippets = ( $action =~ $regex ) ) { return [ [ $c->actions->{regex}->{$name}, $name, \@snippets ] ]; } @@ -261,7 +255,7 @@ Set an action in a given namespace. sub set_action { my ( $c, $method, $code, $namespace, $attrs ) = @_; - my $prefix = _class2prefix($namespace) || ''; + my $prefix = Catalyst::Utils::class2prefix($namespace) || ''; my %flags; for my $attr ( @{$attrs} ) { @@ -443,23 +437,6 @@ sub setup_actions { if ( @{ $regexes->{tbl_rows} } && $self->debug ); } -sub _prefix { - my ( $class, $name ) = @_; - my $prefix = _class2prefix($class); - $name = "$prefix/$name" if $prefix; - return $name; -} - -sub _class2prefix { - my $class = shift || ''; - my $prefix; - if ( $class =~ /^.*::([MVC]|Model|View|Controller)?::(.*)$/ ) { - $prefix = lc $2; - $prefix =~ s/\:\:/\//g; - } - return $prefix; -} - =back =head1 AUTHOR