On Sat, 26 Aug 2000, Philip Molter wrote:

> On Sat, Aug 26, 2000 at 01:56:18PM +0200, Stas Bekman wrote:
> : On Fri, 25 Aug 2000, Philip Molter wrote:
> : 
> : Do you have the two packages in the same file like you have presented
> : below? I guess they aren't since you have '1;' just before the declaration
> : of the second package. If they live in two different files obviously that
> : 'use Object::SubObj' is mising, see the code below. Object doesn't know
> : about Object::SubObj if you don't tell it about it.
> : 
> : So how exactly your files are organized?
> 
> Actually, that '1;' was a mistake.  Yes, they are both in the same
> file, and no, that '1;' is not really there.

The following is a known kludge, but it doesn't seem to apply in your
case (I thought you might use it in PerlHandler)

=head1 More package name related issues

If you have the following:

  PerlHandler Apache::Work::Foo
  PerlHandler Apache::Work::Foo::Bar

And you make a request that pulls in C<Apache/Work/Foo/Bar.pm> first,
then the C<Apache::Work::Foo> package gets defined, so mod_perl does
not try to pull in C<Apache/Work/Foo.pm>


> : > I have a module with some code like this:
> : >
> : >   package Object;
> :
> : =>  use Object::SubObj;
> : 
> : >   sub new {
> : >     my $class = shift;
> : >     return bless {}, $class;
> : >   }
> : >
> : >   sub SubObj {
> : >     Object::SubObj->new();
> : >   }
> : >
> : >   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();

How about:

        $sub = Object::SubObj();

Your sub 'SubObj' isn't a method, so you should call it as a function and
not a method.


> : > 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]
> : > 
> : 
> : 
> : 
> : _____________________________________________________________________
> : Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
> : http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
> : mailto:[EMAIL PROTECTED]   http://apachetoday.com http://jazzvalley.com
> : http://singlesheaven.com http://perlmonth.com   perl.org   apache.org
> : 
> 
> * Philip Molter
> * Data Foundry International
> * http://www.datafoundry.net/
> * [EMAIL PROTECTED]
> 



_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://jazzvalley.com
http://singlesheaven.com http://perlmonth.com   perl.org   apache.org


Reply via email to