darkwater23 has asked for the wisdom of the Perl Monks concerning the following question:

Hello!

I'm trying to migrate a site over to an Apache2 server from an Apache1 server. The perl cookie handling pieces of code are not quite working. Here's the error I get:

Can't locate object method "fetch" via package "Apache2::Cookie" (perhaps you forgot to load "Apache2::Cookie"?) at /usr/local/apache/htdocs/autohandler line 6.

Our site uses Mason. The block of code causing trouble is below. Per the documentation on CPAN, I added the $r object and changed the name of the packages referenced in the code. When I received the can't locate "fetch" error, I had the server admin check the installation and update the packages again. He insists that Apache2::Cookie is available. Assuming it is, is there anything is this code that would cause the error?

<%init> local *session; if ($r->uri =~ m/product|faq|finder|broadmarket|msp/gi) { my %c = Apache2::Cookie->fetch($r); my $session_id = exists $c{session_} ? $c{session_}->value : undef; eval { tie %session, 'Apache2::Session::File', $session_id, { Directory => '/var/sessions/data', LockDirectory => '/var/sessions/lock', }; }; if ($@) { die $@ unless $@ =~ /Object does not exist/; # Re-throw $m->redirect('/index.html'); } #expires => '+20m', Apache2::Cookie->new( $r, name => 'session_', value => $session{_session_id}, path => '/', )->bake; } #$m->out($r->as_string); $m->call_next; </%init>
Some people are like Slinkies. Not really good for anything, but you still can't help but smile when you see one tumble down the stairs.

Replies are listed 'Best First'.
Re: Convert Apache1 perl to Apache2
by dtr (Scribe) on Sep 21, 2006 at 18:30 UTC

    Two things come to mind. Firstly, are you sure that Apache2::Cookie is being loaded (not just installed on your machine) when your apache server starts up? Perhaps have a look at your startup.pl file?

    It *used* to be the case with mod_perl 2 that you could arrange for it to be installed in a separate "Apache2" directory (so that it's modules could co-exist with modules of the same name in mod_perl 1). Then, in order to use those modules, you'd have to say use Apache2 in your code first. This would fiddle with your @INC so that the remaining mod_perl2 modules could be used.

    That all stopped when the mod_perl 2 modules were renamed (sometime around 1.99_22 IIRC). Perhaps your server has been set up in this way?

Re: Convert Apache1 perl to Apache2
by perrin (Chancellor) on Sep 21, 2006 at 18:47 UTC
    Apache2::Cookie is provided by libapreq2. If you have not installed that, you don't have Apache2::Cookie. You also may need to explicitly load the module somewhere. I'm not sure Mason will do it for you.