ctflags::parse - configure ctflags from command line or environments
use ctflags::parse allow => [qw(myapp yourapp debug)], ns => 'myapp', # or namespace => 'myapp' env => 'MYAPPFLAGS', parse => 'b45ar7yui'; ... use ctflags 'foo=myapp:B67';
ctflags::parse implementes a simple language that can be used to set ctflags from specifications obtained from the command line or from environment variables.
ctflags::parse define and sets ctflag values from string declarations.
ctflags::parse
It does all its work from the use statement use ctflags::parse ... because this way ctflags are defined early at compile time.
use ctflags::parse ...
It support diferent options expressed as key => value pairs:
key => value
restrict the namespaces that could be latter (but in the same use statement) included in the declarations. i.e:
use
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).
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!
parses the declaration in the environment variable if exists. Incorrect declarations will cause your program to die with an explanation of the error.
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.
myapp:debug
s
j
k
O
u
I
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:
BEGIN {...}
#!/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; ...
None.
ctflags, Getopt::Std, Getopt::Long.
Salvador Fandiño Garcia, <sfandino@yahoo.com>.
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.
To install ctflags, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ctflags
CPAN shell
perl -MCPAN -e shell install ctflags
For more information on module installation, please visit the detailed CPAN module installation guide.