From: Vincent Pit Date: Thu, 19 Mar 2015 17:39:14 +0000 (-0300) Subject: Factor the exporting logic into a new export_to_pkg() helper X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=6eebc74aa64e2c12b7d2b5449fef997abc06a164;p=perl%2Fmodules%2FVPIT-TestHelpers.git Factor the exporting logic into a new export_to_pkg() helper --- diff --git a/lib/VPIT/TestHelpers.pm b/lib/VPIT/TestHelpers.pm index c147f80..023a873 100644 --- a/lib/VPIT/TestHelpers.pm +++ b/lib/VPIT/TestHelpers.pm @@ -5,6 +5,17 @@ use warnings; use Config (); +sub export_to_pkg { + my ($subs, $pkg) = @_; + + while (my ($name, $code) = each %$subs) { + no strict 'refs'; + *{$pkg.'::'.$name} = $code; + } + + return 1; +} + my %exports = ( load_or_skip => \&load_or_skip, load_or_skip_all => \&load_or_skip_all, @@ -15,10 +26,7 @@ my %exports = ( sub import { my $pkg = caller; - while (my ($name, $code) = each %exports) { - no strict 'refs'; - *{$pkg.'::'.$name} = $code; - } + export_to_pkg \%exports => $pkg; } my $test_sub = sub {