[Catalyst-commits] r7999 - in Catalyst-Runtime/5.70/branches/compres: . lib/Catalyst lib/Catalyst/Request t t/lib/TestApp/Controller t/lib/TestApp/Controller/Engine/Request

marcus at dev.catalyst.perl.org marcus at dev.catalyst.perl.org
Wed Jun 25 20:06:44 BST 2008


Author: marcus
Date: 2008-06-25 20:06:44 +0100 (Wed, 25 Jun 2008)
New Revision: 7999

Modified:
   Catalyst-Runtime/5.70/branches/compres/
   Catalyst-Runtime/5.70/branches/compres/Changes
   Catalyst-Runtime/5.70/branches/compres/Makefile.PL
   Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Controller.pm
   Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Engine.pm
   Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Request.pm
   Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Request/Upload.pm
   Catalyst-Runtime/5.70/branches/compres/t/lib/TestApp/Controller/Engine/Request/URI.pm
   Catalyst-Runtime/5.70/branches/compres/t/lib/TestApp/Controller/Root.pm
   Catalyst-Runtime/5.70/branches/compres/t/live_component_controller_action_regexp.t
   Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_parameters.t
   Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_uploads.t
   Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_uri.t
Log:
 r20038 at Command-Central (orig r7857):  bricas | 2008-05-29 15:01:03 +0200
 Added the ability to remove parameters in req->uri_with() by passing in an undef value (RT #34782)
 r21359 at Command-Central (orig r7936):  bricas | 2008-06-20 20:14:11 +0200
 remove a confusing and duplicate bit of documentation
 r21361 at Command-Central (orig r7938):  bricas | 2008-06-23 15:38:24 +0200
 Fix for LocalRegex when used in the Root controller
 r21418 at Command-Central (orig r7995):  bricas | 2008-06-24 00:01:06 +0200
 Update HTTP::Body dep so that the uploadtmp config value will work (RT #22540)
 r21419 at Command-Central (orig r7996):  bricas | 2008-06-24 02:14:21 +0200
 remove 0-length query string components so warnings aren't thrown (RT #36428)



Property changes on: Catalyst-Runtime/5.70/branches/compres
___________________________________________________________________
Name: svk:merge
   - 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442
   + 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:7996
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst:4483
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442

Modified: Catalyst-Runtime/5.70/branches/compres/Changes
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/Changes	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/Changes	2008-06-25 19:06:44 UTC (rev 7999)
@@ -9,8 +9,13 @@
           2) you call a component resolution method with a string, and it resorts to a regexp 
              fallback wherein a result is returned -- if you really want to search, call the
              method with a regex as the argument
+        - remove 0-length query string components so warnings aren't thrown (RT #36428)
+        - Update HTTP::Body dep so that the uploadtmp config value will work (RT #22540)
+        - Fix for LocalRegex when used in the Root controller
         - Get some of the optional_* tests working from dirs with spaces (RT #26455)
         - Fix Catalyst::Utils::home() when application .pm is in the current dir (RT #34437)
+        - Added the ability to remove parameters in req->uri_with() by passing in
+          an undef value (RT #34782)
 
 5.7014  2008-05-25 15:26:00
         - Addition of .conf in restart regex in Catalyst::Engine::HTTP::Restarter::Watcher

Modified: Catalyst-Runtime/5.70/branches/compres/Makefile.PL
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/Makefile.PL	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/Makefile.PL	2008-06-25 19:06:44 UTC (rev 7999)
@@ -13,7 +13,7 @@
 requires 'Data::Dump';
 requires 'File::Modified';
 requires 'HTML::Entities';
-requires 'HTTP::Body'    => '0.9';
+requires 'HTTP::Body'    => '1.04'; # makes uploadtmp work
 requires 'HTTP::Headers' => '1.64';
 requires 'HTTP::Request';
 requires 'HTTP::Response';

Modified: Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Controller.pm
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Controller.pm	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Controller.pm	2008-06-25 19:06:44 UTC (rev 7999)
@@ -270,7 +270,11 @@
 sub _parse_LocalRegex_attr {
     my ( $self, $c, $name, $value ) = @_;
     unless ( $value =~ s/^\^// ) { $value = "(?:.*?)$value"; }
-    return ( 'Regex', '^' . $self->path_prefix($c) . "/${value}" );
+
+    my $prefix = $self->path_prefix( $c );
+    $prefix .= '/' if length( $prefix );
+   
+    return ( 'Regex', "^${prefix}${value}" );
 }
 
 sub _parse_LocalRegexp_attr { shift->_parse_LocalRegex_attr(@_); }

Modified: Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Engine.pm
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Engine.pm	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Engine.pm	2008-06-25 19:06:44 UTC (rev 7999)
@@ -314,7 +314,7 @@
         unless ( $c->request->{_body} ) {
             my $type = $c->request->header('Content-Type');
             $c->request->{_body} = HTTP::Body->new( $type, $length );
-            $c->request->{_body}->{tmpdir} = $c->config->{uploadtmp}
+            $c->request->{_body}->tmpdir( $c->config->{uploadtmp} )
               if exists $c->config->{uploadtmp};
         }
         
@@ -452,7 +452,7 @@
     # replace semi-colons
     $query_string =~ s/;/&/g;
     
-    my @params = split /&/, $query_string;
+    my @params = grep { length $_ } split /&/, $query_string;
 
     for my $item ( @params ) {
         

Modified: Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Request/Upload.pm
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Request/Upload.pm	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Request/Upload.pm	2008-06-25 19:06:44 UTC (rev 7999)
@@ -34,11 +34,6 @@
 
     __PACKAGE__->config( uploadtmp => '/path/to/tmpdir' );
 
-It is provided a way to have configurable temporary directory.
-If there is no config uploadtmp, system temprary directory will used.
-
-    __PACKAGE__->config( uploadtmp => '/path/to/tmpdir' );
-
 See also L<Catalyst>.
 
 =head1 DESCRIPTION

Modified: Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Request.pm
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Request.pm	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/lib/Catalyst/Request.pm	2008-06-25 19:06:44 UTC (rev 7999)
@@ -525,7 +525,8 @@
 =head2 $req->uri_with( { key => 'value' } );
 
 Returns a rewritten URI object for the current request. Key/value pairs
-passed in will override existing parameters. Unmodified pairs will be
+passed in will override existing parameters. You can remove an existing
+parameter by passing in an undef value. Unmodified pairs will be
 preserved.
 
 =cut
@@ -535,7 +536,7 @@
     
     carp( 'No arguments passed to uri_with()' ) unless $args;
 
-    for my $value ( values %$args ) {
+    foreach my $value ( values %$args ) {
         next unless defined $value;
         for ( ref $value eq 'ARRAY' ? @$value : $value ) {
             $_ = "$_";
@@ -543,11 +544,12 @@
         }
     };
     
-    my $uri = $self->uri->clone;
-    
+    my $uri   = $self->uri->clone;
+    my %query = ( %{ $uri->query_form_hash }, %$args );
+
     $uri->query_form( {
-        %{ $uri->query_form_hash },
-        %$args
+        # remove undef values
+        map { defined $query{ $_ } ? ( $_ => $query{ $_ } ) : () } keys %query
     } );
     return $uri;
 }

Modified: Catalyst-Runtime/5.70/branches/compres/t/lib/TestApp/Controller/Engine/Request/URI.pm
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/t/lib/TestApp/Controller/Engine/Request/URI.pm	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/t/lib/TestApp/Controller/Engine/Request/URI.pm	2008-06-25 19:06:44 UTC (rev 7999)
@@ -77,4 +77,26 @@
     $c->forward('TestApp::View::Dump::Request');
 }
 
+sub uri_with_undef_only : Local {
+    my ( $self, $c ) = @_;
+
+    my $uri = $c->req->uri_with( { a => undef } );
+    
+    $c->res->header( 'X-Catalyst-uri-with' => "$uri" );
+    $c->forward('TestApp::View::Dump::Request');
+}
+
+sub uri_with_undef_ignore : Local {
+    my ( $self, $c ) = @_;
+
+    my $uri = $c->req->uri_with( { a => 1, b => undef } );
+    
+    my %query = $uri->query_form;
+    $c->res->header( 'X-Catalyst-uri-with' => "$uri" );
+    $c->res->header( 'X-Catalyst-Param-a' => $query{ a } );
+    $c->res->header( 'X-Catalyst-Param-b' => $query{ b } );
+    $c->res->header( 'X-Catalyst-Param-c' => $query{ c } );
+    $c->forward('TestApp::View::Dump::Request');
+}
+
 1;

Modified: Catalyst-Runtime/5.70/branches/compres/t/lib/TestApp/Controller/Root.pm
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/t/lib/TestApp/Controller/Root.pm	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/t/lib/TestApp/Controller/Root.pm	2008-06-25 19:06:44 UTC (rev 7999)
@@ -13,4 +13,11 @@
     $c->forward('TestApp::View::Dump::Request');
 }
 
+sub localregex : LocalRegex('^localregex$') {
+    my ( $self, $c ) = @_;
+    $c->res->header( 'X-Test-Class' => ref($self) );
+    $c->response->content_type('text/plain; charset=utf-8');
+    $c->forward('TestApp::View::Dump::Request');
+}
+
 1;

Modified: Catalyst-Runtime/5.70/branches/compres/t/live_component_controller_action_regexp.t
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/t/live_component_controller_action_regexp.t	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/t/live_component_controller_action_regexp.t	2008-06-25 19:06:44 UTC (rev 7999)
@@ -10,7 +10,7 @@
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
-use Test::More tests => 28*$iters;
+use Test::More tests => 33*$iters;
 use Catalyst::Test 'TestApp';
 
 use Catalyst::Request;
@@ -103,4 +103,19 @@
         is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' );
         is( $req->captures->[ 1 ], '/optional', 'optional capture' );
     }
+
+    # test localregex in the root controller
+    {
+        ok( my $response = request('http://localhost/localregex'),
+            'Request' );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is( $response->header('X-Catalyst-Action'),
+            '^localregex$', 'Test Action' );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Root',
+            'Test Class'
+        );
+    }
 }

Modified: Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_parameters.t
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_parameters.t	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_parameters.t	2008-06-25 19:06:44 UTC (rev 7999)
@@ -6,7 +6,7 @@
 use FindBin;
 use lib "$FindBin::Bin/lib";
 
-use Test::More tests => 40;
+use Test::More tests => 53;
 use Catalyst::Test 'TestApp';
 
 use Catalyst::Request;
@@ -137,3 +137,26 @@
     ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
     is( $creq->{uri}->query, 'x=1&y=1&z=1', 'Catalyst::Request GET query_string' );
 }
+
+{
+    my $creq;
+    ok( my $response = request("http://localhost/dump/request?&&q="),
+        'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->content_type, 'text/plain', 'Response Content-Type' );
+    ok( eval '$creq = ' . $response->content );
+    is( keys %{$creq->{parameters}}, 1, 'remove empty parameter' );
+    is( $creq->{parameters}->{q}, '', 'empty parameter' );
+}
+
+{
+    my $creq;
+    ok( my $response = request("http://localhost/dump/request?&0&q="),
+        'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->content_type, 'text/plain', 'Response Content-Type' );
+    ok( eval '$creq = ' . $response->content );
+    is( keys %{$creq->{parameters}}, 2, 'remove empty parameter' );
+    is( $creq->{parameters}->{q}, '', 'empty parameter' );
+    ok( !defined $creq->{parameters}->{0}, 'empty parameter' );
+}

Modified: Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_uploads.t
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_uploads.t	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_uploads.t	2008-06-25 19:06:44 UTC (rev 7999)
@@ -6,7 +6,7 @@
 use FindBin;
 use lib "$FindBin::Bin/lib";
 
-use Test::More tests => 75;
+use Test::More tests => 88;
 use Catalyst::Test 'TestApp';
 
 use Catalyst::Request;
@@ -242,3 +242,62 @@
         is( $upload->filename, 'catalyst_130pix.gif' );
     }
 }
+
+# test uploadtmp config var
+
+{
+    my $creq;
+
+    my $dir = "$FindBin::Bin/";
+    local TestApp->config->{ uploadtmp } = $dir;
+
+    my $request = POST(
+        'http://localhost/dump/request/',
+        'Content-Type' => 'multipart/form-data',
+        'Content'      => [
+            'testfile' => ["$FindBin::Bin/live_engine_request_uploads.t"],
+        ]
+    );
+
+    ok( my $response = request($request), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->content_type, 'text/plain', 'Response Content-Type' );
+    like(
+        $response->content,
+        qr/^bless\( .* 'Catalyst::Request' \)$/s,
+        'Content is a serialized Catalyst::Request'
+    );
+
+    {
+        no strict 'refs';
+        ok(
+            eval '$creq = ' . $response->content,
+            'Unserialize Catalyst::Request'
+        );
+    }
+
+    isa_ok( $creq, 'Catalyst::Request' );
+    is( $creq->method, 'POST', 'Catalyst::Request method' );
+    is( $creq->content_type, 'multipart/form-data',
+        'Catalyst::Request Content-Type' );
+    is( $creq->content_length, $request->content_length,
+        'Catalyst::Request Content-Length' );
+
+    for my $part ( $request->parts ) {
+
+        my $disposition = $part->header('Content-Disposition');
+        my %parameters  = @{ ( split_header_words($disposition) )[0] };
+
+        next unless exists $parameters{filename};
+
+        my $upload = $creq->{uploads}->{ $parameters{name} };
+
+        isa_ok( $upload, 'Catalyst::Request::Upload' );
+
+        is( $upload->type, $part->content_type, 'Upload Content-Type' );
+        is( $upload->size, length( $part->content ), 'Upload Content-Length' );
+
+        like( $upload->tempname, qr{\Q$dir\E}, 'uploadtmp' );
+    }
+}
+

Modified: Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_uri.t
===================================================================
--- Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_uri.t	2008-06-25 16:25:12 UTC (rev 7998)
+++ Catalyst-Runtime/5.70/branches/compres/t/live_engine_request_uri.t	2008-06-25 19:06:44 UTC (rev 7999)
@@ -1,12 +1,10 @@
-#!perl
-
 use strict;
 use warnings;
 
 use FindBin;
 use lib "$FindBin::Bin/lib";
 
-use Test::More tests => 49;
+use Test::More tests => 66;
 use Catalyst::Test 'TestApp';
 use Catalyst::Request;
 
@@ -120,3 +118,36 @@
     is( $response->header( 'X-Catalyst-warnings' ), 0, 'no warnings emitted' );
 }
 
+# more tests with undef - should be ignored
+{
+    my $uri = "http://localhost/engine/request/uri/uri_with_undef_only";
+    ok( my $response = request($uri), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->header( 'X-Catalyst-uri-with' ), $uri, 'uri_with ok' );
+
+    # try with existing param
+    $uri = "$uri?x=1";
+    ok( $response = request($uri), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->header( 'X-Catalyst-uri-with' ), $uri, 'uri_with ok' );
+}
+
+{
+    my $uri = "http://localhost/engine/request/uri/uri_with_undef_ignore";
+    ok( my $response = request($uri), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->header( 'X-Catalyst-uri-with' ), "${uri}?a=1", 'uri_with ok' );
+
+    # remove an existing param
+    ok( $response = request("${uri}?b=1"), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->header( 'X-Catalyst-uri-with' ), "${uri}?a=1", 'uri_with ok' );
+
+    # remove an existing param, leave one, and add a new one
+    ok( $response = request("${uri}?b=1&c=1"), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );
+    ok( !defined $response->header( 'X-Catalyst-Param-b' ),'param "b" ok' );
+    is( $response->header( 'X-Catalyst-Param-c' ), '1', 'param "c" ok' );
+}
+




More information about the Catalyst-commits mailing list