-
-
23 Jun 2015 01:12:12 UTC
- Distribution: Mojolicious-Plugin-ParamExpand
- Module version: 0.03
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (0)
- Testers (1000 / 1 / 0)
- Kwalitee
Bus factor: 1- 95.56% Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (3.7KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors- Skye Shaw <skye.shaw AT gmail.com>
- Dependencies
- CGI::Expand
- Mojolicious
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Mojolicious::Plugin::ParamExpand - Use objects and data structures in your forms
SYNOPSIS
# Mojolicious $self->plugin('ParamExpand', %options); # Mojolicious::Lite plugin 'ParamExpand', %options; # In your action sub action { my $self = shift; my $order = $self->param('order'); $order->{address}; $order->{items}->[0]->{id}; $order->{items}->[0]->{price}; # ... }
DESCRIPTION
Mojolicious::Plugin::ParamExpand turns request parameters into nested data structures using CGI::Expand.
MOJOLICIOUS VERSION
Less than 2.52
Due to the old way
Mojolicious::Controller
handled multi-valued request parameters versions prior to 2.52 will not work with this plugin. If this is a problem for you try Mojolicious::Plugin::GroupedParams.Greater than 5.57
"param" in Mojolicious::Controller no longer returns an array. You must call "every_param" in Mojolicious::Controller.
OPTIONS
Options must be specified when loading the plugin.
separator
$self->plugin('ParamExpand', separator => ',')
The character used to separate the data structure's hierarchy in the flattened parameter. Defaults to
'.'
.max_array
$self->plugin('ParamExpand', max_array => 10)
Maximum number of array elements
CGI::Expand
will create. Defaults to100
. If a parameter contains more thanmax_array
elements an exception will be raised.To force the array into a hash keyed by its indexes set this to
0
.Methods
param
This is just "param" in Mojolicious::Controller but, when using
Mojolicious::Plugin::ParamExpand
, a request with the parametersusers.0.name=nameA&users.1.name=nameB&id=123
will return a nested data structure for the param
'users'
@users = $self->param('users'); $users[0]->{name}; $users[1]->{name};
Other parameters can be accessed as usual
$id = $self->param('id');
The flattened parameter name can also be used
$name0 = $self->param('users.0.name');
Arguments
$name
The name of the parameter.
Returns
The value for the given parameter. If applicable it will be an expanded data structure.
Top level arrays will be returned as arrays not as array references. This is how
Mojolicious
behaves. In other wordsusers.0=userA&users.1=userB
is equivlent to
users=userA&users=userB
If this is undesirable you could set
max_array
to zero.SEE ALSO
CGI::Expand, Mojolicious::Plugin::FormFields, Mojolicious::Plugin::GroupedParams
Module Install Instructions
To install Mojolicious::Plugin::ParamExpand, copy and paste the appropriate command in to your terminal.
cpanm Mojolicious::Plugin::ParamExpand
perl -MCPAN -e shell install Mojolicious::Plugin::ParamExpand
For more information on module installation, please visit the detailed CPAN module installation guide.