Re: problem with $r->push_handlers()

2002-09-17 Thread Geoffrey Young



Martin Moss wrote:
> All,
>  
> can anybody provide any help with this problem  - and maybe explain why 
> I get the following anomoly?


[snip]


> mod_perl_push_handlers: Not a subroutine name or CODE reference! at 
> /usr/local/lib/perl//MyMod/Apache/Multiplex.pm line 101.

I really can't follow what you're doing here, but the above error is 
pretty clear: the second argument to push_handlers() isn't in the 
correct format.

I would try a few simple debug statements using Data::Dumper or 
something (and probably not print() since it has that funny 
dereferencing feature) to see what's in the variable so you're 
completely sure.  maybe you're holding a reference to the string and 
not the string itself.

you could also try using

PerlSetEnv MOD_PERL_TRACE all

in your httpd.conf to find out what mod_perl sees under the hood 
(assuming you have a debug perl and built mod_perl with PERL_TRACE=1)

>  
> Anyway, Answers on a Postcard please:-)

if you're still having problems, if you could reduce the scenario to a 
simple test case we can try, that would help.

--Geoff




Re: problem with $r->push_handlers()

2002-09-17 Thread Martin Moss



I have traced my problem to the following 
subroutine which populates the Hash I use to keep track of mappings of URL's to 
Modules (handlers) to use.
As you will see, at the very end of my parse_file 
subroutine I have two lines commented out. IF I uncomment these lines out, I end 
up overwriting the data in my hash with the clean data I supply. When I do this 
my Apache Multiplexer (the thing which does the 
$r->push_handlers($handler_bf)) works fine and all is fine. However if I 
leave the line commented out - as is here - I get the following 
error:-
 
[Tue Sep 17 22:41:35 2002] [error] Undefined 
subroutine &MyMod::Apache::Test1 called,  line 2.
 
 
 
So I'm at a loss, any further help you could give 
would be useful,
 
Marty
 
 
Here is a sample file:-
/test1/   =  
MyMod::Apache::Test1/test2/   =  
MyMod::Apache::Test2
Here is a file parsing subroutine I use to read the 
above file and populate a hash, which I export to another 
routine.:-
 
our (%HANDLERS);
 
sub _is_tainted{  not eval  {    
join("",@_), kill 0;    1;  };}
 
sub parse_file{  my 
$file=shift;  print STDERR "Parsing file $file\n";  open 
(FILE,"<$file") or die "Cannot open file for reading $file";  while 
(my $line=)  {    chomp 
$line;    if ($line=~/^\#/)    
{  next;    
}    else    
{  my 
($keyname,$varname)=split/\=/,$line;  print 
STDERR "Initial $keyname = $varname\n";  
$keyname=~s/^\s*//;  
$varname=~s/^\s*//;  
$keyname=~s/\s*$//;  
$varname=~s/\s*$//;  
$keyname=~s/'//g;  
$varname=~s/'//g;  
$keyname=~s/"//g;  
$varname=~s/"//g;
 
  
$keyname=~s/^\///;  
$keyname=~s/\/$//;  my @tmp=split /\//, 
$keyname;  my 
$untainted_keyname;  while 
(@tmp)  
{    my $tainted_var=shift 
@tmp;    if ($tainted_var 
=~/^([\w-]+)$/)    
{  
$tainted_var=$1;  die 
"$tainted_var is Tainted" if 
(&_is_tainted($tainted_var));  
$untainted_keyname.='/'.$tainted_var;  
die "$untainted_keyname is Tainted" if 
(&_is_tainted($untainted_keyname));    
}    
else    
{  die "Taint Check 
failed for $tainted_var\n";    
}  }  
$untainted_keyname.='/';  if 
($varname=~/^([-:\w]+)$/)  
{    
$varname=$1;    die "$varname is 
Tainted" if (&_is_tainted($varname));  
}  else  
{    die "Taint Check failed for 
$varname\n";  
}  
$HANDLERS{$untainted_keyname}=$varname;  print 
STDERR "Added $keyname = $varname\n";    }  
}  #$HANDLERS{'/test1/'}='MyMod::Apache::Test1';  
#$HANDLERS{'/test2/'} = 'MyMod::Apache::Test2';  close 
(FILE);}

  - Original Message - 
  From: 
  Martin Moss 
  To: [EMAIL PROTECTED] 
  Sent: Tuesday, September 17, 2002 2:13 
  AM
  Subject: problem with 
  $r->push_handlers()
  
  
  All,
   
  can anybody provide any help with this 
  problem  - and maybe explain why I get the following 
anomoly?
  I've been trying to find the cause of the issue 
  but to no avail:-(
   
  I have MyMod::Apache::Test  pre-loaded in my httpd.conf file.
   
  Here is an extract of code:-
  ($handler is defined from a Hash defined within 
  this Code)
  ($handler_bf is defined from a hash exported by a 
  module used in this code. to get to the stage in the code where the following 
  lines commence, I already have read the value from the exported hash and it is 
  held in the variable $handler_bf)
   
  #$r->push_handlers(PerlHandler => 
  $handler);$r->push_handlers(PerlHandler => 
  $handler_bf);
  print STDERR "They match\n ($handler) = ($handler_bf)\n" if ($handler 
  eq $handler_bf);
   
   
  When I run the code I get the following error:-
   
  MyMod::Apache::Multiplex Matched /test/ to MyMod::Apache::Test 
  (MyMod::Apache::Test) for /mod_perl_push_handlers: Not a subroutine name 
  or CODE reference! at /usr/local/lib/perl//MyMod/Apache/Multiplex.pm line 
  101.They match (MyMod::Apache::Test) = 
(MyMod::Apache::Test)
   
  WHEREAS if I use the following code:-
   
  
  #$r->push_handlers(PerlHandler => 
  $handler);$r->push_handlers(PerlHandler => 
  $handler_bf);
  print STDERR "They match\n ($handler) = ($handler_bf)\n" if ($handler 
  eq $handler_bf);
   
  It works and I get this output :-
   
  MyMod::Apache::Multiplex Matched /reconciler/test/ to MyMod::Apache::Test 
  (MyMod::Apache::Test) for /They match (MyMod::Apache::Test) = 
  (MyMod::Apache::Test)
   
   
  So I'm still at a loss. I've tried checking for tainted variables as the 
  handler hash which fails is populated by reading the contents of files, 
  whereas the other is simply defined in the script.
  I'm guessing this is something more subtle like a configuration 
  problem.
   
  I've tried stopping a starting apache after making each change to the 
  script. so each test is run on a fresh server.
   
  Anyway, Answers on a Postcard please:-)
   
  Regards
   
  Marty
   


