יובל קוג'מן (Yuval Kogman) > Constant-FromGlobal-0.01 > Constant::FromGlobal

Download:
Constant-FromGlobal-0.01.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.01   Source   Latest Release: Constant-FromGlobal-0.07

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

syntax highlighting: