I have a module with some code like this:                                       
                                                                                
  package Object;                                                               
  sub new {                                                                     
    my $class = shift;                                                          
    return bless {}, $class;                                                    
  }                                                                             
                                                                                
  sub SubObj {                                                                  
    Object::SubObj->new();                                                      
  }                                                                             
                                                        
  1;                                                    
                                                        
  package Object::SubObj;                   
  sub new {                                 
    my $class = shift;                      
    return bless {}, $class;             
  }                                      
                                         
I have a script with code like this:     
                                    
  $obj = Object->new();             
  $sub = Object->SubObj();          
                                    
Now, I can spot the potential problem.  Under regular perl, this
methodology works fine, has been for several years (that's how  
long we've had this module).  Under mod_perl, this setup works  
fine.  It has for several years.  However, on a recent new system,
I decided that this module needed to be preloaded in a startup.pl-type
script, like so:                                                      
                                                                      
  use Object;                                                         
                                                                      
Nothing fancy.  When the script above is called in mod_perl now,      
it goes into an endless loop.  Apparently, the $obj->SubObj(); call   
results in it calling itself continuously, as Object::SubObj is       
mapped to the function, not the class.  To fix it, I did:             
                                                                      
  sub SubObj {                                                        
    'Object::SubObj'->new();                                          
  }                                                                   
                                                                      
Why does this work under regular perl and under mod_perl, but under   
mod_perl with this module preloaded, perl has a problem deciding      
whether this is a function or a class?  Is this a bug in mod_perl's   
methodology or is it just another case of mod_perl catching bad       
programming practice (no comments about the programming practice;     
I only fix it)?                                                       
                                                                      
Is this in the Perl Guide?  If so, I missed it.  If not, would it  
be appropriate to add it as an example?  This was a challenge to   
track down, especially with the way it affected the system (one    
gets very scared running code he knows is going into an endless    
loop in a location he can't determine).

* Philip Molter
* Data Foundry International
* http://www.datafoundry.net/
* [EMAIL PROTECTED]

Reply via email to