Config::Constants::XML - Configuration loader for Config::Constants


Config-Constants documentation Contained in the Config-Constants distribution.

Index


Code Index:

NAME

Top

Config::Constants::XML - Configuration loader for Config::Constants

SYNOPSIS

Top

  use Config::Constants::XML;

DESCRIPTION

Top

This module reads and parses XML files as configuration files that look like this:

  <config>
      <module name='Foo::Bar'>
          <constant name='BAZ' value='the coolest module ever' />
      </module>
  </config>  

It is also possible to do more complex constant value types, like this:

  <config>
      <module name='Foo::Bar2'>
            <constant name='BAZ' type='ARRAY'>
              [ 1, 2, 3 ]
            </constant>
      </module>
      <module name='Bar::Baz2'>
          <constant name='FOO' type='HASH'>
              { test => 'this', out => 10 }
          </constant>
          <constant name='BAR' type='My::Object'>
              My::Object->new()
          </constant>        
      </module>
  </config>

The type parameter much match the value returned after eval-ing the text.

You can also include other configurations into the current one like this:

  <config> 
      <include path='conf/base_conf.xml' />
      <module name='Foo::Bar'>
          <constant name='BAZ' value='the coolest module ever' />
      </module>
  </config>  

The configurations are processed in order, so in this example, anything set in conf/base_conf.xml will be shadowed by anything set in the current xml.

METHODS

Top

new ($file)

This takes the file, loads, parses and stores the resulting configuration.

modules

This will return an array of modules in this configuration.

constants ($module_name)

Given a $module_name, this will return an array of hash references for each constant specified.

TO DO

Top

BUGS

Top

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

Top

I use Devel::Cover to test the code coverage of my tests, see the Config::Constants module for more information.

SEE ALSO

Top

XML::SAX

AUTHOR

Top

stevan little, <stevan@iinteractive.com>

COPYRIGHT AND LICENSE

Top


Config-Constants documentation Contained in the Config-Constants distribution.

package Config::Constants::XML;

use strict;
use warnings;

our $VERSION = '0.02';

use base 'Config::Constants::Perl';

use Config::Constants::XML::SAX::Handler;
use XML::SAX::ParserFactory;

sub _init {
    my ($self, $file) = @_;
    (-e $file && -f $file)
        || die "Bad config file '$file' either it doesn't exist or it's not a file";    
    my $handler = Config::Constants::XML::SAX::Handler->new();
    my $p = XML::SAX::ParserFactory->parser(Handler => $handler);
    $p->parse_uri($file);
    $self->{_config} = $handler->config();
}

1;

__END__