perldoc Apache::Cookie says

   value
           Get or set the values of the cookie:

1.            my $value = $cookie->value;
2.            my @values = $cookie->value;

3.            $cookie->value("string");
4.            $cookie->value(\@array); 

so if you set  a array ref in 4 you retrieve it as in 2
extrapolating that I hope if you set a hash ref with value
you should get a hash back with value. The the same happens.

the following two snippets (set and get cookie) demonstrates
that-------->





set-cookie.html
---------------
<% value
           

use Apache;
use Apache::Cookie;

my $hash_ref = {
                 'AGE' => 30,
                 'SEX' => 'M'
               };
my $r = Apache->request;

my $c = Apache::Cookie->new($r,
                -name    => 'conf',
                -value   => $hash_ref,
                -expires => '+30m',
                -path    => '/'
                           );
$c->bake;
%>
-------------------


get-cookie.html
--------------------------
<%
use Apache::Cookie;
my $cookie_ref = Apache::Cookie->fetch;
my $conf_cookie = $cookie_ref->{conf};
my %hash  = $conf_cookie->value;
my $hash_ref = \%hash;
%>

<html>
cookie 'conf'  has value <% print $conf_cookie %> <br>
hash reference is <% print $hash_ref %> <br>
content of cookie:
AGE: <% print $hash{'AGE'} %><br>
SEX: <% print $hash{'SEX'} %><br>
</html>
--------------------

Alvar Freude wrote:
> 
> Hi,
> 
> I have some problems in setting and getting back Cookie Values with
> Apache::Cookie.
> 
> I'm setting a cookie with Apache::Cookie and it seems that the cookie is
> set correct:
> 
>     my $c = Apache::Cookie->new($r,
>                             -name    => 'conf',
>                             -value   => $hash_ref,
>                             -expires => '+30D',
>                             -path    => '/'
>                             );
>     $c->bake;
> 
> But while Recovering the Cookie I got some errors:
> 
> $cookie_ref = Apache::Cookie->fetch;
> 
> Now $cookoe_ref->{conf} contains not a reference to the old values, it
> contains a skalar like "Apache::Cookie=SCALAR(0x8b675b8)", but no
> hashref ...
> 
> Whats going on? It seems that I'm too stupid, argl!
> 
> The CGI::Cookie-POD only sais:
> 
>        fetch returns an associative array consisting of all
>        cookies returned by the browser.  The keys of the array
>        are the cookie names.
> 
> OK, OK, but what's with the Values of the Hash?
> How can I get the Cookie Values back?
> 
> Whats going wrong?
> 
> Thanx and Ciao
>   Alvar

Reply via email to