Constant::FromGlobal - Adam Kennedy's "Constant Global" pattern
package Foo; use Constant::FromGlobal qw(DEBUG); sub foo { # to enable debug, set $Foo::DEBUG=1 before loading Foo warn "lalala" if DEBUG: }
This module lets you easily define constants whose value is initialized from a global or an environment variable.
This routine takes an optional hash of options for all constants, followed by an option list (see Data::OptList) of constant names.
For example:
use Constant::FromGlobal { env => 1 }, "DSN", MAX_FOO => { int => 1, default => 3 };
is the same as
use Constant::FromGlobal DSN => { env => 1 }, MAX_FOO => { int => 1, default => 3, env => 1 };
which will define two constants, DSN and MAX_FOO. DSN is a string and MAX_FOO is an integer. Both will take their values from $Foo::DSN if defined or $ENV{FOO_DSN} as a fallback.
DSN
MAX_FOO
$Foo::DSN
$ENV{FOO_DSN}
constant, constant::def, http://use.perl.org/~Alias/journal/39845
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Constant::FromGlobal, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Constant::FromGlobal
CPAN shell
perl -MCPAN -e shell install Constant::FromGlobal
For more information on module installation, please visit the detailed CPAN module installation guide.