This is what I thought but I am not getting behaviour that indicates this.
To explain.

I have two applications, a forums program and a basic portal. Both of these
run on the same server under virtual servers. Both .pl's have a section
where they switch into the UNIVERSAL package and setup some global routines.
For example:

in forums.pl

sub main {
        # init type stuff
}

sub loader {
}

package UNIVERSAL;

sub print_error {
        # Global error logging routine
}

The portal.pl has the equivalent. The problem I am getting is that under
some as of yet unknown circumstances the print_error from portal is coming
up in forums. But, and here's the bit that's confusing me, under normal
operating they seem to coexist fine. forums.pl gets it's print_error (i.e.
somewhere is calling $self->print_error) and portal.pl get's it's. How is it
possible for this to happen at all? If the UNIVERSAL namespace is shared I
would have thought one or the other (the last one?) would "get" the
print_error sub and the other loses out but at some point they seem to
coexist just fine. Whilst at some other point they as expected and one gets
the others. Any theories?

Matt.

-----Original Message-----
From: Perrin Harkins [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, 13 February 2002 7:45 AM
To: Morton-Allen, Matthew; [EMAIL PROTECTED]
Subject: Re: mod_perl + UNIVERSAL

> However both applications make use of the UNIERVSAL package to create
> universally accessible methods (to return the current database handle for
> example) within the application.

Better to put those into a package of your own and call them with
fully-qualified names, or import them as Tatsuhiko demonstrated.

> The thing is I am getting some weird behaviour where one application seems
> to be getting code from the other. In theory this isn't possible with the
> separated namespaces. I suspect my UNIERVSAL use is the problem.

There is just one Perl interpreter per process, and thus one namespace and
one UNIVERSAL package.  If you try to create two different versions of the
sub UNIVERSAL::foo() it won't work: there can be only one.  This is true for
any package name, actually.  If you need separate subs, name them
differently or put them in separate packagaes.

- Perrin

Reply via email to