perl - Can't locate object method "***" via package "Apache2::RequestRec" -


i'm trying mod_perl working on apache installation in order use perlhandler.

i first tryied in subdirectory of domain virtual host

<virtualhost *:80>     serveradmin webmaster@localhost     servername ***.fr.cr      documentroot /var/www/aw     <directory /var/www/aw/>             allowoverride none             order allow,deny             allow     </directory>      perlmodule test2::rules2     alias /perl2/ /usr/lib/perl5/test2/     <location /perl2/>             order allow,deny             allow             sethandler perl-script             perlhandler test2::rules2     </location>      errorlog ${apache_log_dir}/aw.error.log      # possible values include: debug, info, notice, warn, error, crit,     # alert, emerg.     loglevel warn      customlog ${apache_log_dir}/aw.access.log combined </virtualhost> 

and here, working fine when go *.fr.cr/perl2/

but, when try directoly root of domain, virtualhost :

<virtualhost *:80>     serveradmin webmaster@localhost     servername ***.fr.cr      documentroot /var/www/aw     <directory /var/www/aw/>             allowoverride none             order allow,deny             allow     </directory>      perlmodule aw::main     alias / /usr/lib/perl5/aw/     <location />             order allow,deny             allow             sethandler perl-script             perlhandler aw::main     </location>      errorlog ${apache_log_dir}/aw.error.log      # possible values include: debug, info, notice, warn, error, crit,     # alert, emerg.     loglevel warn      customlog ${apache_log_dir}/aw.access.log combined </virtualhost> 

i got error 500, , apache log has line :

can't locate object method "content_type" via package "apache2::requestrec" @ /usr/lib/perl5/aw/main.pm line 6.\n 

the strange thing tested 2 codes

one missing "print" package , 1 missing "content_type" package, , first 1 has "content_type", error later in code.

i guess i'm missing virtual host, because works in 1 case, , not in other same code.

thanks!

edit : code : not working :

package aw::main; use apache2::const qw(:common);  sub handler {     $r = shift;     $r->content_type("text/plain");     $r->print("mod_perl rules!\n");     return ok; } 1; 

and working :

package test2::rules2; use apache2::const qw(:common);  sub handler { $r = shift; $r->content_type("text/plain"); $r->print("mod_perl rules!\n"); return ok; } 1; 

i've been struggling same problem , think i've found answer:

when call object method in perl, e.g. myinstance->themethod(arg1) themethod gets name of class (package) first parameter , first argument second parameter. if call method static method, e.g. class::method(arg1) first parameter subroutine gets first argument. this:

#!/usr/bin/perl  print "calling object method:\n"; fish->chips('lettuce'); print "calling static method:\n"; fish::chips('lettuce');  {package fish;  sub chips {   $x=shift;   $y=shift;    print "\$x $x , \$y $y\n";   } } 

and output of is:

calling object method: $x fish , $y lettuce calling static method: $x lettuce , $y  

mod_perl calling handler object method. it's taking package name first parameter. if add shift , throw away first parameter before shift second parameter $r request object you're looking for.

after looking @ apache conf file again realize had given handler directive perlresponsehandler fish->chips instead of perlresponsehandler fish::chips. had trouble mod_perl in finding handler wanted use. when specified fish , named handler sub handler {... mod_perl couldn't find it. likewise, when specified handler name, in fish::handler (or, renamed it) fish::chips apache file named chips.pm in directory named fish.

i don't know if actual bug in way mod_perl parsing or resolving handler names, @ least it's brittle behaviour. unless i'm missing here, , if hope can point out.

i hope helps.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -