Test2::...:Exports(3)
πΈ NAME πΈ
Test2::Tools::Exports β Tools for validating exporters.
okay so you'll see this page filed as Test2::...:Exports(3) in the User Contributed Perl Documentation, and the module in question is Test2::Tools::Exports. that's the whole intro, bestie π
π DESCRIPTION π
These are tools for checking that symbols have been imported into your namespace. no cap, that's the assignment: you wanna know which symbols landed in your namespace, and these little helpers do the vibe check for you. β¨
π¦ SYNOPSIS π¦
tiny little usage moment:
use Test2::Tools::Exports
use Data::Dumper;
imported_ok qw/Dumper/;
not_imported_ok qw/dumper/;
β¨ EXPORTS β¨
All subs are exported by default. every single one, periodt. π
π imported_ok(@SYMBOLS) π
Vibe check: do these symbols exist in the current package? It's not gonna find inherited subs, bestie. It only scans the current package's symbol table. And it WILL NOT confirm that the symbols were defined outside of the package itself β it's checking the symbol table, not doing a whole forensic investigation, okay? π
imported_ok( '$scalar', '@array', '%hash', '&sub', 'also_a_sub' );
@SYMBOLS can hold any number of symbols. Every item in the array has to be a string, and that string should be the name of a symbol. If a sigil is present then it will search for that specified type, if no sigil is specified it will be used as a sub name.
π not_imported_ok(@SYMBOLS) π
Vibe check the other way: these symbols should NOT exist in the current package. This won't find inherited subs. It will only look at symbols in the current package's symbol table.
not_imported_ok( '$scalar', '@array', '%hash', '&sub', 'also_a_sub' );
@SYMBOLS can hold any number of symbols. Every item in the array has to be a string, and that string should be the name of a symbol. If a sigil is present, then it will search for that specified type. If no sigil is specified, it will be used as a sub name.
π CAVEATS π
Before Perl 5.10, distinguishing a package scalar that is undeclared vs declared and undefined is genuinely rough. Currently imported_ok and not_imported_ok cannot see package scalars declared using our $var unless the variable has been assigned a defined value.
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/);
If $foo is imported from another module, or imported using use vars qw/$foo/; then it will work on all supported perl versions.
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 be nosy, bestie π«Ά
π MAINTAINERS π
Chad Granum <exodist@cpan.org> β holding it down.
π AUTHORS π
Chad Granum <exodist@cpan.org> β also the author, slay.
π 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 manual, bestie π β brought to you by perl v5.42.0, dated 2025-07-28, and filed under Test2::...:Exports(3). slay and goodbye β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Simple 1.302214-bp160.1.2 Β· Artistic-1.0 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