Test2::Require(3pm)
π NAME π
okay so this is Test2::Require(3pm), straight outta the Perl Programmers Reference Guide β and Test2::Require is literally the base class and documentation for skip-unless type test packages. periodt. π
πΈ DESCRIPTION πΈ
Test2::Require::* packages are packages you load to ensure your test file is skipped unless a specific requirement is met. That's the whole point: no requirement, no test run. π«Ά
Modules in this namespace may subclass Test2::Require if they wish, but it is not strictly necessary to do so. lowkey flexible, fr fr. β¨
π HOW DO I WRITE A 'REQUIRE' MODULE? π
π§ AS A SUBCLASS π§
here's the subclass route, bestie β copy this energy:
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;
A subclass of Test2::Require simply needs to implement a skip() method. That method will receive all import arguments. It should return undef if the test should run, and it should return a reason for skipping if the test should be skipped. no cap. π
π¦ STAND-ALONE π¦
If you do not wish to subclass Test2::Require then you should write an import() method:
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;
that's the stand-alone vibe β context object, skip plan, release, done. iconic. π
π SOURCE π
The source code repository for Test2-Suite can be found at 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/
and that's the page, bestie π«Ά β this was Test2::Require(3pm) from perl v5.42.3, dated 2026-11-03. go make skip-unless magic that slays π
β¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms