constant::def - Perl pragma to declare previously undeclared constants
Version 0.01
Define compile-time constant only if it wasn't previously defined elsewhere. The main reason is to use for debugging constants, since there is no way to change the value, except by editing the source
# common way: (redefine may be done only in source file) use constant DEBUG => ...; # or BEGIN { *DEBUG = sub () { ... } } # or sub DEBUG () { ... } ################ # complex way: redefine works, if done before use of module # in main.pl BEGIN { *My::Module::Debug = sub () { 1 }; } use My::Module; # in My/Module.pm BEGIN { defined &DEBUG or do { my $debug = $ENV{MY_MODULE_DEBUG} || 0; *DEBUG = sub () { $debug } } } ################ # using this distribution # redefine works, if done before use of module # in main.pl use constant::abs 'My::Module::DEBUG' => 1; use My::Module; # in My/Module.pm use constant::def DEBUG => $ENV{MY_MODULE_DEBUG} || 0;
Syntax is fully compatible with constant
constant
constant::abs, constant
Mons Anderson, <mons at cpan.org>
<mons at cpan.org>
Please report any bugs or feature requests to bug-constant-def at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=constant-def. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-constant-def at rt.cpan.org
Copyright 2009 Mons Anderson.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install constant::def, copy and paste the appropriate command in to your terminal.
cpanm
cpanm constant::def
CPAN shell
perl -MCPAN -e shell install constant::def
For more information on module installation, please visit the detailed CPAN module installation guide.