Mailing List Archive

Can't locate object method "new" via package "CGI::Cookie"
Hi List,

I have two servers using mod_perl, both having the same modules installed and enabled; server1 got a fresh install of Debian Buster, while server2 was upgraded to Buster from Stretch.

This code :
my $cookie = CGI::Cookie->new(-name => 'session',
-value => $session_id,
-domain => $hostname
) ;

generates the following error on server2 :

[Sun May 31 19:54:03.053725 2020] [perl:error] [pid 30663] [client 83.113.48.133:59196] Can't locate object method "new" via package "CGI::Cookie" (perhaps you forgot to load "CGI::Cookie"?) at /home/lib/Marica/Base/login.pm line 198.\n, referer: https://marica.fr/site/abonnes/index.html

It works fine if add "use CGI::Cookie" to my module.

What could be the reason why it works on server1 without "use CGI::Cookie" and not on server2?

--
https://compta.libremen.com
Logiciel libre de comptabilit? g?n?rale en partie double
AW: Can't locate object method "new" via package "CGI::Cookie" [ In reply to ]
Hi Vincent,

I don't have Debian. Therefor just a view hints.

1) CGI::Cookie loading is done sometimes dynamically via require. E.g. in
CGI.pm itself.
2) mod_perl 1/2 with the helper modules Apache2::RequestUtil interact
dynamically.
3) It can be possible that you have a version clash (alone or in combination
with other modules). Probably there was once pulled a module in your older
server which hinders the same behaviour.

Tests:
perl -MCGI::Cookie -E'say CGI::Cookie->VERSION'
perl -MApache2::RequestUtil -E'say Apache2::RequestUtil->VERSION'

On the other hand you can add debug code just before line
/home/lib/Marica/Base/login.pm line 198
to inspect the %INC hash to see whether CGI::Cookie was loaded somewhere.

You can also find the file Cookie.pm in your include path and put a
print STDERR map { "$_\n" } caller;
into it to find the location in Apache error log where it gets loaded in
the module stack.

Best regards
Andreas


-----Urspr?ngliche Nachricht-----
Von: Vincent Veyron <vv.lists@wanadoo.fr>
Gesendet: Sonntag, 31. Mai 2020 20:50
An: modperl@perl.apache.org
Betreff: Can't locate object method "new" via package "CGI::Cookie"

Hi List,

I have two servers using mod_perl, both having the same modules installed
and enabled; server1 got a fresh install of Debian Buster, while server2 was
upgraded to Buster from Stretch.

This code :
my $cookie = CGI::Cookie->new(-name => 'session',
-value => $session_id,
-domain => $hostname
) ;

generates the following error on server2 :

[Sun May 31 19:54:03.053725 2020] [perl:error] [pid 30663] [client
83.113.48.133:59196] Can't locate object method "new" via package
"CGI::Cookie" (perhaps you forgot to load "CGI::Cookie"?) at
/home/lib/Marica/Base/login.pm line 198.\n, referer:
https://marica.fr/site/abonnes/index.html

It works fine if add "use CGI::Cookie" to my module.

What could be the reason why it works on server1 without "use CGI::Cookie"
and not on server2?

--
https://compta.libremen.com
Logiciel libre de comptabilit? g?n?rale en partie double
Re: Can't locate object method "new" via package "CGI::Cookie" [ In reply to ]
On 31.05.2020 20:49, Vincent Veyron wrote:
> Hi List,
>
> I have two servers using mod_perl, both having the same modules installed and enabled; server1 got a fresh install of Debian Buster, while server2 was upgraded to Buster from Stretch.
>
> This code :
> my $cookie = CGI::Cookie->new(-name => 'session',
> -value => $session_id,
> -domain => $hostname
> ) ;
>
> generates the following error on server2 :
>
> [Sun May 31 19:54:03.053725 2020] [perl:error] [pid 30663] [client 83.113.48.133:59196] Can't locate object method "new" via package "CGI::Cookie" (perhaps you forgot to load "CGI::Cookie"?) at /home/lib/Marica/Base/login.pm line 198.\n, referer: https://marica.fr/site/abonnes/index.html
>
> It works fine if add "use CGI::Cookie" to my module.
>
> What could be the reason why it works on server1 without "use CGI::Cookie" and not on server2?
>

Hi.
Since the two systems were installed/upgraded differently ..

When I configure mod_perl on a Debian system, I usually have a "startup script" running
from within the /etc/apache2/mod_enabled/perl.conf file, e.g. via

PerlPostConfigRequire "/etc/apache2/modperl2_startup.pl"

This startup script, among other things, preloads frequently-used modules, so that they
will be loaded and available later in any Apache child/thread. Like :

...
use lib "some_path_with_proprietary_modules";
...
use ModPerl::Registry ();
use CGI ();
CGI->compile(':all');
use My::Module;
...

Maybe you forgot this on one of the systems, and not the other ?

P.S.
I also use the same startup script to log some information to the Apache error log at
startup, such as this for example :

[Sun May 31 06:25:08.054152 2020] [:error] [pid 5519] mp2-startup: EFSDIR is : /home/EFS
[Sun May 31 06:25:08.054160 2020] [:error] [pid 5519] mp2-startup: AUTHZ_GRANTED is : 1
[Sun May 31 06:25:08.054166 2020] [:error] [pid 5519] mp2-startup: AUTHZ_DENIED is : 0
[Sun May 31 06:25:08.054173 2020] [:error] [pid 5519] mp2-startup: AUTHZ_DENIED_NO_USER is : 4
[Sun May 31 06:25:08.054184 2020] [:error] [pid 5519] mp2-startup: @INC is now :
/home/EFS/lib / /etc/perl / /usr/local/lib/x86_64-linux-gnu/perl/5.20.2 /
/usr/local/share/perl/5.20.2 / /usr/lib/x86_64-linux-gnu/perl5/5.20 / /usr/share/perl5 /
/usr/lib/x86_64-linux-gnu/perl/5.20 / /usr/share/perl/5.20 / /usr/local/lib/site_perl / .
/ /etc/apache2

precisely so that I would know what the perl module library search paths would be under
Apache when it runs.
Re: Can't locate object method "new" via package "CGI::Cookie" [ In reply to ]
On Mon, 1 Jun 2020 09:55:24 +0200
Andr? Warnier (tomcat/perl) <aw@ice-sa.com> wrote:

>
> PerlPostConfigRequire "/etc/apache2/modperl2_startup.pl"
>
> Maybe you forgot this on one of the systems, and not the other ?
>

You know, I grepped the hell out of my modules for an hour before posting, trying to find this "use ...' line. I can't believe I indeed forgot about the startup.pl :

ssh kimsufi_3 grep use\ /etc/apache2/startup.pl | grep CGI
use CGI::Cookie ();

ssh kimsufi_2 grep use\ /etc/apache2/startup.pl | grep CGI
#use CGI::Cookie ();

Good call Andr? :-)

(note to self : stop working when you're obviously too tired to think, so as not to embarass yourself in public)

> I also use the same startup script to log some information to the Apache error log at
> startup, such as this for example :
> 4184 2020] [:error] [pid 5519] mp2-startup: @INC is now :
...
> precisely so that I would know what the perl module library search paths would be under
> Apache when it runs.
>

Nice, thanks for the tip.