NAME
Debug::Helper::Flag - Define and import boolean constant DEBUG_FLAG helping to optimize code.
VERSION
Version 0.01
SYNOPSIS
In main script (or a module you use early):
use Debug::Helper::Flag DEBUG_FLAG => BOOL_VAL;
Where BOOL_VAL
is a boolean value. In your module do:
use Debug::Helper::Flag 'DEBUG_FLAG';
# ...
sub Foo {
if (DEBUG_FLAG) { do_argument_check }
# ...
}
DESCRIPTION
This module lets you set a constant Debug::Helper::Flag::DEBUG_FLAG
which is imported on demand. Intended to be used to optimze code like this:
use Debug::Helper::Flag 'DEBUG_FLAG';
# ...
sub Foo {
if (DEBUG_FLAG) { do_argument_check }
# ...
}
If DEBUG_FLAG
is true, then do_argument_check
is executed but if it is false then the perl compiler will completely optimize away the statement, including the surrounding if(...)
construction. The constant must be set to true or false before you can import it. The constant should be specified in the main script or on the command line.
use Debug::Helper::Flag DEBUG_FLAG => 0;
or
use Debug::Helper::Flag DEBUG_FLAG => 1;
or on the command line
perl -MDebug::Helper::Flag=DEBUG_FLAG,1 ...
If you need to specify and use the constant in the same script, then you can do:
use Debug::Helper::Flag 'DEBUG_FLAG', DEBUG_FLAG => 1;
Note: using this
use Debug::Helper::Flag DEBUG_FLAG => EXPRESSION;
multiple times is not a problem provided that EXPRESSION
always evaluates to the same boolean value. Otherwise the script terminates with error message Attempt to redefine DEBUG_FLAG with different value
.
Note: only load this module directly via use
or in a BEGIN
block and never try to load it at runtime, otherwise the optimization will not work!
SEE ALSO
https://metacpan.org/pod/Getopt::constant
AUTHOR
Abdul al Hazred, <451 at gmx.eu>
BUGS
Please report any bugs or feature requests to bug-debug-helper-flag at rt.cpan.org
, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Debug-Helper-Flag. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Debug::Helper::Flag
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
Search CPAN
GitHub Repository
LICENSE AND COPYRIGHT
This software is copyright (c) 2024 by Abdul al Hazred.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.