GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
constant::def(3) User Contributed Perl Documentation constant::def(3)

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::abs, constant

Mons Anderson, "<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.

Copyright 2009 Mons Anderson.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2009-03-11 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.