Re: Problem with "use" getting the wrong file

2001-08-16 Thread Tim Tompkins

If you use/require with the path as Perrin suggested, these libs will
compile in separately.  One caveat, watch for clashing of exported symbols.

My personal preference is to call a config routine from a single package
that returns the desired info.

# file: foo/same_name.pl
use My::Configuration;
my(%conf) = Configuration("foo");

#file: bar/same_name.pl
use My::Configuration;
my(%conf) = Configuration("bar");

This way you're not attempting to recompile configuration data each time you
load the script (that kinda defeats the purpose of running modperl).  Your
My::Configuration package can load it's data from any number of sources, or
just have it hard coded in the package.  Note that there are a number of
variations to this, but in general, this makes the most sense.



Thanks,

Tim Tompkins
--
Programmer
http://www.arttoday.com/
http://www.rebelartist.com/
--
- Original Message -
From: "ryc" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, August 16, 2001 3:38 PM
Subject: Re: Problem with "use" getting the wrong file


> > I have two mod_perl programs on my site. One is in the directory "inr2",
> > and the other is in the directory "otherinr2".
> >
> > These mod_perl programs have exactly the same code. Both of them do:
> > use cfg;
> >
> > where cfg.pm is a file that's in both inr2 and otherinr2, but it's
> > different in these directories.
> >
> > But the code in "otherinr2" is getting the cfg.pm from "inr2" since they
> > have the same filename and relative paths. How can I make the "use"
> > command not act braindead about this? Is there a CPAN module that I can
> > import to overload the use command with something that takes the full
> > pathname into account perhaps?
>
> You can specify a full path to use/require.  Check man perlfunc for the
> details.  You can also specify a path relative to the current working
> directory if you don't like hard-coding full paths in your scripts.
> - Perrin

I have learned recently(and the original poster as well) that despite two
files having different file names, and doing a "require
/full/path/to/file.pl", modperl will only compile the file once because they
both have the same package name.

I have yet to find a solution to the problem that I like... I have a file
that contains the database information (username, password, db name, connect
functions, ect) and for a while I couldnt figure out why two scripts using
two seperate files for database info would connect to the wrong database
heh.

ryan







Re: Problem with "use" getting the wrong file

2001-08-16 Thread Perrin Harkins

> I have learned recently(and the original poster as well) that despite two
> files having different file names, and doing a "require
> /full/path/to/file.pl", modperl will only compile the file once because
they
> both have the same package name.

No, I don't think that's correct.  Perl will compile both files if they have
different paths and you specify the full path.  However, if they do have the
same package name, the second one will overwrite the first one, which is
probably not what you intended.

> I have yet to find a solution to the problem that I like... I have a file
> that contains the database information (username, password, db name,
connect
> functions, ect) and for a while I couldnt figure out why two scripts using
> two seperate files for database info would connect to the wrong database
> heh.

There are tons of solutions for having separate config files for two
scripts.  You could name the config files differently and call the right one
from each script.  You could use a path relative to the current directory in
your require statement.  You could one conf file with one big hash of
configuration that is keyed on a variable you set with PerlSetVar to
something different for each script.

- Perrin




Re: Problem with "use" getting the wrong file

2001-08-16 Thread ryc

> > I have two mod_perl programs on my site. One is in the directory "inr2",
> > and the other is in the directory "otherinr2".
> >
> > These mod_perl programs have exactly the same code. Both of them do:
> > use cfg;
> >
> > where cfg.pm is a file that's in both inr2 and otherinr2, but it's
> > different in these directories.
> >
> > But the code in "otherinr2" is getting the cfg.pm from "inr2" since they
> > have the same filename and relative paths. How can I make the "use"
> > command not act braindead about this? Is there a CPAN module that I can
> > import to overload the use command with something that takes the full
> > pathname into account perhaps?
>
> You can specify a full path to use/require.  Check man perlfunc for the
> details.  You can also specify a path relative to the current working
> directory if you don't like hard-coding full paths in your scripts.
> - Perrin

I have learned recently(and the original poster as well) that despite two
files having different file names, and doing a "require
/full/path/to/file.pl", modperl will only compile the file once because they
both have the same package name.

I have yet to find a solution to the problem that I like... I have a file
that contains the database information (username, password, db name, connect
functions, ect) and for a while I couldnt figure out why two scripts using
two seperate files for database info would connect to the wrong database
heh.

ryan





Re: Problem with "use" getting the wrong file

2001-08-16 Thread Andy Turner

On Thu, Aug 16, 2001 at 05:20:07PM -0400, Philip Mak wrote:
> But the code in "otherinr2" is getting the cfg.pm from "inr2" since they
> have the same filename and relative paths. How can I make the "use"
> command not act braindead about this? Is there a CPAN module that I can
> import to overload the use command with something that takes the full
> pathname into account perhaps?

How about:

do "cfg.pm";

But I'm not sure it will do what you actually want.  You're gonna have name
space collisions if you're using the cfg name space for anything.  About the
only way it could work is if all you did was export some symbols.  If that's
all you're doing then you might be better of by just making them .pl files
and not changing name spaces (and thus importing all symbols without having
to use Exporter).

-- 
Andy <[EMAIL PROTECTED]> - http://anime.mikomi.org/ - Community Anime Reviews
  "All the pain, swelling and immobility of a fracture without the
  inconvenience of a fracture itself."
 -- Lintilla, HHGTTG Radio Show



Re: Problem with "use" getting the wrong file

2001-08-16 Thread Perrin Harkins


> I have two mod_perl programs on my site. One is in the directory "inr2",
> and the other is in the directory "otherinr2".
>
> These mod_perl programs have exactly the same code. Both of them do:
> use cfg;
>
> where cfg.pm is a file that's in both inr2 and otherinr2, but it's
> different in these directories.
>
> But the code in "otherinr2" is getting the cfg.pm from "inr2" since they
> have the same filename and relative paths. How can I make the "use"
> command not act braindead about this? Is there a CPAN module that I can
> import to overload the use command with something that takes the full
> pathname into account perhaps?

You can specify a full path to use/require.  Check man perlfunc for the
details.  You can also specify a path relative to the current working
directory if you don't like hard-coding full paths in your scripts.
- Perrin




Re: Problem with "use" getting the wrong file

2001-08-16 Thread Remco Schaar

On Thu, 16 Aug 2001, Philip Mak wrote:

Hi,

> I have two mod_perl programs on my site. One is in the directory "inr2",
> and the other is in the directory "otherinr2".
> 
> These mod_perl programs have exactly the same code. Both of them do:
> use cfg;
> 
> where cfg.pm is a file that's in both inr2 and otherinr2, but it's
> different in these directories.
> 
> But the code in "otherinr2" is getting the cfg.pm from "inr2" since they
> have the same filename and relative paths. How can I make the "use"
> command not act braindead about this? Is there a CPAN module that I can
> import to overload the use command with something that takes the full
> pathname into account perhaps?

try a
do 'cfg.pm';
to force the compile

otherwise you might want to take a look at Apache::Reload on CPAN.

remco