Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 2, 2011
1 parent da27380 commit c37d414
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 36 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

1.97 2011-09-02 00:00:00
- Fixed typos.

1.96 2011-09-02 00:00:00
- Updated jQuery to version 1.6.3.
- Fixed Mojo::IOLoop to ignore SIGPIPE.
Expand Down
13 changes: 7 additions & 6 deletions lib/Mojo/Cookie.pm
Expand Up @@ -6,12 +6,12 @@ use overload
fallback => 1;

use Carp 'croak';
use Mojo::Util 'unquote';

has [qw/name path value version/];

# Regex
my $COOKIE_SEPARATOR_RE = qr/^\s*\,\s*/;
my $EXPIRES_RE = qr/^([^\;\,]+\,?[^\;\,]+)\s*/;
my $NAME_RE = qr/
^\s*
([^\=\;\,]+) # Relaxed Netscape token, allowing whitespace
Expand Down Expand Up @@ -45,21 +45,22 @@ sub _tokenize {
# Name
if ($string =~ s/$NAME_RE//o) {
my $name = $1;
my $value;

# "expires" is a special case, thank you Netscape...
if ($name =~ /expires/i && $string =~ s/$EXPIRES_RE//o) { $value = $1 }
$string =~ s/^([^\;\,]+\,?[^\;\,]+)/"$1"/ if $name =~ /expires/i;

# Value
elsif ($string =~ s/$VALUE_RE//o) { $value = $1 }
my $value;
if ($string =~ s/$VALUE_RE//o) {
$value = $1;
unquote $value;
}

# Token
push @token, [$name, $value];

# Separator
$string =~ s/$SEPARATOR_RE//o;

# Cookie separator
if ($string =~ s/$COOKIE_SEPARATOR_RE//o) {
push @tree, [@token];
@token = ();
Expand Down
8 changes: 2 additions & 6 deletions lib/Mojo/Cookie/Request.pm
@@ -1,7 +1,7 @@
package Mojo::Cookie::Request;
use Mojo::Base 'Mojo::Cookie';

use Mojo::Util qw/quote unquote/;
use Mojo::Util 'quote';

# "Lisa, would you like a donut?
# No thanks. Do you have any fruit?
Expand All @@ -15,7 +15,6 @@ sub parse {
for my $knot ($self->_tokenize($string)) {
for my $token (@{$knot}) {
my ($name, $value) = @{$token};
unquote $value if $value;

# Path
if ($name =~ /^\$Path$/i) { $cookies[-1]->path($value) }
Expand Down Expand Up @@ -46,7 +45,6 @@ sub prefix {
sub to_string {
my $self = shift;

# Render
return '' unless $self->name;
my $cookie = $self->name;
my $value = $self->value;
Expand All @@ -61,9 +59,7 @@ sub to_string {
}

sub to_string_with_prefix {
my $self = shift;

# Render with prefix
my $self = shift;
my $prefix = $self->prefix;
my $cookie = $self->to_string;
return "$prefix; $cookie";
Expand Down
29 changes: 6 additions & 23 deletions lib/Mojo/Cookie/Response.pm
Expand Up @@ -2,24 +2,13 @@ package Mojo::Cookie::Response;
use Mojo::Base 'Mojo::Cookie';

use Mojo::Date;
use Mojo::Util qw/quote unquote/;
use Mojo::Util 'quote';

has [qw/comment domain httponly max_age port secure/];

# Regex
my $FIELD_RE = qr/
(
Comment
| Domain
| expires
| HttpOnly # IE6 FF3 Opera 9.5
| Max-Age
| Path
| Port
| Secure
| Version
)
/xmsi;
my $FIELD_RE =
qr/(Comment|Domain|expires|HttpOnly|Max-Age|Path|Port|Secure|Version)/msi;
my $FLAG_RE = qr/(?:Secure|HttpOnly)/i;

sub expires {
Expand All @@ -31,9 +20,8 @@ sub expires {
return $self;
}

return unless defined $self->{expires};

# Upgrade
return unless defined $self->{expires};
$self->{expires} = Mojo::Date->new($self->{expires})
unless ref $self->{expires};

Expand All @@ -51,7 +39,6 @@ sub parse {
for my $knot ($self->_tokenize($string)) {
for my $i (0 .. $#{$knot}) {
my ($name, $value) = @{$knot->[$i]};
unquote $value if $value;

# This will only run once
if (not $i) {
Expand Down Expand Up @@ -98,14 +85,10 @@ sub to_string {
if (my $path = $self->path) { $cookie .= "; Path=$path" }

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

# Expires
if (defined(my $expires = $self->expires)) {
$cookie .= "; expires=$expires";
}
if (defined(my $e = $self->expires)) { $cookie .= "; expires=$e" }

# Port
if (my $port = $self->port) { $cookie .= qq/; Port="$port"/ }
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -34,7 +34,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Smiling Face With Sunglasses';
our $VERSION = '1.96';
our $VERSION = '1.97';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down

0 comments on commit c37d414

Please sign in to comment.