[cgiapp] Using CGI::Cookie from inside CGI::Application

CGI User cgiapp at mailswamp.com
Wed May 21 11:41:48 EDT 2008


Hello,

I'm trying to use CGI::Cookie module calling it from CGI::Application 
environment in cgiapp_prerun like this:

sub cgiapp_prerun {
     my $self = shift;

     my $cookie = CGI::Cookie->new(
         -name       => 'some_name',
         -value      => '12345',
         -domain     => '.come_domain.com',
         -path       => '/',
         -expires    => '+1H',
        	-secure     => 1,
     );

     $self->header_add(-cookie => [$cookie]);

     return $self;
}

But nothing is happening, and this test cookie is not being set in the browser 
(Firefox).

However, when I try to do this:

sub cgiapp_prerun {
     my $self = shift;

     my $q = $self->query();

     my $cookie = $q->cookie('some_name' => '12345');

    $self->header_add(-cookie => [$cookie]);

     return $self;
}

It works and the cookie name and its value is being set in the browser.

My question are:
1. Why it didn't work in the first case.
2. If the first case won't work, then how I can set all the cookie parameters
e.g. domain, path, expires, secure using the second case.
3. How I can retrieve my cookie from the browser is the recommended first case 
to set cookie is not working, and the second case is working but I cannot see 
any method to retrieve my own cookie?

Thank you very much in advance.

Alex


More information about the cgiapp mailing list