TEST2::TOOLS::EXPORTS(3perl)

πŸ’– Test2::Tools::Exports β€” the perl manual, but make it cute πŸ’–

okay bestie, this is Test2::Tools::Exports(3perl) from the Perl Programmers Reference Guide, and it's lowkey one of the most useful little test helpers ever. it's giving "did that import actually happen" energy. let's get into it 🫢


✨ NAME ✨

Test2::Tools::Exports β€” tools for validating exporters. no cap, that's the whole job: checking that your imports actually landed.


🌸 DESCRIPTION 🌸

these are the tools you reach for when you need to check that symbols have been imported into your namespace. that's it. that's the vibe. you said use Something qw/foo/ and now you wanna prove foo is really sitting there in your package. iconic behavior honestly. πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

use Test2::Tools::Exports

use Data::Dumper;
imported_ok qw/Dumper/;
not_imported_ok qw/dumper/;

see how Dumper passes and dumper doesn't? case sensitivity said "not today" πŸ’…


πŸŽ€ EXPORTS πŸŽ€

all subs are exported by default. free. gifted. no strings attached. ✨

imported_ok(@SYMBOLS)

check that the specified symbols exist in the current package.

okay so important caveats, bestie, don't skip these:

  • this will not find inherited subs.
  • this 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.
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. 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. simple as that πŸ“

not_imported_ok(@SYMBOLS)

check that the specified symbols do not exist in the current package.

same disclaimers, same energy:

  • this will not find inherited subs.
  • this will only look at symbols in the current package's symbol table.
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. 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 😭

okay this is the part where we get real. buckle up.

before Perl 5.10, it is very difficult to distinguish between a package scalar that is undeclared vs declared and undefined. 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/);

(yes, "onlder" β€” that typo is straight from the source, we keep the facts and the typos, fr fr πŸ™ˆ)

if $foo is imported from another module, or imported using use vars qw/$foo/; then it will work on all supported perl versions. slay. ✨

use Test2::Tools::Exports;

use vars qw/$foo/;
use Some::Module qw/$bar/;

# Always works
imported_ok(qw/$foo $bar/);

so like. use vars is the cheat code for old perls. iykyk 🌈


πŸ”₯ SOURCE πŸ”₯

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

go look at it. main character repo behavior. πŸ‘‘


πŸ’œ MAINTAINERS πŸ’œ

  • Chad Granum <exodist@cpan.org>

🌟 AUTHORS 🌟

  • Chad Granum <exodist@cpan.org>

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 whole page bestie!! πŸŽ€ this one shipped as part of perl v5.44.0, dated 2026-10-17. thank you for coming to my ted talk, go write some tests, drink water, and remember: imported_ok is not a vibe check on where the symbol came from, it's just a vibe check on whether it's there. mwah πŸ’–πŸ«Άβœ¨

πŸ“¦ 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