Name
SPVM::Mojo::Parameters - Parameters
Description
Mojo::Parameters class in SPVM is a container for form parameters used by Mojo::URL, based on RFC 3986 and the HTML Living Standard.
Usage
use Mojo::Parameters;
# Parse
my $params = Mojo::Parameters->new("foo=bar&baz=23");
$params->param("baz");
say $params->to_string;
# Build
my $params = Mojo::Parameters->new({foo => "bar", baz => 23});
$params->pairs_list->push_([i => "♥ mojolicious"]);
say $params->to_string;
Fields
pairs
has pairs : virtual rw string[];
Parsed parameter pairs.
This is a virtual field. The value is got from and stored to "pairs_list".
Examples:
# Remove all parameters
$params->set_pairs(new string[0]);
pairs_list
has pairs_list : rw StringList;
Parsed parameter pairs. Note that this method will normalize the parameters.
Class Methods
static method new : Mojo::Parameters ($params_value : object of string|object[] = undef);
Construct a new Mojo::Parameters object and "parse" parameters if necessary.
Examples:
my $params = Mojo::Parameters->new;
my $params = Mojo::Parameters->new("foo=b%3Bar&baz=23");
my $params = Mojo::Parameters->new({foo => "b&ar"});
my $params = Mojo::Parameters->new({foo => ["ba&r", "baz"]});
my $params = Mojo::Parameters->new({foo => ["bar", "baz"], bar => 23});
Instance Methods
append
method append : void ($pairs : object of object[]|Mojo::Parameters);
Append parameters. Note that this method will normalize the parameters.
Examples:
# "foo=bar&foo=baz"
Mojo::Parameters->new("foo=bar")->append(Mojo::Parameters->new("foo=baz"));
# "foo=bar&foo=baz"
Mojo::Parameters->new("foo=bar")->append({foo => "baz"});
# "foo=bar&foo=baz&foo=yada"
Mojo::Parameters->new("foo=bar")->append({foo => ["baz", "yada"]});
# "foo=bar&foo=baz&foo=yada&bar=23"
Mojo::Parameters->new("foo=bar")->append({foo => ["baz", "yada"], bar => 23});
clone
method clone : Mojo::Parameters ();
Return a new Mojo::Parameters object cloned from these parameters.
every_param
method every_param : string[] ($name : string);
Similar to "param", but returns all values sharing the same name as an array reference. Note that this method will normalize the parameters.
Examples:
# Get first value
say $params->every_param("foo")->[0];
merge
method merge : void ($parameters : object of object[]|Mojo::Parameters);
Merge parameters. Note that this method will normalize the parameters.
# "foo=baz"
Mojo::Parameters->new("foo=bar")->merge(Mojo::Parameters->new("foo=baz"));
# "yada=yada&foo=baz"
Mojo::Parameters->new("foo=bar&yada=yada")->merge({foo => "baz"});
# "yada=yada"
Mojo::Parameters->new("foo=bar&yada=yada")->merge({foo => undef});
names
method names : string[] ();
Return an array reference with all parameter names.
Examples:
# Names of all parameters
for my $name (@{$params->names}) {
say $name;
}
param
method param : string ($name : string);
Get parameter values. If there are multiple values sharing the same name, and you want to access more than just the last one, you can use "every_param". Note that this method will normalize the parameters.
Examples:
my $value = $params->param("foo");
set_param
method set_param : void ($name : string, $value : object of string|string[]);
Set parameter values. If there are multiple values sharing the same name, and you want to access more than just the last one, you can use "every_param". Note that this method will normalize the parameters.
Examples:
$params->set_param(foo => "ba&r");
$params->set_param(foo => ["ba&r", "baz"]);
$params->set_param(foo => ["ba;r", "baz"]);
parse
method parse : void ($params_value : object of string|object[]);
Parse parameters.
remove
method remove : void ($name : string);
Remove parameters. Note that this method will normalize the parameters.
Examples:
# "bar=yada"
Mojo::Parameters->new("foo=bar&foo=baz&bar=yada")->remove("foo");
to_hash
method to_hash : Hash ();
Turn parameters into a hash reference. Note that this method will normalize the parameters.
# "baz"
Mojo::Parameters->new("foo=bar&foo=baz")->to_hash->get("foo")->(string[])->[1];
to_string
method to_string : string ();
Turn parameters into a string.
# "foo=bar&baz=23"
Mojo::Parameters->new->set_pairs([foo => "bar", baz => "23"])->to_string;
See Also
Copyright & License
Copyright (c) 2025 Yuki Kimoto
MIT License