You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Foo Ji-Haw <jh...@nexlabs.com> on 2005/09/19 06:04:21 UTC

Apache2::Cookie bug, or just my misinterpretation?

Hello all,

I am using the following setup:
Apache/2.0.52 (Win32) mod_apreq2-20050712/2.1.3-dev mod_perl/2.0.1 Perl/v5.8.7

I get the request cookie names like this:
my $jar = Apache2::Cookie::Jar->new($r);
my @keys = $jar->cookies();

I notice that the @keys list includes not just the cookie names, but also the name=value pair as well. That means the following does NOT work:
foreach my $key (@keys)
{
    print "$key\n";
#    print "$key : ".$jar->cookies($key)->value."\n";
}

Because I will end up with (pseudo):
cookie1=value1 : 
cookie1 :
cookie2 : 
cookie2=value2 :
...

Is this a Apache2::Cookie bug, an old library that I am using, or did I read the docs wrongly?

Re: Apache2::Cookie bug, or just my misinterpretation?

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Foo Ji-Haw wrote:
> I get the request cookie names like this:
> my $jar = Apache2::Cookie::Jar->new($r);
> my @keys = $jar->cookies();
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: $@.
EOD
     }
     $req = APR::Request::Apache2->handle($req)
         unless $req->isa("APR::Request");

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

The reason why is that you do 'wantarray'

You want to instead write:

my $keys_hashref = $jar->cookies();

Also, we don't recommend the Apache2::* interface after/as of 2.05-dev, but 
instead the APR equivalents.

Have a look at
APR::Request::Cookie

You'll notice, its the Apache2::Cookie::fetch() is a wrapper around the APR one 
anyway.


-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com