Skip to content

Commit

Permalink
switched from all_* prefix to every_*
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 7, 2014
1 parent bdcc96a commit 60a1072
Show file tree
Hide file tree
Showing 18 changed files with 195 additions and 194 deletions.
10 changes: 5 additions & 5 deletions Changes
Expand Up @@ -5,12 +5,12 @@
Breaking change: Methods that previously worked differently in scalar than
in list context now always assume scalar context, and new methods have
been added to cover the list context functionality.
- Added all_cookies and all_uploads methods to Mojo::Message.
- Added all_params method to Mojo::Message::Request.
- Added all_params method to Mojo::Parameters.
- Added all_cookies, all_params and all_signed_cookies methods to
- Added every_cookie and every_upload methods to Mojo::Message.
- Added every_param method to Mojo::Message::Request.
- Added every_param method to Mojo::Parameters.
- Added every_cookie, every_param and every_signed_cookie methods to
Mojolicious::Controller.
- Added all_params method to Mojolicious::Validator::Validation.
- Added every_param method to Mojolicious::Validator::Validation.
- Added from_json and to_json functions to Mojo::JSON.
- Improved pluck method in Mojo::Collection to be able to extract values
from hash references.
Expand Down
60 changes: 30 additions & 30 deletions lib/Mojo/Message.pm
Expand Up @@ -17,9 +17,6 @@ has max_line_size => sub { $ENV{MOJO_MAX_LINE_SIZE} || 10240 };
has max_message_size => sub { $ENV{MOJO_MAX_MESSAGE_SIZE} // 10485760 };
has version => '1.1';

sub all_cookies { shift->_cache('cookie', 1, @_) }
sub all_uploads { shift->_cache('upload', 1, @_) }

sub body {
my $self = shift;

Expand Down Expand Up @@ -82,6 +79,9 @@ sub error {
return $self->finish;
}

sub every_cookie { shift->_cache('cookie', 1, @_) }
sub every_upload { shift->_cache('upload', 1, @_) }

sub extract_start_line {
croak 'Method "extract_start_line" not implemented by subclass';
}
Expand Down Expand Up @@ -409,30 +409,6 @@ HTTP version of message, defaults to C<1.1>.
L<Mojo::Message> inherits all methods from L<Mojo::EventEmitter> and
implements the following new ones.
=head2 all_cookies
my $cookies = $msg->all_cookies('foo');
Access all message cookies with the same name, usually
L<Mojo::Cookie::Request> or L<Mojo::Cookie::Response> objects. To access only
one cookie you can also use L</"cookie">. Note that this method caches all
data, so it should not be called before all headers have been received.
# Get first cookie value
say $msg->all_cookies('foo')->[0]->value;
=head2 all_uploads
my $uploads = $msg->all_uploads('foo');
Access all C<multipart/form-data> file uploads with the same name, usually
L<Mojo::Upload> objects. To access only one upload you can also use
L</"upload">. Note that this method caches all data, so it should not be
called before the entire message body has been received.
# Get content of first uploaded file
say $msg->all_uploads('foo')->[0]->asset->slurp;
=head2 body
my $bytes = $msg->body;
Expand Down Expand Up @@ -486,8 +462,8 @@ Render start line.
Access message cookies, usually L<Mojo::Cookie::Request> or
L<Mojo::Cookie::Response> objects. To access more than one cookie you can also
use L</"all_cookies">. Note that this method caches all data, so it should not
be called before all headers have been received.
use L</"every_cookie">. Note that this method caches all data, so it should
not be called before all headers have been received.
# Get cookie value
say $msg->cookie('foo')->value;
Expand Down Expand Up @@ -525,6 +501,30 @@ make sure it is not excessively large, there's a 10MB limit by default.
Get or set message error, an C<undef> return value indicates that there is no
error.
=head2 every_cookie
my $cookies = $msg->every_cookie('foo');
Access all message cookies with the same name, usually
L<Mojo::Cookie::Request> or L<Mojo::Cookie::Response> objects. To access only
one cookie you can also use L</"cookie">. Note that this method caches all
data, so it should not be called before all headers have been received.
# Get first cookie value
say $msg->every_cookie('foo')->[0]->value;
=head2 every_upload
my $uploads = $msg->every_upload('foo');
Access all C<multipart/form-data> file uploads with the same name, usually
L<Mojo::Upload> objects. To access only one upload you can also use
L</"upload">. Note that this method caches all data, so it should not be
called before the entire message body has been received.
# Get content of first uploaded file
say $msg->every_upload('foo')->[0]->asset->slurp;
=head2 extract_start_line
my $bool = $msg->extract_start_line(\$str);
Expand Down Expand Up @@ -634,7 +634,7 @@ Render whole message.
my ($foo, $bar) = $msg->upload(['foo', 'bar']);
Access C<multipart/form-data> file uploads, usually L<Mojo::Upload> objects.
To access more than one upload you can also use L</"all_uploads">. Note that
To access more than one upload you can also use L</"every_upload">. Note that
this method caches all data, so it should not be called before the entire
message body has been received.
Expand Down
36 changes: 18 additions & 18 deletions lib/Mojo/Message/Request.pm
Expand Up @@ -16,8 +16,6 @@ my $START_LINE_RE = qr/
\s+HTTP\/(\d\.\d)$ # Version
/x;

sub all_params { shift->params->all_params(@_) }

sub clone {
my $self = shift;

Expand Down Expand Up @@ -53,6 +51,8 @@ sub cookies {
return $self;
}

sub every_param { shift->params->every_param(@_) }

sub extract_start_line {
my ($self, $bufref) = @_;

Expand Down Expand Up @@ -339,21 +339,6 @@ Request has been performed through a reverse proxy.
L<Mojo::Message::Request> inherits all methods from L<Mojo::Message> and
implements the following new ones.
=head2 all_params
my $values = $req->all_params('foo');
Access all C<GET> and C<POST> parameters with the same name extracted from the
query string and C<application/x-www-form-urlencoded> or
C<multipart/form-data> message body. To access only one value you can also use
L</"param">. Note that this method caches all data, so it should not be called
before the entire request body has been received. Parts of the request body
need to be loaded into memory to parse C<POST> parameters, so you have to make
sure it is not excessively large, there's a 10MB limit by default.
# Get first value
say $req->all_params('foo')->[0];
=head2 clone
my $clone = $req->clone;
Expand All @@ -368,6 +353,21 @@ Clone request if possible, otherwise return C<undef>.
Access request cookies, usually L<Mojo::Cookie::Request> objects.
=head2 every_param
my $values = $req->every_param('foo');
Access all C<GET> and C<POST> parameters with the same name extracted from the
query string and C<application/x-www-form-urlencoded> or
C<multipart/form-data> message body. To access only one value you can also use
L</"param">. Note that this method caches all data, so it should not be called
before the entire request body has been received. Parts of the request body
need to be loaded into memory to parse C<POST> parameters, so you have to make
sure it is not excessively large, there's a 10MB limit by default.
# Get first value
say $req->every_param('foo')->[0];
=head2 extract_start_line
my $bool = $req->extract_start_line(\$str);
Expand Down Expand Up @@ -412,7 +412,7 @@ Check C<X-Requested-With> header for C<XMLHttpRequest> value.
Access C<GET> and C<POST> parameters extracted from the query string and
C<application/x-www-form-urlencoded> or C<multipart/form-data> message body.
To access more than one value you can also use L</"all_params">. Note that
To access more than one value you can also use L</"every_param">. Note that
this method caches all data, so it should not be called before the entire
request body has been received. Parts of the request body need to be loaded
into memory to parse C<POST> parameters, so you have to make sure it is not
Expand Down
26 changes: 13 additions & 13 deletions lib/Mojo/Parameters.pm
Expand Up @@ -10,8 +10,6 @@ use Mojo::Util qw(decode encode url_escape url_unescape);

has charset => 'UTF-8';

sub all_params { shift->_param(@_) }

sub append {
my $self = shift;

Expand Down Expand Up @@ -39,6 +37,8 @@ sub clone {
return $clone;
}

sub every_param { shift->_param(@_) }

sub merge {
my $self = shift;
push @{$self->params}, @{$_->params} for @_;
Expand Down Expand Up @@ -229,16 +229,6 @@ Charset used for encoding and decoding parameters, defaults to C<UTF-8>.
L<Mojo::Parameters> inherits all methods from L<Mojo::Base> and implements the
following new ones.
=head2 all_params
my $values = $params->all_params('foo');
Access all parameter values with the same name. To access only one value you
can also use L</"param">. Note that this method will normalize the parameters.
# Get first value
say $params->all_params('foo')->[0];
=head2 append
$params = $params->append(foo => 'ba&r');
Expand All @@ -262,6 +252,16 @@ Append parameters. Note that this method will normalize the parameters.
Clone parameters.
=head2 every_param
my $values = $params->every_param('foo');
Access all parameter values with the same name. To access only one value you
can also use L</"param">. Note that this method will normalize the parameters.
# Get first value
say $params->every_param('foo')->[0];
=head2 merge
$params = $params->merge(Mojo::Parameters->new(foo => 'b&ar', baz => 23));
Expand Down Expand Up @@ -290,7 +290,7 @@ necessary.
$params = $params->param(foo => ['ba;r', 'baz']);
Access parameter values. To access more than one value you can also use
L</"all_params">. Note that this method will normalize the parameters.
L</"every_param">. Note that this method will normalize the parameters.
=head2 params
Expand Down
11 changes: 6 additions & 5 deletions lib/Mojolicious.pm
Expand Up @@ -158,11 +158,12 @@ sub new {
my $r = $self->routes->namespaces(["@{[ref $self]}::Controller", ref $self]);

# Hide controller attributes/methods and "handler"
$r->hide(qw(all_cookies all_params all_signed_cookies app continue cookie));
$r->hide(qw(finish flash handler helpers match on param redirect_to render));
$r->hide(qw(render_exception render_later render_maybe render_not_found));
$r->hide(qw(render_to_string rendered req res respond_to send session));
$r->hide(qw(signed_cookie stash tx url_for validation write write_chunk));
$r->hide(qw(app continue cookie every_cookie every_param));
$r->hide(qw(every_signed_cookie finish flash handler helpers match on));
$r->hide(qw(param redirect_to render render_exception render_later));
$r->hide(qw(render_maybe render_not_found render_to_string rendered req));
$r->hide(qw(res respond_to send session signed_cookie stash tx url_for));
$r->hide(qw(validation write write_chunk));

# DEPRECATED in Tiger Face!
$r->hide('render_static');
Expand Down

0 comments on commit 60a1072

Please sign in to comment.