++ed by:
STEPHEN VOEGELAS MPGUTTA MUGIFLY MISHIN

112 PAUSE user(s)
138 non-PAUSE user(s).

Sebastian Riedel

NAME

Mojo::Parameters - Parameters

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);
  say "$params";

DESCRIPTION

Mojo::Parameters is a container for form parameters.

ATTRIBUTES

Mojo::Parameters implements the following attributes.

charset

  my $charset = $params->charset;
  $params     = $params->charset('UTF-8');

Charset used for encoding and decoding parameters, defaults to UTF-8.

  # Disable encoding and decoding
  $params->charset(undef);

pair_separator

  my $separator = $params->pair_separator;
  $params       = $params->pair_separator(';');

Separator for parameter pairs, defaults to &.

METHODS

Mojo::Parameters inherits all methods from Mojo::Base and implements the following new ones.

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', 'b;az']);
  my $params = Mojo::Parameters->new(foo => ['ba;r', 'b;az'], bar => 23);

Construct a new Mojo::Parameters object.

append

  $params = $params->append(foo => 'ba;r');
  $params = $params->append(foo => ['ba;r', 'b;az']);
  $params = $params->append(foo => ['ba;r', 'b;az'], bar => 23);

Append parameters.

  # "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;

Clone parameters.

merge

  $params = $params->merge(Mojo::Parameters->new(foo => 'b;ar', baz => 23));

Merge Mojo::Parameters objects.

param

  my @names = $params->param;
  my $foo   = $params->param('foo');
  my @foo   = $params->param('foo');
  my $foo   = $params->param(foo => 'ba;r');
  my @foo   = $params->param(foo => qw(ba;r ba;z));

Check and replace parameter values.

params

  my $array = $params->params;
  $params   = $params->params([foo => 'b;ar', baz => 23]);

Parsed parameters.

parse

  $params = $params->parse('foo=b%3Bar&baz=23');

Parse parameters.

remove

  $params = $params->remove('foo');

Remove parameters.

  # "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.

  # "baz"
  Mojo::Parameters->new('foo=bar&foo=baz')->to_hash->{foo}[1];

to_string

  my $string = $params->to_string;
  my $string = "$params";

Turn parameters into a string.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.