Skip to content

Commit

Permalink
added direct array access for parsed parameters to Mojo::Parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 10, 2013
1 parent 388fb4b commit e368cfc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

3.90 2013-03-10
- Added direct array access for parsed parameters to Mojo::Parameters.
- Added direct array access for path parts to Mojo::Path.
- Improved dumper helper to sort hash keys.
- Improved documentation.
Expand Down
9 changes: 9 additions & 0 deletions lib/Mojo/Parameters.pm
@@ -1,6 +1,7 @@
package Mojo::Parameters;
use Mojo::Base -base;
use overload
'@{}' => sub { shift->params },
'bool' => sub {1},
'""' => sub { shift->to_string },
fallback => 1;
Expand Down Expand Up @@ -326,6 +327,14 @@ the parameters.
Turn parameters into a string.
=head1 PARAMETERS
Direct array reference access to the parsed parameters is also possible. Note
that this will normalize the parameters.
say $params->[0];
say for @$params;
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
Expand Down
5 changes: 5 additions & 0 deletions t/mojo/parameters.t
Expand Up @@ -11,6 +11,11 @@ is $params->to_string, 'foo=b%3Bar&baz=23', 'right format';
is $params2->to_string, 'x=1&y=2', 'right format';
is $params->to_string, 'foo=b%3Bar&baz=23', 'right format';
is_deeply $params->params, ['foo', 'b;ar', 'baz', 23], 'right structure';
is $params->[0], 'foo', 'right value';
is $params->[1], 'b;ar', 'right value';
is $params->[2], 'baz', 'right value';
is $params->[3], 23, 'right value';
is $params->[4], undef, 'no value';
$params->pair_separator(';');
is $params->to_string, 'foo=b%3Bar;baz=23', 'right format';
is "$params", 'foo=b%3Bar;baz=23', 'right format';
Expand Down

0 comments on commit e368cfc

Please sign in to comment.