Skip to content

Instantly share code, notes, and snippets.

@marcusramberg
Created June 27, 2012 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusramberg/3002192 to your computer and use it in GitHub Desktop.
Save marcusramberg/3002192 to your computer and use it in GitHub Desktop.
$req->param
Returns GET and POST parameters with a CGI.pm-compatible param method.
This is an alternative method for accessing parameters in
$c->req->parameters.
$value = $c->request->param( 'foo' );
@values = $c->request->param( 'foo' );
@params = $c->request->param;
Like CGI, and unlike earlier versions of Catalyst, passing multiple
arguments to this method, like this:
$c->request->param( 'foo', 'bar', 'gorch', 'quxx' );
will set the parameter "foo" to the multiple values "bar", "gorch" and
"quxx". Previously this would have added "bar" as another value to
"foo" (creating it if it didn't exist before), and "quxx" as another
value for "gorch".
NOTE this is considered a legacy interface and care should be taken
when using it. "scalar $c->req->param( 'foo' )" will return only the
first "foo" param even if multiple are present; "$c->req->param( 'foo'
)" will return a list of as many are present, which can have unexpected
consequences when writing code of the form:
$foo->bar(
a => 'b',
baz => $c->req->param( 'baz' ),
);
If multiple "baz" parameters are provided this code might corrupt data
or cause a hash initialization error. For a more straightforward
interface see "$c->req->parameters".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment