I'm currently working on a mid-sized project (4 programmers, with 14 components, in 42 scripts and 53 Perl modules, not including stuff from CPAN). Due to the nature of the application, different servers may have one or more of the components installed.
We've attempted to move server specific variables to a configuration module, from which the other modules can get their necessary information. Each of the modules that use the configuration module need to have a chance to register their variables with the configuration module when they're installed.
... And that's where I'm running into problems.
I currently call an 'AddVariable' function from within Makefile.PL:
eval { require Physics::Solar::VSO::Config; }; if ($@) { die "Physics::Solar::VSO::Config not installed"; } Physics::Solar::VSO::Config::AddVariable ( 'REG_DIR', desc => 'location of the registry data. Will be gu +essed if left undefined', default => undef, module => 'registry', ); Physics::Solar::VSO::Config::AddVariable ( 'REG_DUMP', desc => 'location to store pre-parsed registry data +, if defined', default => undef, module => 'registry', );
(I don't think the actual code for storing the variable is significant to the question, as it's more a logic thing, but if you want, I can provide that, too.)
And so we get to the real problem -- how would you handle the configuration such that it's available for a 'make test', but not seen by any other module until you do a 'make install'?
I'm currently storing the configuration info in an xml file in the same directory as the configuration module:
use XML::Simple; my $parserOptions = { cache => [ 'memshare' ], NoAttr => 1, SuppressEmpty => undef, }; require Exporter; our @ISA = qw(Exporter); our @EXPORT = (); ( my $configFile = __FILE__ ) =~ s/\.pm$/.xml/; my $config ||= XMLin( $configFile, %$parserOptions ); our %CONFIG : unique = ( %{ $config->{'CONFIG'} || {} } ); our %C : unique = ( %{ $config->{'C' } || {} } ); our %PERL : unique = ( %{ $config->{'PERL' } || {} } ); our %SHELL : unique = ( %{ $config->{'SHELL' } || {} } ); sub new { my $class = shift; return bless \%CONFIG, ref($class) || $class; } sub AUTOLOAD { (my $constant = our $AUTOLOAD) =~ s/^.*://; no strict 'refs'; if (exists($CONFIG{$constant})) { *{$AUTOLOAD} = sub { return $CONFIG{$constant} }; return &{$AUTOLOAD}; } elsif (exists($PERL{$constant})) { *{$AUTOLOAD} = sub { return $PERL{$constant} }; return &{$AUTOLOAD}; } else { require Carp; Carp::croak "Unknown constant : $constant"; } } # this needs to stay below where %CONFIG and %PERL are populated our @EXPORT_OK = ( keys %CONFIG, keys %PERL );
I've trimmed out the majority of the module, but it should give you the basic idea. Basically, we couldn't decide how to access the values, so some are importing them as constants, others create a config object, etc -- and there are functions to export the configuration as XML, C headers, or shell scripts ... %CONFIG holds the language indendent items.
My current thoughts on how to handle the problem include --
Are there any better suggestions, either for the narrow problem, or to replace my whole configuration logic?
In reply to Handling configuration for multiple modules by jhourcle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |