This file documents the revision history for Perl extension Catalyst.
5.67
+ - Added $c->req->uri_with() helper
- ConfigLoader: Updated to version 0.05
- Fix up Engine to avoid a new 5.8.8 warning
- Added app name with :: support for PAR
use base 'Class::Accessor::Fast';
use IO::Socket qw[AF_INET inet_aton];
+use Carp;
__PACKAGE__->mk_accessors(
qw/action address arguments cookies headers match method
Returns a URI object for the current request. Stringifies to the URI text.
+=head2 $req->uri_with( { key => 'value' } );
+
+Returns a rewriten URI object for the current uri. Key/value pairs passed in
+will override existing parameters. Unmodified pairs will be preserved.
+
+=cut
+
+sub uri_with {
+ my( $self, $args ) = @_;
+
+ carp( 'No arguments passed to uri_with()' ) unless $args;
+
+ my $uri = $self->uri->clone;
+
+ $uri->query_form( {
+ $uri->query_form,
+ %$args
+ } );
+ return $uri;
+}
+
=head2 $req->user
Returns the currently logged in user. Deprecated. The method recommended for
$c->forward('TestApp::View::Dump::Request');\r
}\r
\r
+sub uri_with : Local {\r
+ my ( $self, $c ) = @_;\r
+\r
+ # change the current uri\r
+ my $uri = $c->req->uri_with( { b => 1 } );\r
+ my %query = $uri->query_form;\r
+ \r
+ $c->res->header( 'X-Catalyst-Param-a' => $query{ a } );\r
+ $c->res->header( 'X-Catalyst-Param-b' => $query{ b } );\r
+ \r
+ $c->forward('TestApp::View::Dump::Request');\r
+}\r
+\r
1;\r
use FindBin;\r
use lib "$FindBin::Bin/lib";\r
\r
-use Test::More tests => 23;\r
+use Test::More tests => 35;\r
use Catalyst::Test 'TestApp';\r
use Catalyst::Request;\r
\r
is( $creq->{uri}->query, 'text=Catalyst%20Rocks', 'Query string ok' );\r
is( $creq->{parameters}->{text}, 'Catalyst Rocks', 'Unescaped param ok' );\r
}\r
+\r
+# test that uri_with adds params\r
+{\r
+ ok( my $response = request('http://localhost/engine/request/uri/uri_with'), 'Request' );\r
+ ok( $response->is_success, 'Response Successful 2xx' );\r
+ ok( !defined $response->header( 'X-Catalyst-Param-a' ), 'param "a" ok' );\r
+ is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );\r
+}\r
+\r
+# test that uri_with adds params (and preserves)\r
+{\r
+ ok( my $response = request('http://localhost/engine/request/uri/uri_with?a=1'), 'Request' );\r
+ ok( $response->is_success, 'Response Successful 2xx' );\r
+ is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );\r
+ is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );\r
+}\r
+\r
+# test that uri_with replaces params (and preserves)\r
+{\r
+ ok( my $response = request('http://localhost/engine/request/uri/uri_with?a=1&b=2'), 'Request' );\r
+ ok( $response->is_success, 'Response Successful 2xx' );\r
+ is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );\r
+ is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );\r
+}\r