TEST2::TOOLS::EXPORTS(3pm)
π Test2::Tools::Exports β from the Perl Programmers Reference Guide (3pm section, bestie, we're fancy)
okay so picture this: you just used a module, and now you're squinting at your namespace like "did that actually import anything or am I being gaslit rn??" That's literally the whole job of this page. Welcome to Test2::Tools::Exports. π«Ά
β¨ NAME β¨
Test2::Tools::Exports β tools for validating exporters. Yes, that's it, that's the vibe. π
πΈ DESCRIPTION πΈ
These are tools for checking that symbols have actually been imported into your namespace. Like, actually actually. No cap. It's the vibe check your use statements deserve. π
π¦ SYNOPSIS π¦
use Test2::Tools::Exports
use Data::Dumper;
imported_ok qw/Dumper/;
not_imported_ok qw/dumper/;
See how one is Dumper and the other is dumper? Case matters, bestie, Perl is not doing your lowercase homework for you. π
π EXPORTS π
All subs are exported by default. Every single one, no gatekeeping. π
π imported_ok(@SYMBOLS)
Checks that the specified symbols exist in the current package. So, like, a few things it is not doing, and I need you to hear me on this:
- It will not find inherited subs.
- It will only find symbols in the current package's symbol table.
- This WILL NOT confirm that the symbols were defined outside of the package itself. (Yeah β it just proves the name is sitting there in your symbol table. Could be from anywhere. Could be from you. It's not doing a background check. π)
The example, exactly as written:
imported_ok( '$scalar', '@array', '%hash', '&sub', 'also_a_sub' );
@SYMBOLS can contain any number of symbols. Each item in the array must be a string. The string should be the name of a symbol. Here's the rule:
- If a sigil is present β it will search for that specified type.
- If no sigil is specified β it will be used as a sub name.
Slay, sigil-based dispatch, we love to see it. β¨
π not_imported_ok(@SYMBOLS)
The inverse queen. Checks that the specified symbols do not exist in the current package. Again:
- This will not find inherited subs.
- This will only look at symbols in the current package's symbol table.
The example, verbatim:
not_imported_ok( '$scalar', '@array', '%hash', '&sub', 'also_a_sub' );
@SYMBOLS can contain any number of symbols. Each item in the array must be a string. The string should be the name of a symbol. And the sigil rules are the same deal:
- If a sigil is present β it will search for that specified type.
- If no sigil is specified β it will be used as a sub name.
Consistency is the moment. π§
π CAVEATS π (the dramatic part, sorry)
Before Perl 5.10, it is very difficult to distinguish between a package scalar that is undeclared vs. declared and undefined. Like, genuinely cursed territory. π―οΈ
Currently, imported_ok and not_imported_ok cannot see package scalars declared using our $var unless the variable has been assigned a defined value. So if it's declared-but-empty, the tools are basically squinting into the void. π
This will pass on recent perls, but fail on perls older than 5.10:
use Test2::Tools::Exports;
our $foo;
# Fails on perl onlder than 5.10
imported_ok(qw/$foo/);
(yes, onlder β that's the comment exactly as it appears in the docs, typo and all, I don't make the rules π)
BUT. If $foo is imported from another module, or imported using use vars qw/$foo/;, then it will work on all supported perl versions. Redemption arc. π
use Test2::Tools::Exports;
use vars qw/$foo/;
use Some::Module qw/$bar/;
# Always works
imported_ok(qw/$foo $bar/);
π₯ SOURCE π₯
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go lurk, it's fine, we all do it. π
π 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, you ate that π
β this was Test2::...:Exports(3pm) from the Perl Programmers Reference Guide, with the footer reading perl v5.42.3 dated 2026-11-03. mwah, go write some tests bestie πβ¨
π¦ 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