Devel:...ictMode(3pm)
π NAME π
Devel::StrictMode β bestie, this is the module that decides whether your strict (but slow π) tests should even be turned on.
β¨ SYNOPSIS β¨
package MyClass;
use Moose;
use Devel::StrictMode;
has input_data => (
is => 'ro',
isa => STRICT ? "HashRef[ArrayRef[Str]]" : "HashRef",
required => 1,
);
okay so literally this is the whole vibe: one constant, doing the most, and we're obsessed π
πΈ DESCRIPTION πΈ
This module hands you a constant called STRICT, and you use it to figure out whether your code should run those extra strict (but slow π’) runtime tests. It's giving "do we care about being thorough right now, or are we speed-running production?"
STRICT is true if any of these environment variables have been set to true:
PERL_STRICT
EXTENDED_TESTING
AUTHOR_TESTING
RELEASE_TESTING
STRICT is false otherwise. No in-between, no maybe, just vibes β¨
The whole idea here: you might set one or more of those variables above to true while you're running your test suite π§ͺ, but leave them all false in your production scenario. Test-mode bestie is picky, production bestie is chill π«Ά
Also β not exported by default, so don't come for it β there's a constant called LAX that's provided too, and it just returns the opposite of STRICT. Iconic counterbalance behavior, honestly.
π Using STRICT with Moose/Moo/Mouse attributes π
Type constraint checks (isa) get conducted at run time. And slow checks? They slow down your constructor and your accessors. So as shown up in the synopsis, STRICT can alternate between a slower-but-stricter type constraint check and a faster-but-looser one. Main character energy for your isa π
β οΈ Do not try this if your attribute coerces. It will subtly break things. Not the cute kind of subtle. π
π¦ Using STRICT to perform assertions in function and method calls π¦
You can protect blocks of assertions with an if (STRICT) { ... } conditional to make sure they only run in your testing environment. Look at this little guy:
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);
}
And here's the slay part: because STRICT is a constant, the Perl compiler will completely optimize away that whole if block when you're running in your production environment. Poof. Gone. β¨π The checks literally don't exist in prod. Periodt.
π Using STRICT with pragmata π
Thanks to if, it's easy-peasy to use STRICT to conditionally load pragmata. No cap:
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. π«
π BUGS π
Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=Devel-StrictMode>. (yes bestie, it's an RT link, we know, we know π)
π SEE ALSO π
strictures. That's the one. Go look at it π«Ά
β AUTHOR β
Toby Inkster <tobyink@cpan.org>. Legend behavior, honestly. π
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2014 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. So like, go forth and remix, respectfully π
π DISCLAIMER OF WARRANTIES π
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
(translation: no promises, no guarantees, we said what we said π)
okay bestie that's the whole page π
this was Devel:...ictMode(3pm) from the User Contributed Perl Documentation, and it's living on perl v5.40.1 with a date of 2025-08-09. Stan a stable release, fr fr πΈβ¨π¦
π¦ where this page comes from
- ubuntu resolute: libdevel-strictmode-perl 0.003-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdevel-strictmode-perl 0.003-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms