X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=b65c22ada8258bbc4c1b3f3fb104c72ea646e58a;hb=cd677e12b127597abb93b76560c8cb23a47d5da6;hp=43b473360aa49b3b57b260db1004f3c6fb1c3667;hpb=68a748b9fd30c919139b96ded5339df3be979487;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 43b4733..b65c22a 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -4,7 +4,6 @@ use strict; use base 'Class::Data::Inheritable'; use Memoize; use Text::ASCIITable; -use Text::ASCIITable::Wrap 'wrap'; use Tree::Simple; use Tree::Simple::Visitor::FindByPath; @@ -61,14 +60,17 @@ sub dispatch { } # Execute the auto chain + my $auto = 0; for my $auto ( @{ $c->get_action( 'auto', $namespace ) } ) { $c->execute( @{ $auto->[0] } ); return if scalar @{ $c->error }; last unless $c->state; + $auto++; } # Execute the action or last default - if ( ( my $action = $c->req->action ) && $c->state ) { + my $mkay = $auto ? $c->state ? 1 : 0 : 1; + if ( ( my $action = $c->req->action ) && $mkay ) { if ( my $result = @{ $c->get_action( $action, $default ) }[-1] ) { $c->execute( @{ $result->[0] } ); } @@ -114,14 +116,17 @@ sub forward { if ( $command =~ /^\// ) { $command =~ /^(.*)\/(\w+)$/; $namespace = $1 || '/'; + $namespace = s/^\/// if $namespace ne '/'; $command = $2; } else { $namespace = _class2prefix($caller) || '/' } my $results = $c->get_action( $command, $namespace ); unless ( @{$results} ) { - my $class = $command; + my $class = $command || ''; if ( $class =~ /[^\w\:]/ ) { - $c->log->debug(qq/Couldn't forward to "$class"/) if $c->debug; + my $error = qq/Couldn't forward to "$class"/; + $c->error($error); + $c->log->debug($error) if $c->debug; return 0; } my $method = shift || 'process'; @@ -130,7 +135,9 @@ sub forward { $results = [ [ [ $class, $code ] ] ]; } else { - $c->log->debug(qq/Couldn't forward to "$class->$method"/) + my $error = qq/Couldn't forward to "$class"/; + $c->error($error); + $c->log->debug($error) if $c->debug; return 0; } @@ -231,6 +238,13 @@ sub set_action { elsif ( $attr =~ /^(Regex|Regexp)\((.+)\)$/i ) { $flags{regex} = $2 } } + if ( $flags{private} && ( keys %flags > 1 ) ) { + $c->log->debug( 'Bad action definition "' + . join( ' ', @{$attrs} ) + . qq/" for "$namespace->$method"/ ) + if $c->debug; + return; + } return unless keys %flags; my $parent = $c->tree; @@ -320,18 +334,11 @@ sub setup_actions { } } } - my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } ); - $t->setCols('Class'); - $t->setColWidth( 'Class', 75, 1 ); - $t->addRow( wrap( $_, 75 ) ) for keys %{ $self->components }; - $self->log->debug( 'Loaded components', $t->draw ) - if ( @{ $t->{tbl_rows} } && $self->debug ); my $actions = $self->actions; my $privates = Text::ASCIITable->new; - $privates->setCols( 'Private', 'Class', 'Code' ); - $privates->setColWidth( 'Private', 28, 1 ); - $privates->setColWidth( 'Class', 28, 1 ); - $privates->setColWidth( 'Code', 14, 1 ); + $privates->setCols( 'Private', 'Class' ); + $privates->setColWidth( 'Private', 36, 1 ); + $privates->setColWidth( 'Class', 37, 1 ); my $walker = sub { my ( $walker, $parent, $prefix ) = @_; $prefix .= $parent->getNodeValue || ''; @@ -339,11 +346,7 @@ sub setup_actions { my $uid = $parent->getUID; for my $action ( keys %{ $actions->{private}->{$uid} } ) { my ( $class, $code ) = @{ $actions->{private}->{$uid}->{$action} }; - $privates->addRow( - wrap( "$prefix$action", 28 ), - wrap( $class, 28 ), - wrap( $code, 14 ) - ); + $privates->addRow( "$prefix$action", $class, 37 ); } $walker->( $walker, $_, $prefix ) for $parent->getAllChildren; }; @@ -352,23 +355,25 @@ sub setup_actions { if ( @{ $privates->{tbl_rows} } && $self->debug ); my $publics = Text::ASCIITable->new; $publics->setCols( 'Public', 'Private' ); - $publics->setColWidth( 'Public', 37, 1 ); - $publics->setColWidth( 'Private', 36, 1 ); + $publics->setColWidth( 'Public', 36, 1 ); + $publics->setColWidth( 'Private', 37, 1 ); for my $plain ( sort keys %{ $actions->{plain} } ) { my ( $class, $code ) = @{ $actions->{plain}->{$plain} }; - $publics->addRow( wrap( "/$plain", 37 ), - wrap( $self->actions->{reverse}->{$code} || $code, 36 ) ); + my $reverse = $self->actions->{reverse}->{$code}; + $reverse = $reverse ? "/$reverse" : $code; + $publics->addRow( "/$plain", $reverse ); } $self->log->debug( 'Loaded public actions', $publics->draw ) if ( @{ $publics->{tbl_rows} } && $self->debug ); my $regexes = Text::ASCIITable->new; $regexes->setCols( 'Regex', 'Private' ); - $regexes->setColWidth( 'Regex', 37, 1 ); - $regexes->setColWidth( 'Private', 36, 1 ); + $regexes->setColWidth( 'Regex', 36, 1 ); + $regexes->setColWidth( 'Private', 37, 1 ); for my $regex ( sort keys %{ $actions->{regex} } ) { my ( $class, $code ) = @{ $actions->{regex}->{$regex} }; - $regexes->addRow( wrap( $regex, 37 ), - wrap( $self->actions->{reverse}->{$class} || $class, 36 ) ); + my $reverse = $self->actions->{reverse}->{$code}; + $reverse = $reverse ? "/$reverse" : $code; + $regexes->addRow( $regex, $reverse ); } $self->log->debug( 'Loaded regex actions', $regexes->draw ) if ( @{ $regexes->{tbl_rows} } && $self->debug );