X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=ab305eca9ddc4c7d105cb1dce88a855a904fcbfa;hb=5d2c7203d35650cf3dc99a7b6d6e6659ebc7d559;hp=cf05df1fdd0d11fee3d94e0c141d528930918cb1;hpb=af82dbf734add9f595ac01361c1b529aa5c981c0;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index cf05df1..ab305ec 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] ); } } @@ -130,7 +129,7 @@ sub forward { $command =~ s/^\///; } - else { $namespace = _class2prefix($caller) || '/' } + else { $namespace = Catalyst::Utils::class2prefix($caller) || '/' } my $results = $c->get_action( $command, $namespace ); @@ -138,7 +137,7 @@ sub forward { my $class = $command || ''; if ( $class =~ /[^\w\:]/ ) { - my $error = qq/Couldn't forward to "$class"/; + my $error = qq/"$class" is an invalid Class name/; $c->error($error); $c->log->debug($error) if $c->debug; return 0; @@ -152,7 +151,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; @@ -236,13 +235,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 ] ]; } @@ -260,7 +253,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} ) { @@ -442,23 +435,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