0

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Kev
  • 15,899
  • 15
  • 79
  • 112

3 Answers3

2

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

Kev
  • 15,899
  • 15
  • 79
  • 112
  • 1
    Bizarre that the old school `fetch` worked with ActivePerl but not Strawberry. `Apache2::Cookie::Jar` works and is, I suppose, the proper way so congrats on sorting this out. – mu is too short Nov 10 '10 at 04:26
  • It is bizarre--and now I'm having problems with Apache2::Request::param that are equally bizarre, but I think I'm already doing it "the proper way" there. Anyway, thanks for the confirmation and props for helping me so much. :) – Kev Nov 10 '10 at 11:52
1

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.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • Not that I can see. I followed the directions at http://mail-archives.apache.org/mod_mbox/perl-modperl/201007.mbox/%3CAANLkTimP1oCDwBU2RZ2hfK4nMorZ-SoZlJ_ennx8JKTT@mail.gmail.com%3E and they have it install mod_perl2 from KMX's Strawberry-specific build. – Kev Nov 10 '10 at 01:41
  • 1
    What do you get when you call "$r->jar" yourself? Do you get an object? A scalar? Something that has a "cookie_class()" method? – mu is too short Nov 10 '10 at 01:56
  • I get `Can't locate object method "jar" via package "Apache2::RequestRec"`. – Kev Nov 10 '10 at 02:34
  • 1
    And if you say `my $req = APR::Request::Apache2->handle($r); $req->jar;`? I'm just walking through Apache2::Cookie::fetch line by line BTW, hopefully something will come up. – mu is too short Nov 10 '10 at 02:43
  • (Oddly, `$req->isa("APR::Request")` returns `1`, so the code you suggested, i.e. calling `handle`, shouldn't get executed in `fetch` 'normally'...) – Kev Nov 10 '10 at 03:48
0

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.

hobbs
  • 223,387
  • 19
  • 210
  • 288
  • I did a stack trace. But what's really happening is the same thing that's always been really happening: `%cookies = Apache2::Cookie->fetch($r)` where `$r` is an `Apache2::RequestRec` object. The same code works fine under ActivePerl with no changes. Also, at the point in the code at which it crashes, `MyCookie` is not checked for yet (not that it's passed to `fetch()` anyway), so I'm assuming it's getting this from the browser's actual cookie. – Kev Nov 10 '10 at 01:47
  • I deleted the browser's cookie, and sure enough, it no longer errors out. However, now it no longer successfully sets the cookie, either. – Kev Nov 10 '10 at 01:48