Search code examples
perlcookiesapache2mod-perl2strawberry-perl

Strange Apache2::Cookie error under Strawberry Perl and mod_perl2


I have a set of scripts that run under ActivePerl 5.10. However, under Strawberry Perl 5.10, I get a strange error message:

Can't locate object method "cookie_class" via package "MyCookie" (perhaps you forgot to load "MyCookie"?) at C:/strawberry/perl/site/lib/Apache2/Cookie.pm line 41.

However, MyCookie is the name of the cookie itself, not any Perl package.

If I comment out line 41 of Cookie.pm, the script runs, but I cannot successfully get or set cookies anymore.

The error message seems somewhat correct in that I can't find cookie_class either (except where it's mentioned in the POD files.) That said, the same is true for my ActivePerl installation.

I think it's in C:\strawberry\perl\site\lib\auto\APR\Request\Request.dll--how come it can't find it under Strawberry, but can under ActivePerl?


Solution

  • Change your code to use the 2.X scheme like so:

    my $j = Apache2::Cookie::Jar->new($r);
    my $cookie = $j->cookies("MyCookie"); # works!  go figure...
    

    Rather than the old method:

    local our %cookies = Apache2::Cookie->fetch($r); # error was happening here
    local our $cookie = $cookies{"MyCookie"};
    

    (For some reason this seemed to fix it.)