|
Posted by J Krugman on March 3, 2005, 5:47 pm
Please log in for more thread options
What are the techniques for a module to find its config file? It's
a chicken/egg problem, since the location of the config file is
itself a parameter that may (or must) be configured.
One technique I can think of is to make the config file itself a
module; e.g. the config file for module Foo is the file corresponding
to the module Foo::Config; if Perl can find Foo.pm, it can presumably
also find Foo/Config.pm (or FooConfig.pm, etc.).
My boss, however, hates the idea of config files containing Perl
code, however simple the code. He wants config files with the
simplest possible syntax, that even non-programmers will feel
comfortable with. Moreover, he wants it to be possible to put the
config file anywhere the user wants it, irrespective of the location
of the module and of the Perl module libraries in general. This
is all very reasonable and user-friendly, but leaves me with the
technical problem of how the module is to find its config file (as
I already alluded to, Perl will help with finding module files,
but not with finding any old file).
Is there a general, portable Perl programming technique that enables
a module to find its config file?
Thanks!
jill
--
To s&e^n]d me m~a}i]l r%e*m?ov[e bit from my a|d)d:r{e:s]s.
|
|
Posted by J Krugman on March 3, 2005, 7:18 pm
Please log in for more thread options
What are the techniques for a module to find its config file? It's
a chicken/egg problem, since the location of the config file is
itself a parameter that may (or must) be configured.
One technique I can think of is to make the config file itself a
module; e.g. the config file for module Foo is the file corresponding
to the module Foo::Config; if Perl can find Foo.pm, it can presumably
also find Foo/Config.pm (or FooConfig.pm, etc.).
My boss, however, hates the idea of config files containing Perl
code, however simple the code. He wants config files with the
simplest possible syntax, that even non-programmers will feel
comfortable with. Moreover, he wants it to be possible to put the
config file anywhere the user wants it, irrespective of the location
of the module and of the Perl module libraries in general. This
is all very reasonable and user-friendly, but leaves me with the
technical problem of how the module is to find its config file (as
I already alluded to, Perl will help with finding module files,
but not with finding any old file).
Is there a general, portable Perl programming technique that enables
a module to find its config file?
Thanks!
jill
P.S. I posted this to comp.lang.perl.modules, but then I realized
that that ng is basically moribund, and decided to post it here.
--
To s&e^n]d me m~a}i]l r%e*m?ov[e bit from my a|d)d:r{e:s]s.
|
|
Posted by Sherm Pendley on March 3, 2005, 2:40 pm
Please log in for more thread options
J Krugman wrote:
> What are the techniques for a module to find its config file? It's
> a chicken/egg problem, since the location of the config file is
> itself a parameter that may (or must) be configured.
Nothing says you have to install .pm files as-is - you could always edit
them before installing them.
Code the path into the module like this:
my $config_path = '__REPLACE_ME__';
In Makefile.PL, once the correct value has been provided by the user, open
the .pm file and read it in. Do the appropriate replacement, and write it
back out.
> P.S. I posted this to comp.lang.perl.modules, but then I realized
> that that ng is basically moribund, and decided to post it here.
I think you're a bit confused... "Here" is the same group, an hour later.
And this group isn't dead, it's just resting. :-)
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net Hire me! My resume: http://www.dot-app.org
|
|
Posted by John Bokma on March 3, 2005, 7:29 pm
Please log in for more thread options
J Krugman wrote:
> Is there a general, portable Perl programming technique that enables
> a module to find its config file?
If it can be anywhere, that's going to be hard, something must specify
where it resides.
I would probably make a read_configuration method. If a filename is given,
it would read that. If not, it would check for an environment variable, if
not, it would check the path(s) in @INC for it (starting with the current
working directory). Maybe before the @INC some default places, which depend
on the platform.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
|
| Similar Threads | Posted | | A do-file location: how the code inside that do-file find it? | January 20, 2008, 12:32 am |
| Override System Module With Newer Local Version (noob) | February 2, 2006, 7:36 am |
| New version of Config::Model (v0.616): INI file support | December 6, 2007, 1:06 pm |
| [ANNOUNCE] Config::Model - Framework for semantic validation of config data | March 20, 2006, 10:07 am |
| File::Find on Solaris v8-10 | August 1, 2005, 11:06 am |
| File::Find Win32 Examples | October 26, 2005, 11:51 am |
| can't find xml-parsing module... | May 27, 2006, 5:30 am |
| Can't find Module IP::Address | February 27, 2008, 3:42 pm |
| Need to find a module which can remove attachment from emails | July 15, 2004, 6:18 pm |
| How to find all modules, required by a given CPAN module | September 4, 2005, 2:25 am |
|