Class::Config

Methods From Config Files
Download

Class::Config Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Don Owens
  • Publisher web site:
  • http://search.cpan.org/~dowens/

Class::Config Tags


Class::Config Description

Methods From Config Files Class::Config is a Perl module that generates unique namespaces for new classes that contain methods created from the key/value pairs from hashes in configuration files. This is useful for reusing code, such as modules and scripts for an entire website, but changing certain parameters based on an environment variable, for instance.Method names are generated by capitalizing the first letter and the first letter after each underscore, then adding 'get' in front. For example, if one of the files in @files contains the following: $info = { field1 => 'value1', field2 => , longer_field_name => 'longer value', };the methods getField1(), getField2(), and getLongerFieldName() will be available via the object returned by Class::Config.The files are loaded and the methods are set up in an inheritance hierarchy in the same order they are passed to the load() method - the entries in the 2nd file are placed into a class that inherits from the class generated by the entries in the first file, the entries in the third file inherit from those in the 2nd file, and so on.The $inherit_from parameter passed to the load() method indicates what class, if any, the class generated by the 1st file should inhert from.The $filters parameter is an optional set of filters to be run on each value before being returned. See the documentation on the load() method below for details.The configuration files should not contain a package name. The contents of each file is eval'd in the scope of a unique package. The package global $info must be set to the hash reference that you wish to be used for setting up the methods. Since the configuration files are eval'd, you may write your own subroutines in the configuration files to make them available as methods in the package generated. However, they will be overridden by and methods generated with the same name from the entries in the $info hash.This module has been tested on unix only. It currently depends on device and inode numbers to generate unique namespaces, so it may not work on non-unix platforms.SYNOPSIS use Class::Config; my $conf = Class::Config->new; my $obj = $conf->load(@files, $inherit_from, $filters); Requirements: · Perl


Class::Config Related Software