From: Brian Cassidy Date: Thu, 2 Aug 2007 14:18:21 +0000 (+0000) Subject: remove warning for undef captures X-Git-Tag: 5.7099_04~176 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=cccc8f68ace5d11c3fdcbfc4e353225b3b574255 remove warning for undef captures --- diff --git a/Changes b/Changes index fd6b5be..29c4083 100644 --- a/Changes +++ b/Changes @@ -1,10 +1,10 @@ This file documents the revision history for Perl extension Catalyst. 5.7008 - - add undef warning for uri_for + - Add undef warning for uri_for - Fix bug where a nested component would be setup twice - Make ensure_class_loaded behave better with malformed class name - - Make _register_plugin use ensure_class_loaded + - Make _register_plugin use ensure_class_loaded - Remove 'Argument "??" isn't numeric in sprintf' warning (Emanuele Zeppieri) - Fixed a bug where Content-Length could be set to 0 if a filehandle @@ -12,6 +12,7 @@ This file documents the revision history for Perl extension Catalyst. - Fixed issue where development server running in fork mode did not properly exit after a write error. (http://rt.cpan.org/Ticket/Display.html?id=27135) + - Remove warning for captures that are undef 5.7007 2007-03-13 14:18:00 - Many performance improvements by not using URI.pm: diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 7f201c2..ca5bc25 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -282,7 +282,7 @@ sub prepare_action { unshift @args, $arg; } - s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg for @{$c->req->captures||[]}; + s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg for grep { defined } @{$c->req->captures||[]}; $c->log->debug( 'Path is "' . $c->req->match . '"' ) if ( $c->debug && $c->req->match ); diff --git a/t/lib/TestApp/Controller/Action/Regexp.pm b/t/lib/TestApp/Controller/Action/Regexp.pm index e454cfd..cdb6abc 100644 --- a/t/lib/TestApp/Controller/Action/Regexp.pm +++ b/t/lib/TestApp/Controller/Action/Regexp.pm @@ -13,4 +13,9 @@ sub two : Action LocalRegexp('^(\d+)/(\w+)$') { $c->forward('TestApp::View::Dump::Request'); } +sub three : Action LocalRegex('^(mandatory)(/optional)?$'){ + my ( $self, $c ) = @_; + $c->forward('TestApp::View::Dump::Request'); +} + 1; diff --git a/t/live_component_controller_action_regexp.t b/t/live_component_controller_action_regexp.t index c502456..559167d 100644 --- a/t/live_component_controller_action_regexp.t +++ b/t/live_component_controller_action_regexp.t @@ -10,7 +10,7 @@ our $iters; BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } -use Test::More tests => 12*$iters; +use Test::More tests => 28*$iters; use Catalyst::Test 'TestApp'; if ( $ENV{CAT_BENCHMARK} ) { @@ -61,4 +61,44 @@ sub run_tests { 'Content is a serialized Catalyst::Request' ); } + + { + ok( my $response = request('http://localhost/action/regexp/mandatory'), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + is( $response->header('X-Catalyst-Action'), + '^action/regexp/(mandatory)(/optional)?$', 'Test Action' ); + is( + $response->header('X-Test-Class'), + 'TestApp::Controller::Action::Regexp', + 'Test Class' + ); + my $content = $response->content; + my $req = eval $content; + + is( scalar @{ $req->captures }, 2, 'number of captures' ); + is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' ); + ok( !defined $req->captures->[ 1 ], 'optional capture' ); + } + + { + ok( my $response = request('http://localhost/action/regexp/mandatory/optional'), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + is( $response->header('X-Catalyst-Action'), + '^action/regexp/(mandatory)(/optional)?$', 'Test Action' ); + is( + $response->header('X-Test-Class'), + 'TestApp::Controller::Action::Regexp', + 'Test Class' + ); + my $content = $response->content; + my $req = eval $content; + + is( scalar @{ $req->captures }, 2, 'number of captures' ); + is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' ); + is( $req->captures->[ 1 ], '/optional', 'optional capture' ); + } }