From: Andy Grundman Date: Fri, 3 Aug 2007 01:53:17 +0000 (+0000) Subject: Added req->query_keywords method X-Git-Tag: 5.7099_04~174 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=3b4d12511c59793e85feca1ac1b4a8c2c5f1a6ae Added req->query_keywords method --- diff --git a/Changes b/Changes index 29c4083..8983f86 100644 --- a/Changes +++ b/Changes @@ -1,18 +1,20 @@ This file documents the revision history for Perl extension Catalyst. 5.7008 - - 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 - - Remove 'Argument "??" isn't numeric in sprintf' warning + - Added $c->request->query_keywords for getting the keywords + (a query string with no parameters). + - 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. + - Remove 'Argument "??" isn't numeric in sprintf' warning. (Emanuele Zeppieri) - Fixed a bug where Content-Length could be set to 0 if a filehandle object in $c->response->body did not report a size. - 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 + - 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/Engine.pm b/lib/Catalyst/Engine.pm index 0c42af6..5902c9c 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -447,8 +447,10 @@ process the query string and extract query parameters. sub prepare_query_parameters { my ( $self, $c, $query_string ) = @_; - # Make sure query has params + # Check for keywords (no = signs) + # (yes, index() is faster than a regex :)) if ( index( $query_string, '=' ) < 0 ) { + $c->request->query_keywords( $self->unescape_uri($query_string) ); return; } diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index 24e39bf..763c3ef 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -9,7 +9,7 @@ use utf8; use URI::QueryParam; __PACKAGE__->mk_accessors( - qw/action address arguments cookies headers match method + qw/action address arguments cookies headers query_keywords match method protocol query_parameters secure captures uri user/ ); @@ -51,6 +51,7 @@ Catalyst::Request - provides information about the current client request $req->headers; $req->hostname; $req->input; + $req->query_keywords; $req->match; $req->method; $req->param; @@ -259,6 +260,15 @@ sub hostname { Alias for $req->body. +=head2 $req->query_keywords + +Contains the keywords portion of a query string, when no '=' signs are +present. + + http://localhost/path?some+keywords + + $c->request->query_keywords will contain 'some keywords' + =head2 $req->match This contains the matching part of a Regex action. Otherwise diff --git a/t/live_engine_request_parameters.t b/t/live_engine_request_parameters.t index b677dc2..851d4c5 100644 --- a/t/live_engine_request_parameters.t +++ b/t/live_engine_request_parameters.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 29; +use Test::More tests => 30; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -103,14 +103,15 @@ use URI; }; my $request = POST( - 'http://localhost/dump/request/a/b?query_string', + 'http://localhost/dump/request/a/b?query+string', 'Content' => $parameters, 'Content-Type' => 'application/x-www-form-urlencoded' ); ok( my $response = request($request), 'Request' ); ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' ); - is( $creq->{uri}->query, 'query_string', 'Catalyst::Request POST query_string' ); + is( $creq->{uri}->query, 'query+string', 'Catalyst::Request POST query_string' ); + is( $creq->query_keywords, 'query string', 'Catalyst::Request query_keywords' ); is_deeply( $creq->{parameters}, $parameters, 'Catalyst::Request parameters' ); ok( $response = request('http://localhost/dump/request/a/b?x=1&y=1&z=1'), 'Request' );