Config::Strict

Add strict name- and type-checking to configuration data
Download

Config::Strict Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Blake Willmarth
  • Publisher web site:
  • http://search.cpan.org/~blakew/

Config::Strict Tags


Config::Strict Description

Add strict name- and type-checking to configuration data Config::Strict is a Perl module that wraps Declare::Constraints::Simple to enable strict parameter name- and type-checking on configuration data. That is, it will complain anytime an attempt is made to access a parameter with an invalid name or type; or if an attempt is made to unset a required parameter. Both built-in and custom types can be used to build a validation profile for the entire configuration.This module is meant to be used alongside any configuration parser that hashes configuration data.SYNOPSIS use Config::Strict; use Declare::Constraints::Simple -All; # For custom checks my $config = Config::Strict->new( { params => { # Parameter types & names Bool => , # Multiple parameters Int => 'my_i', # Single parameter Num => 'my_n', HashRef => 'my_href', Enum => { my_enum => }, Anon => { # anonymous profiles my_pos2 => # Positive number And( IsNumber, Matches( qr/^+$/ ) ), my_nest => IsA( 'Config::Strict' ), # Nested configuration } }, required => , # Required parameters defaults => { # Default values my_bool1 => 1, my_enum => 'e2', my_n => -1.1, my_pos2 => 1_000, }, } ); # Access and change the data # Retrieve a single value $got = $config->get( 'my_n' ); # $got = -1.1 # Retrieve a list of values @got = $config->get( qw( my_bool1 my_n ) ); # @got = ( 1, -1.1 ) # Set multiple parameters $config->set( my_bool1 => 1, 'my_pos2' => 2 ); # Unset parameters $config->unset( 'my_n' ); $config->param_is_set( 'my_n' ); # false # The following will die: $config->get( 'foo' ); # foo doesn't exist $config->set( 'my_i' => 2.2 ); # my_i must be an integer $config->set( 'my_pos2' => -5 ); # my_pos2 must be positive $config->unset( 'my_n' ); # my_n is required Requirements: · Perl


Config::Strict Related Software