constant::lexical - Perl pragma to declare lexical compile-time constants


constant-lexical documentation  | view source Contained in the constant-lexical distribution.

Index


NAME

Top

constant::lexical - Perl pragma to declare lexical compile-time constants

VERSION

Top

2

SYNOPSIS

Top

  use constant::lexical DEBUG => 0;
  {
          use constant::lexical PI => 4 * atan2 1, 1;
          use constant::lexical DEBUG => 1;

          print "Pi equals ", PI, "...\n" if DEBUG;
  }
  print "just testing...\n" if DEBUG; # prints nothing
                                        (DEBUG is 0 again)
  use constant::lexical \%hash_of_constants;
  use constant::lexical WEEKDAYS => @weekdays; # list

  use constant::lexical { PIE        => 4 * atan2(1,1),
                          CHEESECAKE => 3 * atan2(1,1),
                         };

DESCRIPTION

Top

This module creates compile-time constants in the manner of constant.pm, but makes them local to the enclosing scope.

WHY?

Top

I sometimes use these for objects that are blessed arrays, which are faster than hashes. I use constants instead of keys, but I don't want them exposed as methods, so this is where lexical constants come in handy.

PREREQUISITES

Top

This module requires perl 5.8.0 or later and, depending on your version of perl, one of the following modules, which you can get from the CPAN:

BUGS

Top

The following three bugs have been fixed for perl 5.11.2 and higher, but are still present for older versions of perl:

If you find any other bugs, please report them to the author via e-mail.

ACKNOWLEDGEMENTS

Top

The idea of using objects in %^H (in the pre-5.11.2 code) was stolen from namespace::clean.

Some of the code for the perl 5.11.2 version is plagiarised from constant.pm by Tom Phoenix.

AUTHOR & COPYRIGHT

Top

SEE ALSO

Top

constant, Sub::Delete, namespace::clean, Lexical::Sub


constant-lexical documentation  | view source Contained in the constant-lexical distribution.