httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philip M. Gollucci" <>
Subject Re: Apache2::Cookies - getting all names
Date Wed, 28 Dec 2005 17:38:12 GMT

Jeff wrote:
 > > Folks,
 > >
 > > I am finding it hard to correctly interpret the Apache2::Cookie
 > > documentation: The docs say:
 > >   @names = $j->cookies();        # all cookie names

The actual code (SVN-trunk), says this:

The final return line in sub fetch() below explains your findings.

package Apache2::Cookie::Jar;
sub cookies { Apache2::Cookie->fetch(@_) }

package Apache2::Cookie;
sub fetch {
      my $class = shift;
      my $req = shift;
      unless (defined $req) {
          my $usage = 'Usage: Apache2::Cookie->fetch($r): missing
argument $r';
          $req = eval {Apache2::RequestUtil->request} or die <<EOD;
$usage: attempt to fetch global Apache2::RequestUtil->request failed: $@.
      $req = APR::Request::Apache2->handle($req)
          unless $req->isa("APR::Request");

      my $jar = $req->jar or return;
      return $jar->get(shift) if @_;
      return wantarray ? %$jar : $jar;

  >  my $jar   =  Apache2::Cookie::Jar->new( $r ); # get the jar
  >  my @names = $jar->cookies();                  # all cookie names
  >Why does @names contain values that are not cookie names?
  >I am guessing that the docs are wrong on this one.

You are correct, I'll update them:
[Move this disccustion to apreq-dev (at) perl (dot) apache (dot) org  CC'ed]

How about like so?

---   (revision 359541)
+++   (working copy)
@@ -191,14 +191,14 @@
   internal I<cookies> table in C<apreq_jar_t>, so their impact will
   be noticed by all libapreq2 applications during this request.

-In list context C<< $jar->cookies() >> returns the list of names
+In list context C<< $jar->cookies() >> returns the list of cookies
   for all the cookies in the jar.  The order corresponds to the
   order in which the cookies appeared in the incoming "Cookie" header.

   This method will throw an C<< APR::Request::Error >> object into $@ if
   the returned value(s) could be unreliable.  In particular, note that
   C<< scalar $jar->cookies("foo") >> will not croak if it can locate
-the a "foo" cookie within the jar's parsed cookie table, even if the
+a "foo" cookie within the jar's parsed cookie table, even if the
   cookie parser has failed (the cookies are parsed in the same order
   as they appeared in the "Cookie" header). In all other circumstances
   C<cookies> will croak if the parser failed to successfully parse the
@@ -209,11 +209,12 @@

       $cookie = $j->cookies("foo");  # first foo cookie
       @cookies = $j->cookies("foo"); # all foo cookies
-    @names = $j->cookies();        # all cookie names
+    @names = $j->cookies();        # all cookies
+    $hashref = $j->cookies();      # hashref keyed on cookie name
+                                   # of all cookies

   =head2 status


Convesly, we could patch the code instead of the docs to make it do what
the docs said originally ?
---   (revision 359541)
+++   (working copy)
@@ -40,7 +40,7 @@
       my $jar = $req->jar or return;
       return $jar->get(shift) if @_;
-    return wantarray ? %$jar : $jar;
+    return wantarray ? keys %$jar : $jar;

I'm betting the code change is what we want here.
"Love is not the one you can picture yourself marrying,
but the one you can't picture the rest of your life without."

"It takes a minute to have a crush on someone, an hour to like someone,
and a day to love someone, but it takes a lifetime to forget someone..."

Philip M. Gollucci ( 301.254.5198
Consultant /
Senior Software Engineer - TicketMaster -

View raw message