From: Marcus Ramberg Date: Wed, 15 Feb 2006 14:30:17 +0000 (+0000) Subject: support hashref for params in uri_for X-Git-Tag: 5.7099_04~705 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=8327e2e21fc9ea72c357e876f868001ad9712474;hp=b248fa4a4191cd3eaa13d72e6ec8e64dfef973e0 support hashref for params in uri_for --- diff --git a/Changes b/Changes index d8264b2..7cc1b0f 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ This file documents the revision history for Perl extension Catalyst. + - Support optional hashref as last param for parameters in uri_for. + 5.64 2006-02-07 20:29:00 - Fixed bug in FastCGI proc manager mode where pm_post_dispatch was not run. (Eric Wong) diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 25b2c7a..d93707f 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -717,12 +717,15 @@ sub uri_for { $namespace = '' if $path =~ /^\//; $path =~ s/^\///; + my $params = (scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {}); + # join args with '/', or a blank string my $args = ( scalar @args ? '/' . join( '/', @args ) : '' ); $args =~ s/^\/// unless $path; my $res = URI->new_abs( URI->new_abs( "$path$args", "$basepath$namespace" ), $base ) ->canonical; + $res->query_form(%$params); $res; } diff --git a/t/unit_core_uri_for.t b/t/unit_core_uri_for.t index c6726f6..f46e2fd 100644 --- a/t/unit_core_uri_for.t +++ b/t/unit_core_uri_for.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 8; use Test::MockObject; use URI; @@ -36,6 +36,12 @@ is( is( Catalyst::uri_for( $context, '../quux' )->as_string, 'http://127.0.0.1/foo/quux', 'URI for relative dot path' ); +is( + Catalyst::uri_for( $context, 'quux', { param1 => 'value1' } )->as_string, + 'http://127.0.0.1/foo/yada/quux?param1=value1', + 'URI for undef action with query params' +); + $request->mock( 'base', sub { URI->new('http://localhost:3000/') } ); $request->mock( 'match', sub { 'orderentry/contract' } ); is(