Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
a few small optimizations
  • Loading branch information
kraih committed Oct 7, 2014
1 parent e312dce commit bdcc96a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
31 changes: 15 additions & 16 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -125,13 +125,12 @@ sub param {
return sort @keys;
}

# Override values
if (@_) {
$captures->{$name} = @_ > 1 ? [@_] : $_[0];
return $self;
}
# Value
return _param($self, $name)->[0] unless @_;

return _param($self, $name)->[0];
# Override values
$captures->{$name} = @_ > 1 ? [@_] : $_[0];
return $self;
}

sub redirect_to {
Expand Down Expand Up @@ -276,13 +275,13 @@ sub signed_cookie {
# Multiple names
return map { $self->signed_cookie($_) } @$name if ref $name eq 'ARRAY';

# Response cookie
my $secrets = $self->stash->{'mojo.secrets'};
return $self->cookie($name,
"$value--" . Mojo::Util::hmac_sha1_sum($value, $secrets->[0]), $options)
if defined $value;
# Request cookie
return _signed_cookie($self, $name)->[0] unless defined $value;

return _signed_cookie($self, $name)->[0];
# Response cookie
my $checksum
= Mojo::Util::hmac_sha1_sum($value, $self->stash->{'mojo.secrets'}[0]);
return $self->cookie($name, "$value--$checksum", $options);
}

sub stash { Mojo::Util::_stash(stash => @_) }
Expand Down Expand Up @@ -491,7 +490,7 @@ implements the following new ones.
=head2 all_cookies
my $values = $c->all_cookie('foo');
my $cookies = $c->all_cookie('foo');
Access all request cookie values with the same name. To access only one cookie
you can also use L</"cookie">.
Expand All @@ -516,7 +515,7 @@ excessively large, there's a 10MB limit by default.
=head2 all_signed_cookies
my $values = $c->all_signed_cookies('foo');
my $cookies = $c->all_signed_cookies('foo');
Access all signed request cookie values with the same name. To access only one
signed cookie you can also use L</"signed_cookie">.
Expand All @@ -532,7 +531,7 @@ Continue dispatch chain with L<Mojolicious::Routes/"continue">.
=head2 cookie
my $value = $c->cookie('foo');
my $cookie = $c->cookie('foo');
my ($foo, $bar) = $c->cookie(['foo', 'bar']);
$c = $c->cookie(foo => 'bar');
$c = $c->cookie(foo => 'bar', {path => '/'});
Expand Down Expand Up @@ -884,7 +883,7 @@ on browser.
=head2 signed_cookie
my $value = $c->signed_cookie('foo');
my $cookie = $c->signed_cookie('foo');
my ($foo, $bar) = $c->signed_cookie(['foo', 'bar']);
$c = $c->signed_cookie(foo => 'bar');
$c = $c->signed_cookie(foo => 'bar', {path => '/'});
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojolicious/Validator/Validation.pm
Expand Up @@ -19,7 +19,7 @@ sub AUTOLOAD {
return $self->check($method => @_);
}

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

sub check {
my ($self, $check) = (shift, shift);
Expand Down Expand Up @@ -92,8 +92,7 @@ sub required {
}

sub _param {
my ($self, $name) = @_;
my $value = $self->output->{$name};
my $value = shift->output->{shift()};
return [ref $value eq 'ARRAY' ? @$value : $value];
}

Expand Down

0 comments on commit bdcc96a

Please sign in to comment.