NAME

ctflags::parse - configure ctflags from command line or environments

SYNOPSIS

use ctflags::parse allow => [qw(myapp yourapp debug)],
                   ns => 'myapp', # or namespace => 'myapp'
                   env => 'MYAPPFLAGS',
                   parse => 'b45ar7yui';

...

use ctflags 'foo=myapp:B67';

ABSTRACT

ctflags::parse implementes a simple language that can be used to set ctflags from specifications obtained from the command line or from environment variables.

DESCRIPTION

ctflags::parse define and sets ctflag values from string declarations.

It does all its work from the use statement use ctflags::parse ... because this way ctflags are defined early at compile time.

It support diferent options expressed as key => value pairs:

allow => 'foo, bar'
allow => [qw(foo bar)]
allow => '*'
allow => ''

restrict the namespaces that could be latter (but in the same use statement) included in the declarations. i.e:

use ctflags::parse allow => 'foo',
                   parse => 'foo:bar', # ok
                   parse => 'app:bar'; # error

Use of the asterisk removes all restrictions (every namespace is allowed).

Use of an empty string disallows usage of any namespace but implicit usage of the default (see below).

ns => $namespace
namespace => $namespace

define implicit namespace to be used when no one appears in the declaration. i.e:

use ctflags::parse ns => 'foo',
                   parse => 'a67'; # sets foo:a = 67

Implicit namespace used implicitly is always allowed:

use ctflags::parse allow => '',        # nothing allowed
                   ns => 'foo',        # implicit ns
                   parse => 'a67',     # ok, foo:a=67
                   parse => 'foo:a67'; # error!
env => $environmet_var_name

parses the declaration in the environment variable if exists. Incorrect declarations will cause your program to die with an explanation of the error.

parse => $declaration

parses the declaration following. Declarations are of the form:

[namespace:](ctflag[value])*,[namespace:](ctflag[value])*,...

when no value is specified for a flag, 1 is used as the default.

Example1:

use ctflags::parse ns => 'myapp',
                   parse => foo:b2ar,bee:bas,r56Y7800;

sets ctflags:

foo:b=2, foo:a=1, foo:r=1

bee:b=1, bee:a=1, bee:s=1

myapp:r=56, myapp:Y=7800

Example2:

use ctflags::parse ns => 'myapp:debug',
                   parse => 'su6jklI1000O';

sets ctflags in namespace myapp:debug s, j, k, O to 1, u to 6 and I to 1000.

You should be carefull about puting ctflags::parse use statements before including any module that uses ctflags.

When parsing options from the command line you also have to be carefull about doing it at compile time, this usually means including the command line parsing code in a BEGIN {...} block:

#!/usr/bin/perl

use Getopt::Std;
BEGIN { getopts('d:o:ther:fla:gs') }

our $opt_d;
use ctflags::parse allow => '',
                   ns => 'myapp:debug',
                   parse => $opt_d;

use Other::Module; # modules using ctflags internally
use Another::One;

...

EXPORT

None.

SEE ALSO

ctflags, Getopt::Std, Getopt::Long.

AUTHOR

Salvador Fandiño Garcia, <sfandino@yahoo.com>.

COPYRIGHT AND LICENSE

Copyright 2002 by Salvador Fandiño Garcia

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