Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 106 lines (64 sloc) 2.44 kB
edb44bf added test cases, docs
sshaw authored
1 =pod
2
f5fea07 initial commit... need to fix/add tests
sshaw authored
3 =head1 NAME
4
f52f695 fix README
sshaw authored
5 Mojolicious::Plugin::ParamExpand - Use objects and data structures in your forms
f5fea07 initial commit... need to fix/add tests
sshaw authored
6
7 =head1 SYNOPSIS
8
9 # Mojolicious
10 $self->plugin('ParamExpand', %options);
11
12 # Mojolicious::Lite
13 plugin 'ParamExpand', %options;
14
15 # In your action
16 sub action
17 {
18 my $self = shift;
19 my $order = $self->param('order');
20 $order->{address};
21 $order->{items}->[0]->{id};
485fa5f v0.01 prep
sshaw authored
22 $order->{items}->[0]->{price};
f5fea07 initial commit... need to fix/add tests
sshaw authored
23 # ...
24 }
25
26 =head1 DESCRIPTION
27
edb44bf added test cases, docs
sshaw authored
28 L<Mojolicious::Plugin::ParamExpand> turns request parameters into nested data
75c7cef change of plans
sshaw authored
29 structures using L<CGI::Expand>.
f5fea07 initial commit... need to fix/add tests
sshaw authored
30
485fa5f v0.01 prep
sshaw authored
31 =head1 MOJOLICIOUS VERSION
32
75c7cef change of plans
sshaw authored
33 Due to the old way C<Mojolicious::Controller> handled multi-valued request parameters,
485fa5f v0.01 prep
sshaw authored
34 versions of Mojolicious B<less than> 2.52 will not work with this plugin. If this is a problem for
35 you try L<Mojolicious::Plugin::GroupedParams>.
36
f5fea07 initial commit... need to fix/add tests
sshaw authored
37 =head1 OPTIONS
38
39 Options must be specified when loading the plugin.
40
edb44bf added test cases, docs
sshaw authored
41 =head2 separator
f5fea07 initial commit... need to fix/add tests
sshaw authored
42
43 $self->plugin('ParamExpand', separator => ',')
44
edb44bf added test cases, docs
sshaw authored
45 The character used to separate the data structure's hierarchy in the
46 flattened parameter. Defaults to C<'.'>.
f5fea07 initial commit... need to fix/add tests
sshaw authored
47
edb44bf added test cases, docs
sshaw authored
48 =head2 max_array
f5fea07 initial commit... need to fix/add tests
sshaw authored
49
50 $self->plugin('ParamExpand', max_array => 10)
51
52 Maximum number of array elements C<CGI::Expand> will create.
75c7cef change of plans
sshaw authored
53 Defaults to C<100>. If a parameter contains more than C<max_array>
54 elements an exception will be raised.
f5fea07 initial commit... need to fix/add tests
sshaw authored
55
485fa5f v0.01 prep
sshaw authored
56 To force the array into a hash keyed by its indexes set this to C<0>.
57
f5fea07 initial commit... need to fix/add tests
sshaw authored
58 =head1 Methods
59
edb44bf added test cases, docs
sshaw authored
60 =head2 param
61
75c7cef change of plans
sshaw authored
62 This is just L<Mojolicious::Controller/param> but, when using C<Mojolicious::Plugin::ParamExpand>, a
edb44bf added test cases, docs
sshaw authored
63 request with the parameters
f5fea07 initial commit... need to fix/add tests
sshaw authored
64
edb44bf added test cases, docs
sshaw authored
65 users.0.name=nameA&users.1.name=nameB&id=123
f5fea07 initial commit... need to fix/add tests
sshaw authored
66
edb44bf added test cases, docs
sshaw authored
67 will return a nested data structure for the param C<'users'>
f5fea07 initial commit... need to fix/add tests
sshaw authored
68
edb44bf added test cases, docs
sshaw authored
69 @users = $self->param('users');
70 $users[0]->{name};
71 $users[1]->{name};
72
73 Other parameters can be accessed as usual
f5fea07 initial commit... need to fix/add tests
sshaw authored
74
75 $id = $self->param('id');
76
edb44bf added test cases, docs
sshaw authored
77 The flattened parameter name can also be used
f5fea07 initial commit... need to fix/add tests
sshaw authored
78
edb44bf added test cases, docs
sshaw authored
79 $name0 = $self->param('users.0.name');
f5fea07 initial commit... need to fix/add tests
sshaw authored
80
edb44bf added test cases, docs
sshaw authored
81 =head3 Arguments
f5fea07 initial commit... need to fix/add tests
sshaw authored
82
edb44bf added test cases, docs
sshaw authored
83 C<$name>
f5fea07 initial commit... need to fix/add tests
sshaw authored
84
edb44bf added test cases, docs
sshaw authored
85 The name of the parameter.
f5fea07 initial commit... need to fix/add tests
sshaw authored
86
edb44bf added test cases, docs
sshaw authored
87 =head3 Returns
88
89 The value for the given parameter. If applicable it will be an expanded
90 data structure.
91
92 Top level arrays will be returned as arrays B<not> as array references.
93 This is how C<Mojolicious> behaves. In other words
94
95 users.0=userA&users.1=userB
96
97 is equivlent to
98
99 users=userA&users=userB
100
485fa5f v0.01 prep
sshaw authored
101 If this is undesirable you could L<< set C<max_array> to zero|/max_array >>.
edb44bf added test cases, docs
sshaw authored
102
103 =head1 SEE ALSO
104
105 L<CGI::Expand>, L<Mojolicious::Plugin::GroupedParams>
Something went wrong with that request. Please try again.