Stevan Little > Config-Constants-0.03 > Config::Constants

Download:
Config-Constants-0.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  

NAME ^

Config::Constants - Configuration variables as constants

SYNOPSIS ^

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

DESCRIPTION ^

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/Bar.pm,-ft/lib/Bar/Baz.pm 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.

METHODS ^

import

TO DO ^

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

BUGS ^

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

CODE COVERAGE ^

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/Constants.pm                   95.2   90.9    n/a   75.0    n/a   31.6   91.8
 Config/Constants/Perl.pm             100.0   50.0   33.3  100.0  100.0   23.8   82.0
 Config/Constants/XML.pm              100.0   50.0   33.3  100.0    n/a   23.9   90.6
 Config/Constants/XML/SAX/Handler.pm   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
 ----------------------------------- ------ ------ ------ ------ ------ ------ ------

SEE ALSO ^

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

AUTHOR ^

stevan little, <stevan@iinteractive.com>

COPYRIGHT AND LICENSE ^

Copyright 2005 by Infinity Interactive, Inc.

http://www.iinteractive.com

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

syntax highlighting: