Skip to content

Commit

Permalink
fixed Mojo::Cookie interface definition
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 19, 2012
1 parent 3137385 commit 353b6d3
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 107 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@
This file documents the revision history for Perl extension Mojolicious.

2.63 2012-03-18 00:00:00
2.63 2012-03-19 00:00:00
- Improved Mojolicious::Renderer performance.
- Improved documentation.
- Fixed bug that slowed down Mojolicious::Renderer.
Expand Down
3 changes: 3 additions & 0 deletions lib/Mojo/Content/MultiPart.pm
Expand Up @@ -7,13 +7,16 @@ has parts => sub { [] };

sub new {
my $self = shift->SUPER::new(@_);

# Default content parser
$self->on(
read => sub {
my ($self, $chunk) = @_;
$self->{multipart} .= $chunk;
$self->_parse_multipart;
}
);

return $self;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Mojo/Content/Single.pm
Expand Up @@ -9,12 +9,15 @@ has auto_upgrade => 1;

sub new {
my $self = shift->SUPER::new(@_);

# Default content parser
$self->{read} = $self->on(
read => sub {
my ($self, $chunk) = @_;
$self->asset($self->asset->add_chunk($chunk));
}
);

return $self;
}

Expand Down
10 changes: 7 additions & 3 deletions lib/Mojo/Cookie.pm
Expand Up @@ -32,11 +32,9 @@ my $VALUE_RE = qr/
# "My Homer is not a communist.
# He may be a liar, a pig, an idiot, a communist,
# but he is not a porn star."
sub parse { croak 'Method "parse" not implemented by subclass' }
sub to_string { croak 'Method "to_string" not implemented by subclass' }

# DEPRECATED in Leaf Fluttering In Wind!
sub version { warn "Mojo::Cookie->version is DEPRECATED!\n" }

sub _tokenize {
my ($self, $string) = @_;

Expand Down Expand Up @@ -115,6 +113,12 @@ Cookie value.
L<Mojo::Cookie> inherits all methods from L<Mojo::Base> and implements the
following new ones.
=head2 C<parse>
my $cookies = $cookie->parse($string);
Parse cookies.
=head2 C<to_string>
my $string = $cookie->to_string;
Expand Down
6 changes: 0 additions & 6 deletions lib/Mojo/Cookie/Response.pm
Expand Up @@ -8,9 +8,6 @@ has [qw/domain httponly max_age path secure/];

my $ATTR_RE = qr/(Domain|expires|HttpOnly|Max-Age|Path|Secure)/msi;

# DEPRECATED in Leaf Fluttering In Wind!
sub comment { warn "Mojo::Cookie::Response->comment is DEPRECATED!\n" }

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

Expand Down Expand Up @@ -58,9 +55,6 @@ sub parse {
return \@cookies;
}

# DEPRECATED in Leaf Fluttering In Wind!
sub port { warn "Mojo::Cookie::Response->port is DEPRECATED!\n" }

sub to_string {
my $self = shift;

Expand Down
3 changes: 3 additions & 0 deletions lib/Mojo/Log.pm
Expand Up @@ -30,6 +30,8 @@ my $LEVEL = {debug => 1, info => 2, warn => 3, error => 4, fatal => 5};

sub new {
my $self = shift->SUPER::new(@_);

# Default logger
$self->on(
message => sub {
my $self = shift;
Expand All @@ -40,6 +42,7 @@ sub new {
flock $handle, LOCK_UN;
}
);

return $self;
}

Expand Down
24 changes: 11 additions & 13 deletions lib/Mojo/Message/Request.pm
Expand Up @@ -39,22 +39,20 @@ sub clone {
sub cookies {
my $self = shift;

# Add cookies
# Parse cookies
my $headers = $self->headers;
if (@_) {
my @cookies = $headers->cookie || ();
for my $cookie (@_) {
$cookie = Mojo::Cookie::Request->new($cookie) if ref $cookie eq 'HASH';
push @cookies, $cookie;
}
$headers->cookie(join('; ', @cookies));
return $self;
return [map { @{Mojo::Cookie::Request->parse($_)} } $headers->cookie]
unless @_;

# Add cookies
my @cookies = $headers->cookie || ();
for my $cookie (@_) {
$cookie = Mojo::Cookie::Request->new($cookie) if ref $cookie eq 'HASH';
push @cookies, $cookie;
}
$headers->cookie(join('; ', @cookies));

# Cookie
my @cookies;
push @cookies, @{Mojo::Cookie::Request->parse($_)} for $headers->cookie;
return \@cookies;
return $self;
}

sub fix_headers {
Expand Down
21 changes: 9 additions & 12 deletions lib/Mojo/Message/Response.pm
Expand Up @@ -73,21 +73,18 @@ my %MESSAGES = (
sub cookies {
my $self = shift;

# Add cookies
# Parse cookies
my $headers = $self->headers;
if (@_) {
for my $cookie (@_) {
$cookie = Mojo::Cookie::Response->new($cookie) if ref $cookie eq 'HASH';
$headers->add('Set-Cookie', "$cookie");
}
return $self;
return [map { @{Mojo::Cookie::Response->parse($_)} } $headers->set_cookie]
unless @_;

# Add cookies
for my $cookie (@_) {
$cookie = Mojo::Cookie::Response->new($cookie) if ref $cookie eq 'HASH';
$headers->add('Set-Cookie', "$cookie");
}

# Parse cookies
my @cookies;
push @cookies, @{Mojo::Cookie::Response->parse($_)}
for $headers->set_cookie;
return \@cookies;
return $self;
}

sub default_message { $MESSAGES{$_[1] || $_[0]->code || 404} || '' }
Expand Down
9 changes: 0 additions & 9 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -29,15 +29,6 @@ sub DESTROY {
$loop->drop($_) for @{$self->{listening} || []};
}

# DEPRECATED in Leaf Fluttering In Wind!
sub keep_alive_timeout {
warn <<EOF;
Mojo::Server::Daemon->keep_alive_timeout is DEPRECATED in favor of
Mojo::Server::Daemon->inactivity_timeout!
EOF
shift->inactivity_timeout(@_);
}

# DEPRECATED in Leaf Fluttering In Wind!
sub prepare_ioloop {
warn <<EOF;
Expand Down
4 changes: 0 additions & 4 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -161,10 +161,6 @@ sub _config {
my $listen = $c->{listen} || ['http://*:8080'];
$listen = [$listen] unless ref $listen;
$daemon->listen($listen);

# DEPRECATED in Leaf Fluttering In Wind!
$daemon->inactivity_timeout($c->{keep_alive_timeout})
if $c->{keep_alive_timeout};
}

sub _exit { say shift and exit 0 }
Expand Down
43 changes: 20 additions & 23 deletions lib/Mojo/URL.pm
Expand Up @@ -153,35 +153,32 @@ sub path {
sub query {
my $self = shift;

# Merge or replace parameters
if (@_) {
# Get parameters
return $self->{query} ||= Mojo::Parameters->new unless @_;

# Replace with list
if (@_ > 1) {
$self->{query} = Mojo::Parameters->new(ref $_[0] ? @{$_[0]} : @_);
}

# Merge with array
elsif (ref $_[0] && ref $_[0] eq 'ARRAY') {
my $q = $self->{query} ||= Mojo::Parameters->new;
while (my $name = shift @{$_[0]}) {
my $value = shift @{$_[0]};
defined $value ? $q->param($name => $value) : $q->remove($name);
}
}
# Replace with list
if (@_ > 1) {
$self->{query} = Mojo::Parameters->new(ref $_[0] ? @{$_[0]} : @_);
}

# Append hash
elsif (ref $_[0] && ref $_[0] eq 'HASH') {
($self->{query} ||= Mojo::Parameters->new)->append(%{$_[0]});
# Merge with array
elsif (ref $_[0] && ref $_[0] eq 'ARRAY') {
my $q = $self->{query} ||= Mojo::Parameters->new;
while (my $name = shift @{$_[0]}) {
my $value = shift @{$_[0]};
defined $value ? $q->param($name => $value) : $q->remove($name);
}
}

# Replace with string
else { $self->{query} = Mojo::Parameters->new($_[0]) }

return $self;
# Append hash
elsif (ref $_[0] && ref $_[0] eq 'HASH') {
($self->{query} ||= Mojo::Parameters->new)->append(%{$_[0]});
}

return $self->{query} ||= Mojo::Parameters->new;
# Replace with string
else { $self->{query} = Mojo::Parameters->new($_[0]) }

return $self;
}

sub to_abs {
Expand Down
21 changes: 4 additions & 17 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -45,12 +45,9 @@ sub app {

# Try to detect application
$self->{app} ||= $ENV{MOJO_APP} if ref $ENV{MOJO_APP};
if ($app) {
$self->{app} = ref $app ? $app : $self->_server->app_class($app)->app;
return $self;
}

return $self->{app};
return $self->{app} unless $app;
$self->{app} = ref $app ? $app : $self->_server->app_class($app)->app;
return $self;
}

sub app_url {
Expand Down Expand Up @@ -82,15 +79,6 @@ sub detect_proxy {
return $self;
}

# DEPRECATED in Leaf Fluttering In Wind!
sub keep_alive_timeout {
warn <<EOF;
Mojo::UserAgent->keep_alive_timeout is DEPRECATED in favor of
Mojo::UserAgent->inactivity_timeout!
EOF
shift->inactivity_timeout(@_);
}

sub need_proxy {
my ($self, $host) = @_;
return 1 unless my $no = $self->no_proxy;
Expand Down Expand Up @@ -431,8 +419,7 @@ sub _redirect {

# Follow redirect
return 1 unless my $id = $self->_start($new, delete $c->{cb});
$self->{connections}->{$id}->{redirects} = $redirects + 1;
return 1;
return $self->{connections}->{$id}->{redirects} = $redirects + 1;
}

sub _server {
Expand Down
25 changes: 9 additions & 16 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -155,15 +155,13 @@ sub name {
my $self = shift;

# Custom names have precedence
if (@_) {
if (defined(my $name = shift)) {
$self->{name} = $name;
$self->{custom} = 1;
}
return $self;
return $self->{name} unless @_;
if (defined(my $name = shift)) {
$self->{name} = $name;
$self->{custom} = 1;
}

return $self->{name};
return $self;
}

sub options { shift->_generate_route(options => @_) }
Expand Down Expand Up @@ -289,15 +287,10 @@ sub under { shift->_generate_route(under => @_) }

sub via {
my $self = shift;

# Restrict methods
if (@_) {
my $methods = [map { lc $_ } @{ref $_[0] ? $_[0] : [@_]}];
$self->{via} = $methods if @$methods;
return $self;
}

return $self->{via};
return $self->{via} unless @_;
my $methods = [map { lc $_ } @{ref $_[0] ? $_[0] : [@_]}];
$self->{via} = $methods if @$methods;
return $self;
}

sub waypoint { shift->route(@_)->block(1) }
Expand Down
5 changes: 2 additions & 3 deletions t/pod_coverage.t
Expand Up @@ -9,9 +9,8 @@ plan skip_all => 'set TEST_POD to enable this test (developer only!)'

# DEPRECATED in Leaf Fluttering In Wind!
my @leaf = (
qw/comment default_static_class default_template_class keep_alive_timeout/,
qw/max_redirects port prepare_ioloop root unsubscribe version/,
qw/x_forwarded_for/
qw/default_static_class default_template_class max_redirects/,
qw/prepare_ioloop root unsubscribe x_forwarded_for/
);

# "Marge, I'm going to miss you so much. And it's not just the sex.
Expand Down

0 comments on commit 353b6d3

Please sign in to comment.