Re: problem with $r->push_handlers()

2002-09-17 Thread Marcin Kasperski

> MyMod::Apache::Multiplex Matched /test/ to MyMod::Apache::Test
> (MyMod::Apache::Test) for /
> mod_perl_push_handlers: Not a subroutine name or CODE reference! at
> /usr/local/lib/perl//MyMod/Apache/Multiplex.pm line 101.
> They match
>  (MyMod::Apache::Test) = (MyMod::Apache::Test)

I have observed similar problem myself. I got the same error when I
wrote in my startup.pl

Apache->push_handlers("PerlChildInitHandler",
  \&MyApp::Main::on_child_init);

when I replaced it with 

Apache->push_handlers("PerlChildInitHandler",
  sub { MyApp::Main::on_child_init(); });

it works as expected.


-- 
( Marcin Kasperski   | You have the right to peace, fun, and productive  )
( http://www.mk.w.pl |and enjoyable work. (Beck) )
()
( Nie gub zgłoszeń błędów: http://www.mk.w.pl/narzedzia/narzedzia_bugewid)



Re: problem with $r->push_handlers()

2002-09-17 Thread Martin Moss

You are a star!!!

I ammended your syntax slightly
 and did this:-

my $sub_string='sub { '.$handler_bf.'($r) };';
$r->push_handlers(PerlHandler => eval $sub_string);

Otherwise The handler routine of my handler module doesn't get passed the
Apache object as it's first argument.

It seems to work fine. Thank you.

One point to ask, Is this less efficient, as I'm passing an anonynmous
subroutine around rather than a code reference?

I can finally go to bed :-)

Kind regards

Marty



- Original Message -
From: "Marcin Kasperski" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, September 18, 2002 12:55 AM
Subject: Re: problem with $r->push_handlers()


> > MyMod::Apache::Multiplex Matched /test/ to MyMod::Apache::Test
> > (MyMod::Apache::Test) for /
> > mod_perl_push_handlers: Not a subroutine name or CODE reference! at
> > /usr/local/lib/perl//MyMod/Apache/Multiplex.pm line 101.
> > They match
> > (MyMod::Apache::Test) = (MyMod::Apache::Test)
>
> I have observed similar problem myself. I got the same error when I
> wrote in my startup.pl
>
> Apache->push_handlers("PerlChildInitHandler",
>   \&MyApp::Main::on_child_init);
>
> when I replaced it with
>
> Apache->push_handlers("PerlChildInitHandler",
>   sub { MyApp::Main::on_child_init(); });
>
> it works as expected.
>
>
> --
> ( Marcin Kasperski   | You have the right to peace, fun, and
ctive  )
> ( http://www.mk.w.pl |and enjoyable work.
   )
>
(---
-)
> ( Nie gub zgłoszeń błędów:
p://www.mk.w.pl/narzedzia/narzedzia_bugewid)
>




Not a subroutine name... (was Re: problem with $r->push_handlers())

2002-09-19 Thread Marcin Kasperski

> > mod_perl_push_handlers: Not a subroutine name or CODE reference!
>
> I have observed similar problem myself. I got the same error when I
> wrote in my startup.pl
> 
> Apache->push_handlers("PerlChildInitHandler",
> \&MyApp::Main::on_child_init);
> 
> when I replaced it with 
> 
> Apache->push_handlers("PerlChildInitHandler",
> sub { MyApp::Main::on_child_init(); });
> 
> it works as expected.

It is probably worth noting, that in my opinion the first syntax
should work and there is something wrong in mod_perl code...

Is it something 'well known' or 'by design'?