Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHI/Test.pm: Replace manual import stuff with Import::Into #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ repository.web = https://github.com/jonswar/perl-chi
repository.type = git

; Build
[PruneFiles]
filenames = Makefile.PL
[ExecDir]
[ExtraTests]
[GatherDir]
exclude_filename = Makefile.PL

[License]
[MakeMaker]
[ManifestSkip]
Expand Down
47 changes: 19 additions & 28 deletions lib/CHI/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,36 @@ use List::MoreUtils qw(uniq);
use Module::Runtime qw(require_module);
use CHI;
use CHI::Driver::Memory;
use Import::Into;
use strict;
use warnings;

sub import {
my $class = shift;
$class->export_to_level( 1, undef, @_ );
}

sub packages_to_import {
return (
qw(
Test::Deep
Test::More
Test::Exception
CHI::Test::Util
)
# Test::Deep exports way too much by default
'Test::Deep'->import::into(
1, qw(eq_deeply cmp_deeply cmp_set cmp_bag
cmp_methods subbagof superbagof subsetof
supersetof superhashof subhashof)
);

# Exports all by default
'Test::More'->import::into(1);

# Exports all by default
'Test::Exception'->import::into(1);

# EXPORT_OK Only
'CHI::Test::Util'->import::into(
1, qw(activate_test_logger is_between
cmp_bool random_string skip_until)
);
}

sub export_to_level {
my ( $class, $level, $ignore ) = @_;

foreach my $package ( $class->packages_to_import() ) {
require_module($package);
my @export;
if ( $package eq 'Test::Deep' ) {

# Test::Deep exports way too much by default
@export =
qw(eq_deeply cmp_deeply cmp_set cmp_bag cmp_methods subbagof superbagof subsetof supersetof superhashof subhashof);
}
else {

# Otherwise, grab everything from @EXPORT
no strict 'refs';
@export = @{"$package\::EXPORT"};
}
$package->export_to_level( $level + 1, undef, @export );
}
$class->import::into($level);
}

1;