T - Encapsulate testing tools instead of cluttering your namespace.
This module collection makes it possible to use popular testing tools such as Test::More or Test2::Bundle::Extended without cluttering up your namespace. Under the hood all the work is done by Import::Box which was created specifically to implement this.
use T 'More'; # Loads Test::More, and provides the t() box function use T2 'Basic'; # Loads Test2::Tools::Basic, and provides the t2() function use T2::B 'Extended'; # Loads Test2::Bundle::Extended, also provides/appends to the t2() function use T2::P 'SRand'; # Loads Test2::Plugin::SRand, and provides the t2p() function t->is('a', 'a', "Can run Test::More::is()"); t2->is('a', 'a', "Can run Test2::Tools::Compare::is()"); # (Provided by the extended bundle) # Alternate syntax: t is => ('a', 'a'); t2 is => ('a', 'a');
use T; use T2; use T2::B; my $t = T->new('More'); # Loads Test::More into $t my $t2 = T2->new('Basic'); # Loads Test2::Tools::Basic into $t2 my $t2b = T2::B->new('Extended'); # Loads Test2::Bundle::Extended into $t2b $t->is('a', 'a', "Can run Test::More::is()"); $t2->ok(1, "ok from Test2::Tools::Basic"); $t2b->is('a', 'a', "Can run Test2::Tools::Compare::is()"); # Indirect syntax (just say NO!) is $t('a', 'a'); ok $t2(1, "pass"); is $t2b('a', 'a');
This is used for boxing Test:: modules into the t() box.
Test::
t()
This is used for boxing Test2::Tools:: modules into the t2() box.
Test2::Tools::
t2()
This is used for boxing Test2::Bundle:: modules into the t2() box.
Test2::Bundle::
This is used for boxing Test2::Plugin:: modules into the t2p() box. A plugin should never actually export anything, so this is actually just a shortcut for loading plugins.
Test2::Plugin::
t2p()
This will load $MODULE and place the exports into the box instead of your namespace. A prefix is automatically prepended to $MODULE, which prefix depends on the class used for boxing. To avoid the prefix you can append '+' to the front of $MODULE:
$MODULE
t->import('+My::Module');
Prefixes with Test::
Prefixes with Test2::Tools::
Prefixes with Test2::Bundle::
Prefixes with Test2::Plugin::
Import::Box - Everything here is based off of this module.
The source code repository for T can be found at http://github.com/Test-More/T/.
Copyright 2016 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/
To install T, copy and paste the appropriate command in to your terminal.
cpanm
cpanm T
CPAN shell
perl -MCPAN -e shell install T
For more information on module installation, please visit the detailed CPAN module installation guide.