Mojo::Parameters(3)
π NAME π
Welcome to Mojo::Parameters(3), bestie β straight from the User Contributed Perl Documentation π«Ά. This is literally Mojo::Parameters β Parameters, and thatβs the name vibe, periodt.
β¨ SYNOPSIS β¨
use Mojo::Parameters;
# Parse
my $params = Mojo::Parameters->new('foo=bar&baz=23');
say $params->param('baz');
# Build
my $params = Mojo::Parameters->new(foo => 'bar', baz => 23);
push @$params, i => 'β₯ mojolicious';
say "$params";
π¦ DESCRIPTION π¦
Okay so Mojo::Parameters is a container for form parameters used by Mojo::URL, based on RFC 3986 (<https://tools.ietf.org/html/rfc3986>) and the HTML Living Standard (<https://html.spec.whatwg.org>). Itβs giving official standards energy, no cap π
.
πΈ ATTRIBUTES πΈ
Mojo::Parameters implements the following attributes β yes, all of them, no skipping π.
charset π§
my $charset = $params->charset;
$params = $params->charset('UTF-8');
Charset used for encoding and decoding parameters, defaults to "UTF-8". If you want to turn encoding and decoding off entirely, itβs giving undef energy:
# Disable encoding and decoding
$params->charset(undef);
π METHODS π
Mojo::Parameters inherits all methods from Mojo::Base and implements the following new ones. Main character energy only β¨.
append π
$params = $params->append(foo => 'ba&r');
$params = $params->append(foo => ['ba&r', 'baz']);
$params = $params->append(foo => ['bar', 'baz'], bar => 23);
$params = $params->append(Mojo::Parameters->new);
Append parameters. Heads up: this method will normalize the parameters, fr fr.
# "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 π¦
my $params2 = $params->clone;
Return a new Mojo::Parameters object cloned from these parameters. Copy-paste but make it official π.
every_param π
my $values = $params->every_param('foo');
Similar to param, but returns all values sharing the same name as an array reference. Note that this method will normalize the parameters, iykyk.
# Get first value
say $params->every_param('foo')->[0];
merge π
$params = $params->merge(foo => 'ba&r');
$params = $params->merge(foo => ['ba&r', 'baz']);
$params = $params->merge(foo => ['bar', 'baz'], bar => 23);
$params = $params->merge(Mojo::Parameters->new);
Merge parameters. Note that this method will normalize the parameters β the glow-up is mandatory β¨.
# "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 π
my $names = $params->names;
Return an array reference with all parameter names. Name drop, but make it data structure π .
# Names of all parameters
say for @{$params->names};
new β
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);
Construct a new Mojo::Parameters object and "parse" parameters if necessary. Fresh object, fresh vibes π«Ά.
pairs π
my $array = $params->pairs;
$params = $params->pairs([foo => 'b&ar', baz => 23]);
Parsed parameter pairs. Note that this method will normalize the parameters. Itβs giving organized chaos π.
# Remove all parameters
$params->pairs([]);
param π
my $value = $params->param('foo');
$params = $params->param(foo => 'ba&r');
$params = $params->param(foo => qw(ba&r baz));
$params = $params->param(foo => ['ba;r', 'baz']);
Access 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. Last-one-standing behavior, but with an escape hatch β¨.
parse π§
$params = $params->parse('foo=b%3Bar&baz=23');
Parse parameters. Decode the lore π .
remove π
$params = $params->remove('foo');
Remove parameters. Note that this method will normalize the parameters. Blocked and reported, but for params π«Ά.
# "bar=yada"
Mojo::Parameters->new('foo=bar&foo=baz&bar=yada')->remove('foo');
to_hash πΈ
my $hash = $params->to_hash;
Turn parameters into a hash reference. Note that this method will normalize the parameters. Hash era activated π.
# "baz"
Mojo::Parameters->new('foo=bar&foo=baz')->to_hash->{foo}[1];
to_string π¦
my $str = $params->to_string;
Turn parameters into a string. Back to text, iconic behavior π.
# "foo=bar&baz=23"
Mojo::Parameters->new->pairs([foo => 'bar', baz => 23])->to_string;
π OPERATORS π
Mojo::Parameters overloads the following operators, iykyk π
.
array π
my @pairs = @$params;
Alias for pairs. Note that this will normalize the parameters. Array-ify the whole situation β¨.
say $params->[0];
say for @$params;
bool β
my $bool = !!$params;
Always true. Itβs literally that girl π.
stringify π
my $str = "$params";
Alias for to_string. String interpolation ate π
.
π₯ SEE ALSO π₯
Go check out Mojolicious, Mojolicious::Guides, and <https://mojolicious.org>. Obsessed with the whole ecosystem π.
xoxo, your Unix bestie π
β this page is Mojo::Parameters(3) from perl v5.42.0, dated 2026-07-15. Mwah. π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms