The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

OpenInteract2::Config::Base - Represents a server base configuration

SYNOPSIS

 # Sample base configuration
 
 website_dir      /path/to/mysite
 config_type      ini
 config_class     OpenInteract2::Config::IniFile
 config_dir       conf
 config_file      server.ini
 package_dir      pkg

 # Open an existing base config
 
 my $bc = OpenInteract2::Config::Base->new({
                    website_dir => '/path/to/mysite' });
 my $bc = OpenInteract2::Config::Base->new({
                    filename => '/path/to/mysite/conf/base-alt.conf' });

 # Create a new one and write it with the default filename
 
 my $bc = OpenInteract2::Config::Base->new;
 $bc->website_dir( '/path/to/mysite' );
 $bc->config_type( 'ini' );
 $bc->config_class( 'OpenInteract2::Config::IniFile' );
 $bc->config_dir( 'conf' );
 $bc->config_file( 'server.ini' );
 $bc->package_dir( 'pkg' );
 $bc->write;

DESCRIPTION

A base configuration enables you to easily bootstrap an OpenInteract server configuration with just a little information.

METHODS

Class Methods

new( [ \%params ] )

Creates a new base config object. You can initialize it with as many parameters as you like if you are creating one from scratch.

You can also pass in one of:

filename
website_dir

And the constructor will read values from filename or the filename returned by create_filename() with website_dir. The constructor will also set the filename property to the file from which the values were read.

Returns: A OpenInteract2::Config::Base object.

read_config( $filename )

Reads configuration values from $filename and returns the configured key/value pairs. When reading in the file we sskip all blank lines as well as lines beginning with a '#' for comments. Extra space is stripped from the beginning and ending of all keys and values.

Returns: Hashref of config values from $filename.

create_website_filename( $website_directory )

Creates a typicaly configuration filename given $website_directory. This is:

 $website_directory/BASE_CONF_DIR/BASE_CONF_FILE

where BASE_CONF_DIR and BASE_CONF_FILE are from OpenInteract2::Constants.

An exception is thrown if $directory is not provided. We do not check whether $directory is a valid directory.

Returns: a potential filename for a base config object

create_filename( $directory )

Creates a typical configuration filename given $directory. This is:

 $directory/BASE_CONF_FILE

where BASE_CONF_FILE is from OpenInteract2::Constants.

An exception is thrown if $directory is not provided. We do not check whether $directory is a valid directory.

Returns: a potential filename for a base config object

Object Methods

initialize( \%params )

You will probably never call this as it is only used from the constructor.

Returns: a OpenInteract2::Config::Base object with relevant properties from \%params set.

clean_dir( $property_name )

Remove the trailing '/' from the directory specified by $property_name. Sets the property in the object and returns the cleaned directory.

Example:

  $bc->clean_dir( 'config_dir' );
  $bc->clean_dir( 'website_dir' );

Returns: the cleaned directory.

get_server_config_file()

Puts together the properties 'website_dir', 'config_dir' and 'config_file' to create a fully qualified filename.

Returns: full filename for the server config.

save_config()

Writes the configured values from the object to a file. If you do not set a filename before calling this the method will create one for you using create_filename() and the value from the website_dir property.

If you do not have all the properties defined the method will throw an exception.

Returns: the filename to which the configuration was written.

PROPERTIES

website_dir: Root directory of the website

config_type: Type of configuration site is using

config_class: Class used to read server configuration

config_dir: Directory where configuration is kept, relative to website_dir

config_file: Name of configuration file in config_dir

package_dir: Directory where packages are kept, relative to website_dir.

filename: Location of base_configuration file. Not written out to the base configuration file.

BUGS

None known.

TO DO

Nothing known.

SEE ALSO

Class::Accessor

COPYRIGHT

Copyright (c) 2001-2004 Chris Winters. All rights reserved.

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

AUTHORS

Chris Winters <chris@cwinters.com>