Re: making user definable variables really global
Dumas Patrice <[email protected]> Tue, 17 Jun 2003 17:36:30 +0200
| Newsgroups | gmane.comp.tex.texi2html.devel |
|---|---|
| Message-ID | <[email protected]> |
> I don't remember the exact syntax. Does that work? At the least, I meant:
>
> cat >file.init <<EOF
> package Texi2HTML::Config;
> $setting1="some data";
> $setting2="some other data";
> $function1=sub { some function };
> EOF
It seemd to me that it is the other way around: we have a module file
Texi2HTML::Config (Texi2html/Config.pm) and in Texi2html/Config.pm
users files are sourced such that the symbols are not global.
example:
texi2html.pl:
===========================================================
use Texi2HTML::Config;
# find the dirs containing files to require with --init_file
....
# pass them to Texi2HTML::Config:
Texi2HTML::Config::load_dirs(@init_dirs);
===========================================================
Texi2html/Config.pm (inspirated by CPAN::Config)
===========================================================
package Texi2HTML::Config
sub load_dirs
{
foreach my $dir (@_)
{
unshift @INC, $dir;
evel {require Texi2html::Config;}
shift @INC;
}
}
> The CPAN module distributed with Perl should have an example of this,
> but maybe it is too complex. I did something like this for one program
> I wrote:
>
> # Load our config file.
> use lib "$ENV{'HOME'}/lib/perl5/myperl";
> use PageMe::Config;
>
> Then in the config file (~/lib/perl5/myperl/PageMe/Config.pm):
>
> %PageMe::Config =
> (
> 'PagerEmailAddress' => q/[email protected]/,
> 'debug' => 0
> );
>
> 1;
> __END__
The problem with that kind of syntax is that the file name must be known
by advance (although the directory don't have to). However it could be
possible that the following works:
texi2html.pl:
===========================================================
use Texi2HTML::Config;
# find the files to require with --init_file
....
# pass them to Texi2HTML::Config:
Texi2HTML::Config::load_files(@init_files);
===========================================================
Texi2html/Config.pm (or in the texi2html.pl file itself)
===========================================================
package Texi2HTML::Config
sub load_files
{
foreach my $file (@_)
{
evel {require $file;}
}
}
I will test that soon.
> $PageMe::Config{'PagerEmailAddress'}
This or
$PageMe::Config::PagerEmailAddress
is about the same for me.
The nice thing with $PageMe::Config{'PagerEmailAddress'} is that only %Config
has to be exported, however there is no checking on the hash fields in that
case.
Pat