Test2::Tools(3pm) Perl Programmers Reference Guide Test2::Tools(3pm)

# [NAME](#NAME)

Test2::Tools - Documentation for Tools.

# [DESCRIPTION](#DESCRIPTION)

Tools are packages that export test functions, typically all related to a specific aspect of testing. If you have a couple different categories of exports then you may want to break them into separate modules.

Tools should export testing functions. Loading tools **should not** have side- effects, or alter the behavior of other tools. If you want to alter behaviors or create side-effects then you probably want to write a Test2::Plugin.

# [FAQ](#FAQ)

[Why is it called Test2::Tools, and not Test2::Tool?](#Why)

This question arises since Tools is the only namespace in the plural. This is because each Plugin should be a distinct unit of functionality, but a Tools dist can (and usually should) export several tools. A bundle is also typically described as a single unit. Nobody would like Test2::Bundles::Foo.

[Should my tools subclass Test2::Tools?](#Should)

No. Currently this class is empty. Eventually we may want to add behavior, in which case we do not want anyone to already be subclassing it.

# [HOW DO I WRITE A 'TOOLS' MODULE?](#HOW_DO_I_WRITE_A_)

It is very easy to write tools:

```
    package Test2::Tools::Mine
    use strict;
    use warnings;
    # All tools should use the context() function.
    use Test2::API qw/context/;
    our @EXPORTS = qw/ok plan/;
    use base 'Exporter';
    sub ok($;$) {
        my ($bool, $name) = @_;
        # All tool functions should start by grabbing a context
        my $ctx = context();
        # The context is the primary interface for generating events
        $ctx->ok($bool, $name);
        # When you are done you release the context
        $ctx->release;
        return $bool ? 1 : 0;
    }
    sub plan {
        my ($max) = @_;
        my $ctx = context();
        $ctx->plan($max);
        $ctx->release;
    }
    1;
```

See Test2::API::Context for documentation on what the $ctx object can do.

# [SOURCE](#SOURCE)

The source code repository for Test2-Suite can be found at *https://github.com/Test-More/test-more/*.

# [MAINTAINERS](#MAINTAINERS)

[Chad Granum &lt;exodist@cpan.org&gt;](#Chad)

# [AUTHORS](#AUTHORS)

[Chad Granum &lt;exodist@cpan.org&gt;](#Chad~2)

# [COPYRIGHT](#COPYRIGHT)

Copyright Chad Granum &lt;exodist@cpan.org&gt;.

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/*

2026-10-21 perl v5.44.0

---

Document: Test2::Tools(3pm) from perl 5.44.0-r2 (Chainguard OS)
Source: https://github.com/Perl/perl5.git
