Devel:...ictMode(3pm)

πŸ“¦
version 0.003 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– 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. πŸ‘‘


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