Skip to content

Commit

Permalink
deprecate Mojo::UserAgent::CookieJar::collecting in favor of Mojo::Us…
Browse files Browse the repository at this point in the history
…erAgent::CookieJar::ignore
  • Loading branch information
kraih committed Sep 15, 2015
1 parent 0a84de7 commit 9fd79e2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

6.20 2015-09-15
- Deprecated Mojo::UserAgent::CookieJar::collecting in favor of
Mojo::UserAgent::CookieJar::ignore.
- Improved support for epoll/kqueue in Mojo::IOLoop::Client.

6.19 2015-09-12
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -510,8 +510,8 @@ environment variable or C<10>.
Cookie jar to use for requests performed by this user agent, defaults to a
L<Mojo::UserAgent::CookieJar> object.
# Disable collecting cookies from responses
$ua->cookie_jar->collecting(0);
# Ignore all cookies
$ua->cookie_jar->ignore(sub { 1 });
# Ignore cookies for public suffixes
my $ps = IO::Socket::SSL::PublicSuffix->default;
Expand Down
27 changes: 17 additions & 10 deletions lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -3,8 +3,8 @@ use Mojo::Base -base;

use Mojo::Cookie::Request;
use Mojo::Path;
use Mojo::Util 'deprecated';

has collecting => 1;
has 'ignore';
has max_cookie_size => 4096;

Expand Down Expand Up @@ -40,7 +40,8 @@ sub all {
sub collect {
my ($self, $tx) = @_;

return unless $self->collecting;
# DEPRECATED in Clinking Beer Mugs!
return unless $self->{collecting} // 1;

my $url = $tx->req->url;
for my $cookie (@{$tx->res->cookies}) {
Expand All @@ -59,6 +60,16 @@ sub collect {
}
}

# DEPRECATED in Clinking Beer Mugs!
sub collecting {
deprecated 'Mojo::UserAgent::CookieJar::collecting is DEPRECATED in favor of'
. ' Mojo::UserAgent::CookieJar::ignore';
my $self = shift;
return $self->{collecting} //= 1 unless @_;
$self->{collecting} = shift;
return $self;
}

sub empty { delete shift->{jar} }

sub find {
Expand Down Expand Up @@ -147,21 +158,17 @@ L<Mojo::UserAgent> and based on L<RFC 6265|http://tools.ietf.org/html/rfc6265>.
L<Mojo::UserAgent::CookieJar> implements the following attributes.
=head2 collecting
my $bool = $jar->collecting;
$jar = $jar->collecting($bool);
Allow L</"collect"> to L</"add"> new cookies to the jar, defaults to a true
value.
=head2 ignore
my $ignore = $jar->ignore;
$jar = $jar->ignore(sub {...});
A callback used to decide if a cookie should be ignored by L</"collect">.
# Ignore all cookies
$jar->ignore(sub { 1 });
# Ignore cookies with domain "com"
$jar->ignore(sub {
my $cookie = shift;
return undef unless my $domain = $cookie->domain;
Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/group_lite_app.t
Expand Up @@ -282,14 +282,14 @@ $t->get_ok('/bridge2stash' => {Cookie => "mojolicious=$session--$hmac"})
->status_is(200)->content_is("stash too!!!!!!!!\n");

# Not collecting cookies
$t->reset_session->ua->cookie_jar->collecting(0);
$t->reset_session->ua->cookie_jar->ignore(sub {1});
$t->get_ok('/bridge2stash' => {'X-Flash' => 1})->status_is(200)
->content_is("stash too!!!!!!!!\n");

# Still not collecting cookies
$t->get_ok('/bridge2stash' => {'X-Flash' => 1})->status_is(200)
->content_is("stash too!!!!!!!!\n");
$t->ua->cookie_jar->collecting(1);
$t->ua->cookie_jar->ignore(sub {0});

# Fresh start without cookies, session or flash
$t->get_ok('/bridge2stash' => {'X-Flash' => 1})->status_is(200)
Expand Down
2 changes: 1 addition & 1 deletion t/pod_coverage.t
Expand Up @@ -7,4 +7,4 @@ plan skip_all => 'set TEST_POD to enable this test (developer only!)'
plan skip_all => 'Test::Pod::Coverage 1.04+ required for this test!'
unless eval 'use Test::Pod::Coverage 1.04; 1';

all_pod_coverage_ok();
all_pod_coverage_ok({also_private => ['collecting']});

0 comments on commit 9fd79e2

Please sign in to comment.