NAME

Constant::FromGlobal - Adam Kennedy's "Constant Global" pattern

SYNOPSIS

package Foo;

use Constant::FromGlobal qw(DEBUG);

sub foo {
    # to enable debug, set $Foo::DEBUG=1 before loading Foo
    warn "lalala" if DEBUG:
}

DESCRIPTION

This module lets you easily define constants whose value is initialized from a global or an environment variable.

METHODS

import

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.

SEE ALSO

constant, constant::def, http://use.perl.org/~Alias/journal/39845

1 POD Error

The following errors were encountered while parsing the POD:

Around line 152:

You forgot a '=back' before '=head1'