View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Stevan Little > Config-Constants-0.03 > Config::Constants



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 0.03   Source  


Config::Constants - Configuration variables as constants


  # in your perl modules
  package Foo::Bar;
  use Config::Constants qw/BAZ/;
  sub foo_bar { print "Foo::Bar is " . BAZ }
  # in the conf.xml
      <module name='Foo::Bar'>
            <constant name='BAZ' value='the coolest module ever' />
  # or in the
      'Foo::Bar' => {
          'BAZ' => 'the coolest module ever',
  # in the in your perl code
  use Config::Constants xml => 'conf.xml';
  # or ...
  use Config::Constants perl => '';
  use Foo::Bar;
  Foo::Bar::foo_bar(); # prints "Foo::Bar is the coolest module ever"


Using configuration files can help to make you code more flexible. However, this flexiblity comes at a cost of reading and parsing the configuration file, and then making the configuration information available to your application. Most times this is a trade off which is well worth the price, and which works well in many situations.

However, sometimes what you want to configure is really very simple, and it can feel like overengineering to have to use a config object instance and fetch the config variable, and that is where this module comes into play.

Config::Constants allows you to avoid all that overhead by loading the configuration file very early (compile time) and using perl's compile time constant folding to inline your configuration variables.

If you want to see this module in action. Just run this command from within this distribution's folder, and compare what you see to the actual files.

  perl -I lib/ -MO=Deparse,-ft/lib/Foo/,-ft/lib/Bar/ t/11a_Config_Constants_w_Perl.t

Interaction with OO

This module will work for OO modules, however it does have some restructions.

Interaction with Apache & mod_perl

When developing with mod_perl is it useful to use a module like Apache::Reload to help reload modules which have been changed. Because of the way Config::Constants handles loading of constants, this should not require the config to be reloaded. However, if the config file itself is changed, it will require you to restart Apache in order for those changes to take effect.

Future plans include making a mod_perl handler which can be used to automatically reload the config file if it is modified.




A means to automatically reload the config while using Apache/mod_perl
More tests
re-write the docs, they are horrid


None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it.


I use Devel::Cover to test the code coverage of my tests, below is the Devel::Cover report on this module test suite.

 ----------------------------------- ------ ------ ------ ------ ------ ------ ------
 File                                  stmt branch   cond    sub    pod   time  total
 ----------------------------------- ------ ------ ------ ------ ------ ------ ------
 Config/                   95.2   90.9    n/a   75.0    n/a   31.6   91.8
 Config/Constants/             100.0   50.0   33.3  100.0  100.0   23.8   82.0
 Config/Constants/              100.0   50.0   33.3  100.0    n/a   23.9   90.6
 Config/Constants/XML/SAX/   96.7   82.4    n/a  100.0  100.0   20.7   92.7
 ----------------------------------- ------ ------ ------ ------ ------ ------ ------
 Total                                 97.0   79.4   33.3   91.2  100.0  100.0   90.3
 ----------------------------------- ------ ------ ------ ------ ------ ------ ------


generics - this module is largely based on ideas from the generics pragma I wrote.


stevan little, <>


Copyright 2005 by Infinity Interactive, Inc.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: