Test::Stream::Exporter - Declarative exporter for Test::Stream and friends.
This distribution is deprecated in favor of Test2, Test2::Suite, and Test2::Workflow.
See Test::Stream::Manual::ToTest2 for a conversion guide.
Test::Stream::Exporter is an internal implementation of some key features from Exporter::Declare. This is a much more powerful exporting tool than Exporter. This package is used to easily manage complicated export logic across Test::Stream and friends.
use Test::Stream::Exporter; # Export some named subs from the package default_exports qw/foo bar baz/; exports qw/fluxx buxx suxx/; # Export some anonymous subs under specific names. export some_tool => sub { ... }; default_export another_tool => sub { ... }; # Call this when you are done providing exports in order to cleanup your # namespace. no Test::Stream::Exporter; ...;
Note: If you import Test::Stream::Exporter functions under alternative names, no Test::Stream::Exporter; will not find and remove them like it normally would.
no Test::Stream::Exporter;
The rename syntax is borrowed from Exporter::Declare, which borrowed it from Sub::Exporter.
use Some::Exporter an_export => {-as => 'new_name'}, other_export => {-as => 'other_name'};
You can also prefix and/or postfix to the names:
use Some::Exporter an_export => {-preifx => 'my_', postfix '_tool'}; # Now use it: my_an_export_tool(...);
You can use -all to import ALL subs exported by a module.
-all
use Some::Exporter '-all';
This can be combined with aliasing:
use Some::Exporter '-all', foo => { -as => 'my_foo' };
In this example foo will be imported as 'my_foo', all other subs will be imported with their original names. Order is not important here.
foo
You can use -default to import all default subs, then list others you want to import as well.
-default
use Some::Exporter '-default', qw/and_this and_that/;
If you want to import all the defaults AND rename one or more:
use Some::Exporter '-default', foo => { -as => 'my_foo' };
In this example foo() will be imported as my_foo(). All other defaults will also be imported, but with their original names. Order is not important here.
foo()
my_foo()
Sometimes you need to make a custom import method, but you still want to use the exporter tool to manage exports. here is how you do it:
use Test::Stream::Exporter qw/export exports export_from/; export foo => sub { 'foo' }; export qw/bar baz/; sub import { my $class = shift; my @exports = @_; # Do whatever you need to ... # Now go ahead and do the exporting with your list my $caller = caller; export_from($class, $caller, \@exports); } # This will cleanup the namespace, including 'export_from', do you need to # do it AFTER your import method. no Test::Stream::Exporter; sub bar { 'bar' } sub baz { 'baz' } 1;
Your class needs this to function as an exporter.
Note: All of thease are removed by default when you run no Test::Stream::Exporter;
These are used to define exports that may not actually be subs in the current package.
These let you export package subs en mass.
Export from the exporter class into the $dest package. The seconond argument is optional, if it is omitted the default export list will be used. The second argument must be an arrayref with export names.
$dest
This will export all the specified symbols from the $from package to the $to package.
$from
$to
The source code repository for Test::Stream can be found at http://github.com/Test-More/Test-Stream/.
Copyright 2015 Chad Granum <exodist7@gmail.com>.
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 Test::Stream, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Stream
CPAN shell
perl -MCPAN -e shell install Test::Stream
For more information on module installation, please visit the detailed CPAN module installation guide.