Skip to content

Commit

Permalink
added all method to Mojo::UserAgent::CookieJar
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 11, 2012
1 parent 2d39c62 commit 8d7d223
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,4 +1,7 @@

3.47 2012-10-12
- Added all method to Mojo::UserAgent::CookieJar.

3.46 2012-10-11
- Improved router and renderer to allow camel case controllers.
- Improved documentation.
Expand Down
12 changes: 12 additions & 0 deletions lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -30,6 +30,11 @@ sub add {
return $self;
}

sub all {
my $jar = shift->{jar};
return map { @{$jar->{$_}} } sort keys %$jar;
}

sub empty { shift->{jar} = {} }

sub extract {
Expand Down Expand Up @@ -137,6 +142,13 @@ implements the following new ones.
Add multiple L<Mojo::Cookie::Response> objects to the jar.
=head2 C<all>
my @cookies = $jar->all;
Return all L<Mojo::Cookie::Response> objects that are currently stored in the
jar.
=head2 C<empty>
$jar->empty;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -38,7 +38,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Rainbow';
our $VERSION = '3.46';
our $VERSION = '3.47';

sub AUTOLOAD {
my $self = shift;
Expand Down
12 changes: 11 additions & 1 deletion t/mojo/cookiejar.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 83;
use Test::More tests => 92;

use Mojo::Cookie::Response;
use Mojo::URL;
Expand Down Expand Up @@ -136,6 +136,16 @@ is $cookies[1], undef, 'no second cookie';
is $cookies[0]->name, 'bar', 'right name';
is $cookies[0]->value, 'baz', 'right value';
is $cookies[1], undef, 'no second cookie';
@cookies = $jar->all;
is $cookies[0]->domain, 'com', 'right domain';
is $cookies[0]->path, '/foo', 'right path';
is $cookies[0]->name, 'foo', 'right name';
is $cookies[0]->value, 'bar', 'right value';
is $cookies[1]->domain, 'kraih.com', 'right domain';
is $cookies[1]->path, '/foo', 'right path';
is $cookies[1]->name, 'bar', 'right name';
is $cookies[1]->value, 'baz', 'right value';
is $cookies[2], undef, 'no second cookie';

# Huge cookie
$jar = Mojo::UserAgent::CookieJar->new->max_cookie_size(1024);
Expand Down

0 comments on commit 8d7d223

Please sign in to comment.