Skip Menu |

This queue is for tickets about the HTTP-Cookies CPAN distribution.

Report information
The Basics
Id: 12151
Status: resolved
Priority: 0/
Queue: HTTP-Cookies

People
Owner: Nobody in particular
Requestors: mark [...] summersault.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: wish: HTTP::Cookies should have easy access methods
I'm using Mech for testing, and I would like an easy way to express: "Did I get back a cookie named "foo"?". Right now it appears to do this would involve calling scan() with a callback. I would like a high level method for cookie access to be added, similar in spirit to Mechs find_link(). So maybe for my case it would work like this: $something = $cookie_jar->find_cookie( name => 'foo' ); And maybe "$something" should be an object for a single cookie, with several accessor methods. This is beginning to sound like real work now. :)
[guest - Tue Apr 5 12:56:29 2005]: Show quoted text
> I'm using Mech for testing, and I would like an easy way to express: > "Did I get back a cookie named "foo"?".
You shouldn't need to have to test for specific cookies when testing an app. Just test the app works. It shouldn't matter if the cookie changes names for the application to work correctly. I don't think there's real need for that API.
From: mark [...] summersault.com
hmm.. a previous comment I left seems to be missing. Anyway, here's anothe r real life use case: The login form has a "remember me" button, which sets a cookie for 1 year instead of 1 hour if it's checked. It's not reasonable for a test to wait a year (or an hour!) to see if the cookie set appropriately. A reasonable test is to examine the contents of the cookie. Mark
From: Michael Stillwell
[guest - Wed Apr 6 10:47:38 2005]: Show quoted text
> You shouldn't need to have to test for specific cookies when testing > an > app. Just test the app works. It shouldn't matter if the cookie > changes > names for the application to work correctly. > > I don't think there's real need for that API.
I have a need to this functionality too; in my case the cookie is read by a Flash app--so I can't test, from Perl, whether the app works. (In any case, I think there's a case for such a method by appeal to symmetry--there's a set, why not a get?)
Quick hack to add a get_cookie_hash method (doesn't filter by host, etc.): package HTTP::Cookies; sub get_cookie_hash { my ($self) = @_; my $hash = { }; $self->scan(sub { $hash->{$_[1]} = $_[2]; }); return $hash; }
Without a concrete API suggestion I'm not going to do anything about this.
On Sun Jul 26 14:54:47 2009, GAAS wrote: Show quoted text
> Without a concrete API suggestion I'm not going to do anything about this.
Thanks for the reply, Gisle. Then we can put it in my court to make some concrete API suggestions.
Here's a more specific API suggestion: # Returns the first cookie that relate to the current page and have the name of 'foo': my $cookie = $cookie_jar->find_current_cookie( name => 'foo' ); The "find" method is intentionally modeled after the "find*" methods in WWW::Mechanize. The initially implementation may only support the "name" search or other easy targets. Other criteria could be added later. The notion of "current cookies" is already in "add_cookie_header()", but needs to be factored-out for re-use. The "$cookie" returned would be an object that would have an API identical to CGI::Cookie, for familiarity and perhaps direct code re-use. If you are not a fan of CGI::Cookie, modeling CGI::Simple::Cookie or Mojo::Cookie are also possibilities. If heading in this direction seems interesting, myself or someone else could start to look at a patch. Mark
migrated queues: libwww-perl -> HTTP-Cookies