Return-Path: Delivered-To: apmail-perl-modperl-archive@www.apache.org Received: (qmail 2854 invoked from network); 26 Dec 2005 19:20:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 26 Dec 2005 19:20:03 -0000 Received: (qmail 64798 invoked by uid 500); 26 Dec 2005 19:19:56 -0000 Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 64772 invoked by uid 500); 26 Dec 2005 19:19:56 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 64760 invoked by uid 99); 26 Dec 2005 19:19:55 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Dec 2005 11:19:55 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [66.250.131.114] (HELO mail2.2xlp.com) (66.250.131.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Dec 2005 11:19:55 -0800 Received: from [64.131.154.173] (helo=[192.168.1.103]) by mail2.2xlp.com with esmtpsa (TLSv1:RC4-SHA:128) (Exim 4.54 (FreeBSD)) id 1Eqxte-000C4W-3X; Mon, 26 Dec 2005 14:20:38 -0500 In-Reply-To: <20051226183256.E9F9F10FB00E@asf.osuosl.org> References: <20051226183256.E9F9F10FB00E@asf.osuosl.org> Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <33194B0E-F32E-41D7-B0D0-0C9AEF1B3EF2@2xlp.com> Cc: mod_perl List Content-Transfer-Encoding: 7bit From: Jonathan Subject: Re: Apache2::Cookies - getting all names Date: Mon, 26 Dec 2005 14:19:29 -0500 To: Jeff X-Mailer: Apple Mail (2.746.2) X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 > > > >