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