Question

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?

Was it helpful?

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.)

OTHER TIPS

Are you possibly mixing the apreq DLLs between the Strawberry and ActivePerl versions? Or mixing apreq-1 and apreq-2 DLLs somehow?

The area around the offending cookie_class call is just this:

my $jar = $req->jar or return;
$jar->cookie_class(__PACKAGE__);
return $jar->get(shift) if @_;

The cookie_class method does come from Request.dll and $req is type checked before jar() is called.

Somewhere, you or someone else is passing a string to a function that expects an object. Your best first step in debugging would be to load Carp::Always so that you can get a backtrace and find out what's really happening.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top