Skip to content

Commit

Permalink
a few more small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 9, 2013
1 parent 97f463f commit 9274340
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions lib/Mojo/Cookie/Request.pm
Expand Up @@ -21,8 +21,7 @@ sub to_string {
my $self = shift;
return '' unless length(my $name = $self->name // '');
my $value = $self->value // '';
$value = $value =~ /[,;" ]/ ? quote($value) : $value;
return "$name=$value";
return join '=', $name, $value =~ /[,;" ]/ ? quote($value) : $value;
}

1;
Expand Down
9 changes: 4 additions & 5 deletions lib/Mojo/Cookie/Response.pm
Expand Up @@ -57,8 +57,7 @@ sub to_string {
# Name and value (Netscape)
return '' unless length(my $name = $self->name // '');
my $value = $self->value // '';
$value = $value =~ /[,;" ]/ ? quote($value) : $value;
my $cookie = "$name=$value";
my $cookie = join '=', $name, $value =~ /[,;" ]/ ? quote($value) : $value;

# "expires" (Netscape)
if (defined(my $e = $self->expires)) { $cookie .= "; expires=$e" }
Expand All @@ -70,13 +69,13 @@ sub to_string {
if (my $path = $self->path) { $cookie .= "; path=$path" }

# "secure" (Netscape)
if (my $secure = $self->secure) { $cookie .= "; secure" }
$cookie .= "; secure" if $self->secure;

# "Max-Age" (RFC 6265)
if (defined(my $m = $self->max_age)) { $cookie .= "; Max-Age=$m" }
if (defined(my $max = $self->max_age)) { $cookie .= "; Max-Age=$max" }

# "HttpOnly" (RFC 6265)
if (my $httponly = $self->httponly) { $cookie .= "; HttpOnly" }
$cookie .= "; HttpOnly" if $self->httponly;

return $cookie;
}
Expand Down

0 comments on commit 9274340

Please sign in to comment.