Test2::Require(3perl)
β¨ Test2::Require β¨
omg hi bestie π this is Test2::Require (from the perl manual, section 3), and it's the base class + documentation home for all those skip-unless type test packages. iykyk.
π NAME π
Test2::Require β the base class and the docs for packages that skip your tests unless something is true. basically the blueprint for "nah, not today" test files π
πΈ DESCRIPTION πΈ
okay so Test2::Require::* packages are the things you load to make sure your test file gets skipped unless some specific requirement is met. iconic behaviour honestly π¦
Modules living in this namespace may subclass Test2::Require if they feel like it β but it's not strictly necessary. do what feels right, queen π
π HOW DO I WRITE A 'REQUIRE' MODULE? π
two ways, bestie. pick your fighter:
π§ AS A SUBCLASS
package Test2::Require::Widget;
use strict;
use warnings;
use base 'Test2::Require';
sub HAVE_WIDGETS { ... };
sub skip {
my $class = shift;
my @import_args = @_;
if (HAVE_WIDGETS()) {
# We have widgets, do not skip
return undef;
}
else {
# No widgets, skip the test
return "Skipped because there are no widgets" unless HAVE_WIDGETS();
}
}
1;
so a subclass of Test2::Require literally just needs to implement a skip() method. that's it, that's the whole vibe π
that method receives all the import arguments. and the rule is:
- return
undefβ test should run β - return a reason for skipping β test gets skipped π
lowkey simple fr fr.
π STAND-ALONE
if you don't feel like subclassing Test2::Require, that's valid, no judgement β you just write an import() method instead:
package Test2::Require::Widget;
use strict;
use warnings;
use Test2::API qw/context/;
sub HAVE_WIDGETS { ... };
sub import {
my $class = shift;
# Have widgets, should run.
return if HAVE_WIDGETS();
# Use the context object to create the event
my $ctx = context();
$ctx->plan(0, SKIP => "Skipped because there are no widgets");
$ctx->release;
}
1;
not me grabbing a context object and planning a SKIP β main character energy tbh π
π SOURCE π
the source code repository for Test2-Suite lives right here (go look, it's giving open source excellence π):
https://github.com/Test-More/test-more/.
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
β AUTHORS β
Chad Granum <exodist@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
okay that's the whole page bestie, you ate π«Ά this was perl v5.44.0, dated 2026-10-17, and the page name is Test2::Require(3perl) β periodt. go skip some tests responsibly π
β¨
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND 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