Apache2::ASP::ConfigFinder - Universal configuration finder


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

Index


Code Index:

NAME

Top

Apache2::ASP::ConfigFinder - Universal configuration finder

SYNOPSIS

Top

  # You will probably never use this class, but...

  use Apache2::ASP::ConfigFinder;

  my $path_to_config = Apache2::ASP::ConfigFinder->config_path();

DESCRIPTION

Top

Finding the configuration is sometimes impossible in web applications.

This package makes it trivial. However you will probably never use this class directly. Use Apache2::ASP::ConfigLoader instead.

PUBLIC METHODS

Top

config_path( )

Returns the full path to the current configuration file - i.e. /usr/local/projects/mysite.com/conf/apache2-asp-config.xml.

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::ConfigFinder;

use strict;
use warnings 'all';
use Cwd 'cwd';

our $CONFIGFILE = 'apache2-asp-config.xml';

#==============================================================================
sub config_path
{
  my $path = $CONFIGFILE;
  
  my $root = $ENV{DOCUMENT_ROOT} || cwd();
  
  # Try test dir:
  if( -f "$root/t/conf/$CONFIGFILE" )
  {
    return "$root/t/conf/$CONFIGFILE";
  }# end if()
  
  # Start moving up:
  for( 1...10 )
  {
    my $path = "$root/conf/$CONFIGFILE";
    return $path if -f $path;
    $root =~ s/\/[^\/]+$//
      or last;
  }# end for()
  
  die "CANNOT FIND '$CONFIGFILE' anywhere under '$root'";
}# end config_path()

1;# return true:

__END__