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?
> 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();
> }
>
> 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]
>
_____________________________________________________________________
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