This module provides you with a constant "STRICT" which you can use to determine whether additional
strict (but slow) runtime tests are executed by your code.
"STRICT" is true if any of the following environment variables have been set to true:
PERL_STRICT
EXTENDED_TESTING
AUTHOR_TESTING
RELEASE_TESTING
"STRICT" is false otherwise.
It is anticipated that you might set one or more of the above variables to true while running your test
suite, but leave them all false in your production scenario.
Although not exported by default, a constant "LAX" is also provided, which returns the opposite of
"STRICT".
UsingSTRICTwithMoose/Moo/Mouseattributes
Type constraint checks ("isa") are conducted at run time. Slow checks can slow down your constructor and
accessors. As shown above, "STRICT" can be used to alternate between a slower by stricter type constraint
check, and a faster but looser one.
Don't try this if your attribute coerces. It will subtly break things.
UsingSTRICTtoperformassertionsinfunctionandmethodcalls
You may protect blocks of assertions with an "if (STRICT) { ... }" conditional to ensure that they only
run in your testing environment.
sub fibonacci
{
my $n = $_[0];
if (STRICT)
{
die "expected exactly one argument"
unless @_ == 1;
die "expected argument to be a natural number"
unless $n =~ /\A[0-9]+\z/;
}
$n < 2 ? $n : fibonacci($n-1)+fibonacci($n-2);
}
Because "STRICT" is a constant, the Perl compiler will completely optimize away the "if" block when
running in your production environment.
UsingSTRICTwithpragmata
Thanks to if it's easy to use "STRICT" to conditionally load pragmata.
use Devel::StrictMode;
use strict;
use warnings STRICT ? qw(FATAL all) : qw(all);
no if STRICT, "bareword::filehandles";
no if STRICT, "autovivification";
See also autovivification, bareword::filehandles, indirect, multidimensional, etc.