Apache2::ASP::ConfigLoader - Universal access to the configuration.


Apache2-ASP documentation Contained in the Apache2-ASP distribution.

Index


Code Index:

NAME

Top

Apache2::ASP::ConfigLoader - Universal access to the configuration.

SYNOPSIS

Top

  use Apache2::ASP::ConfigLoader;

  my $Config = Apache2::ASP::ConfigLoader->load();

  # $Config is a Apache2::ASP::Config object.

DESCRIPTION

Top

This package solves the "How do I get my config?" problem most web applications end up with at some point.

Config data is cached on a per-path basis. Paths are full - i.e. /usr/local/projects/mysite.com/conf/apache2-asp-config.xml - so there should never be a clash between two different configurations on the same web server, even if it is running multiple websites as VirtualHosts.

PUBLIC METHODS

Top

load( )

Returns a Apache2::ASP::Config object.

BUGS

Top

It's possible that some bugs have found their way into this release.

Use RT http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP to submit bug reports.

HOMEPAGE

Top

Please visit the Apache2::ASP homepage at http://www.devstack.com/ to see examples of Apache2::ASP in action.

AUTHOR

Top

John Drago <jdrago_999@yahoo.com>

COPYRIGHT AND LICENSE

Top


Apache2-ASP documentation Contained in the Apache2-ASP distribution.

package Apache2::ASP::ConfigLoader;

use strict;
use warnings 'all';
use Carp 'confess';
use Apache2::ASP::ConfigFinder;
use Apache2::ASP::ConfigParser;
use XML::Simple ();
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';

our $Configs = { };


#==============================================================================
sub load
{
  my ($s) = @_;
  
  my $path = Apache2::ASP::ConfigFinder->config_path;
  return $Configs->{$path} if $Configs->{$path};
  
  my $doc = XML::Simple::XMLin( $path,
    SuppressEmpty => '',
    ForceArray => [qw/ var setting location /],
    KeyAttr => { },
  );
  
  (my $where = $path) =~ s/\/conf\/[^\/]+$//;
  return $Configs->{$path} = Apache2::ASP::ConfigParser->new->parse( $doc, $where );
}# end parse()

1;# return true:

__END__