Author image יובל קוג'מן (Yuval Kogman)


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.


constant, constant::def,

1 POD Error

The following errors were encountered while parsing the POD:

Around line 152:

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