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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.