简体   繁体   English

草莓Perl和mod_perl2下的奇怪Apache2 :: Cookie错误

[英]Strange Apache2::Cookie error under Strawberry Perl and mod_perl2

I have a set of scripts that run under ActivePerl 5.10. 我有一组在ActivePerl 5.10下运行的脚本。 However, under Strawberry Perl 5.10, I get a strange error message: 但是,在Strawberry Perl 5.10下,我收到一条奇怪的错误消息:

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. 但是, MyCookie是cookie本身的名称,而不是任何Perl包。

If I comment out line 41 of Cookie.pm, the script runs, but I cannot successfully get or set cookies anymore. 如果我注释掉Cookie.pm的第41行,脚本将运行,但是我无法成功获取或设置cookie。

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. 错误消息似乎是正确的,因为我也找不到cookie_class (POD文件中提到的地方除外)。也就是说,ActivePerl安装也是如此。

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? 我认为它在C:\\strawberry\\perl\\site\\lib\\auto\\APR\\Request\\Request.dll为什么它无法在Strawberry下找到,但可以在ActivePerl下找到?

Change your code to use the 2.X scheme like so: 更改代码以使用2.X方案,如下所示:

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.) (由于某种原因,这似乎可以解决。)

Are you possibly mixing the apreq DLLs between the Strawberry and ActivePerl versions? 您是否可能在Strawberry版本和ActivePerl版本之间混合apreq DLL? Or mixing apreq-1 and apreq-2 DLLs somehow? 还是以某种方式混合apreq-1和apreq-2 DLL?

The area around the offending cookie_class call is just this: 令人讨厌的cookie_class调用周围的区域是这样的:

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. cookie_class方法的确来自Request.dll ,在调用jar()之前对$req进行了类型检查。

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. 调试的最佳第一步是加载Carp :: Always,以便您可以追溯并了解实际情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM