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=d64b17eb4bf237df340391e403f93beca23f8c7d;hp=6fde402842cb778d58ec7beee355c5e9970ff219;hb=cc7af07896de5c87baac6769907537038683ebe7;hpb=e7399d8baa841cb6525daa2c20d88f70ba42474c diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 6fde402..d64b17e 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -15,6 +15,7 @@ use Text::SimpleTable; use Tree::Simple; use Tree::Simple::Visitor::FindByPath; use Class::Load qw(load_class try_load_class); +use Encode 2.21 'decode_utf8'; use namespace::clean -except => 'meta'; @@ -108,6 +109,9 @@ sub dispatch { } else { my $path = $c->req->path; + $path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; + $path = decode_utf8($path); + my $error = $path ? qq/Unknown resource "$path"/ : "No default action defined"; @@ -235,7 +239,7 @@ Documented in L sub forward { my $self = shift; no warnings 'recursion'; - $self->_do_forward(forward => @_); + return $self->_do_forward(forward => @_); } sub _do_forward { @@ -257,6 +261,12 @@ sub _do_forward { no warnings 'recursion'; $action->dispatch( $c ); + #If there is an error, all bets off regarding state. Documentation + #Specifies that when you forward, if there's an error you must expect + #state to be 0. + if( @{ $c->error }) { + $c->state(0); + } return $c->state; } @@ -269,6 +279,7 @@ Documented in L sub detach { my ( $self, $c, $command, @args ) = @_; $self->_do_forward(detach => $c, $command, @args ) if $command; + $c->state(0); # Needed in order to skip any auto functions Catalyst::Exception::Detach->throw; } @@ -385,10 +396,14 @@ sub prepare_action { s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg for grep { defined } @{$req->captures||[]}; - $c->log->debug( 'Path is "' . $req->match . '"' ) - if ( $c->debug && defined $req->match && length $req->match ); + if($c->debug && defined $req->match && length $req->match) { + my $match = $req->match; + $match =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; + $match = decode_utf8($match); + $c->log->debug( 'Path is "' . $match . '"' ) + } - $c->log->debug( 'Arguments are "' . join( '/', @args ) . '"' ) + $c->log->debug( 'Arguments are "' . join( '/', map { decode_utf8 $_ } @args ) . '"' ) if ( $c->debug && @args ); } @@ -606,6 +621,7 @@ sub setup_actions { @{ $self->_registered_dispatch_types }{@classes} = (1) x @classes; foreach my $comp ( values %{ $c->components } ) { + $comp = $comp->() if ref($comp) eq 'CODE'; $comp->register_actions($c) if $comp->can('register_actions'); }