Hi,
I recently uploaded a module to CPAN that I would like to offer for
inclusion as a Perl pragma. I've taken the liberty of explaining it
here, and I would greatly appreciate any replies on this subject. The
module can be viewed at:
http://search.cpan.org/~ggurevich/define-1.02/lib/define.pm. Thanks in
advance for your time and review.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
define.pm can be thought of as doing exactly the same thing as
constant.pm, but with global scope. You can also think of it as a
perlish version of C's #define directive.
The original motivation for the define pragma was to get
compile-time constant optimizations on a global basis for debugging
statements. Since one usually desires to enable or disable
compilation of debugging statements for the entire program, the need
for a globally accessible constant was indicated.
define.pm can also ensure consistency of constant values. Unlike
constant.pm, you can't have two different values for PI in the
same program.
define.pm also makes it easy to create global objects. For
instance, things like POE's kernel could be defined as a global
constant 'KERNEL', and not need to be passed explicitly as a
parameter to every handler.
While the obvious and well-known problems with naming clashes
present themselves, the documentation makes it clear that modules,
as a rule, should not set their own constants, rather they should
import constants that are defined in the main body of a program, so
name clashes should not be a serious issue.