Added req->query_keywords method
Andy Grundman [Fri, 3 Aug 2007 01:53:17 +0000 (01:53 +0000)]
Changes
lib/Catalyst/Engine.pm
lib/Catalyst/Request.pm
t/live_engine_request_parameters.t

diff --git a/Changes b/Changes
index 29c4083..8983f86 100644 (file)
--- 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:
index 0c42af6..5902c9c 100644 (file)
@@ -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;
     }
 
index 24e39bf..763c3ef 100644 (file)
@@ -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
index b677dc2..851d4c5 100644 (file)
@@ -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' );