NAME

Test::Stream::Exporter - Declarative exporter for Test::Stream and friends.

DEPRECATED

This distribution is deprecated in favor of Test2, Test2::Suite, and Test2::Workflow.

See Test::Stream::Manual::ToTest2 for a conversion guide.

DESCRIPTION

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.

SYNOPSIS

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;

...;

CONTROLLING IMPORTS

IMPORTING SUBS WITH ALTERNATE NAMES

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.

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(...);

IMPORTING ALL SUBS

You can use -all to import ALL subs exported by a module.

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.

IMPORTING DEFAULTS PLUS

You can use -default to import all default subs, then list others you want to import as well.

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.

CUSTOMIZING AN IMPORT METHOD

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;

EXPORTS

DEFAULT

METHODS

$class->import(@list)

Your class needs this to function as an exporter.

FUNCTIONS

Note: All of thease are removed by default when you run no Test::Stream::Exporter;

export NAME => sub { ... }
default_export NAME => sub { ... }

These are used to define exports that may not actually be subs in the current package.

exports qw/foo bar baz/
default_exports qw/foo bar baz/

These let you export package subs en mass.

OTHER AVAILABLE EXPORTS

METHODS

$class->export_to($dest)
$class->export_to($dest, \@symbols)

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.

FUNCTIONS

Note: All of thease are removed by default when you run no Test::Stream::Exporter;

export_from($from, $to)
export_from($from, $to, \@symbols)

This will export all the specified symbols from the $from package to the $to package.

SOURCE

The source code repository for Test::Stream can be found at http://github.com/Test-More/Test-Stream/.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>
Kent Fredric <kentnl@cpan.org>

COPYRIGHT

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/