This is what I do:
my $cookiejar = Apache2::Cookie::Jar->new( $this->{'ApacheRequest'} );
my @names = $cookiejar->cookies();
DEBUG_COOKIE >0 && print STDERR "-| Found These Cookies : " . (join
" , ",@names) . "\n";
if ( $cookiejar->cookies( $this->{'CookieDefaults'}->{'names'}->
{'Session'} ) )
{
DEBUG_COOKIE >0 && print STDERR "-| Handling cookie: {$this->
{'CookieDefaults'}->{'names'}->{'Session'}} \n";
DEBUG_COOKIE >0 && print STDERR "-| >> Validating... \n";
my %c_cookies = Apache2::Cookie->fetch(
$this->{'ApacheRequest'} );
my $c_value = $c_cookies{ $this->{'CookieDefaults'}->{'names'}->
{'Session'} }->value;
DEBUG_COOKIE >0 && print STDERR "-| \%c_cookies => \{\} ; \
$c_cookies\{{$this->{'CookieDefaults'}->{'names'}->{'Session'}}\}-
>value = '", $c_value , "'\n";
DEBUG_COOKIE >0 && print STDERR "-| Validating c_value
$c_value \n";
}
you've got
my @vals = $cookie->value();
as far as i know, cookies only have a single scalar value. you'll
need to serialize/deserialize any other data structure into it.
cookiedefaults are something that i set in a sitewide configuration
file:
my $CookieDefaults = {
domain =>
[
'127.0.0.1',
'dev.2xlp.com',
],
path => '/',
expires => '+365d',
secure => 0,
names =>
{
'Session' => 'my_session',
'AutoLogin' => 'my_autologin',
}
};
and i have a session wrapper class that sets/reads cookies for all
domains in the cookie defaults configuration, for the Session cookie
( named names[Session] ) or AutoLogin cookie ( names[AutoLogin] )
that setup is very manageable for me
On Dec 26, 2005, at 1:32 PM, Jeff wrote:
Folks,
I am finding it hard to correctly interpret the Apache2::Cookie
documentation: The docs say:
@names = $j->cookies(); # all cookie names
When I do this, for the following cookies:
c1 => 'v1',
c2 => 'v2',
I expect @names to contain ( "c1", "c2" ), but instead
@names contains ( "c1", "c1=v1", "c2", "c2=v2" )
The following code has the above problem:
my $jar = Apache2::Cookie::Jar->new( $r );
my @names = $jar->cookies;
for my $name ( @names ) {
my $cookie = $jar->cookies( $name );
my @vals = $cookie->value();
print "cookie: $name values: @vals\n";
}
Instead, I have ended up with:
my $jar = Apache2::Cookie::Jar->new( $r )->cookies;
my @cookies = values %$jar;
for my $cookie ( @cookies ) {
my $token = $cookie->name();
my @vals = $cookie->value();
print "cookie: $token value: @vals\n";
}
Is there a better way? I couldn't get this to work:
my @cookies = values /
%{ scalar Apache2::Cookie::Jar->new( $r )->cookies };
- seems that the Jar class is trying much to hard to be clever? Or
maybe I'm just being dumb?
Thoughts appreciated,
Jeff