NAME

Config::Context::XMLSimple - Use XML-based config files with Config::Context

SYNOPSIS

use Config::Context;

my $config_text = '
    <opt>

      <Location name="/users">
        <title>User Area</title>
      </Location>

      <LocationMatch name="\.*(jpg|gif|png)$">
        <image_file>1</image_file>
      </LocationMatch>

    </opt>
';

my $conf = Config::Context->new(
    string        => $config_text,
    driver        => 'XMLSimple',
    match_sections => [
        {
            name          => 'Location',
            match_type    => 'path',
        },
        {
            name          => 'LocationMatch',
            match_type    => 'regex',
        },
    ],
);

my %config = $conf->context('/users/~mary/index.html');

use Data::Dumper;
print Dumper(\%config);
--------
$VAR1 = {
    'title'         => 'User Area',
    'image_file'    => undef,
};

my %config = $conf->context('/users/~biff/images/flaming_logo.gif');
print Dumper(\%config);
--------
$VAR1 = {
    'title'         => 'User Area',
    'image_file'    => 1,
};

DESCRIPTION

This module uses XML::Simple to parse XML config files for Config::Context. See the Config::Context docs for more information.

DRIVER OPTIONS

By default, it is assumed that the RootName of your configuration files is <opt>. For instance:

<opt>
 <Location /users>
  <title>Users Area</title>
 </Location>
<opt>

If you change this to some other element, then you must specify the RootName parameter in driver_options:

# Change the name of the root block to <Config>..</Config>
my $conf = Config::Context->new(
    driver => 'XMLSimple',
    driver_options => {
       XMLSimple = > {
           RootName  => 'Config',
       },
    },
);

DEFAULT OPTIONS

By default the options passed to XML::Simple are:

KeyAttr    => [],
ForceArray => \@section_names,

...where @section_names is a list of the sections as defined in match_sections. This makes for consistently formatted configurations that are similar to those generated by the other drivers.

You can change this behaviour by passing a different value to driver_params to new:

my $conf = Config::Context->new(
    driver => 'XMLSimple',
    driver_options => {
       XMLSimple = > {
           ForceArray  => 1,
       },
    },
);

INCLUDE FILES

You include XML files within other XML files by using the XInclude syntax. To include a file called other_config.xml you would use:

<opt>
  <xi:include href="other_config.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
</opt>

Files included this way are included in the same scope. For instance:

# config.xml
<opt>
 <Location /users>
  <title>Users Area</title>
 </Location>
 <xi:include href="other_config.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<opt>

# other_config.xml
<opt>
 <Location /users>
  <title>Members Area</title>
 </Location>
</opt>

In this example, the raw config will look like

{
    'location' => {
        'users' => {
            'title'         => 'Members Area',
        }
    }
}

And the config matching users will look like:

{
    'title'         => 'Members Area',
}

Note that the placement of the <xi:include> tag within a block (e.g. top or bottom) doesn't matter. Contents are merged into the block so that the included file has precedence.

CONSTRUCTOR

new(...)

my $driver = Config::Context::XMLSimple->new(
    file             => $config_file,
    options          => {
        # ...
    }
);

or:

my $driver = Config::Context::XMLSimple->new(
    string           => $config_string,
    options          => {
        # ...
    }
);

Returns a new driver object, using the provided options.

METHODS

parse()

Returns the data structure for the parsed config.

files()

Returns a list of all the config files read, including any config files included in the main file.

config_modules

Returns the modules required to parse the config. In this case: XML::Simple, XML::SAX and XML::Filter::XInclude.

CAVEATS

Lower Case names not supported with this driver

The lower_case_names option is not supported used with this driver. If you specify it, it will produce a warning.

SEE ALSO

Config::Context
CGI::Application::Plugin::Config::Context
XML::Simple

COPYRIGHT & LICENSE

Copyright 2004-2005 Michael Graham, All Rights Reserved.

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