From: Graham Knop Date: Wed, 26 Aug 2015 10:06:19 +0000 (-0400) Subject: VERSION's caller should also match given location X-Git-Tag: v1.002005~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7a9ec1de996eb32a6fb07c942ae3c03744a82a17;p=p5sagit%2FImport-Into.git VERSION's caller should also match given location --- diff --git a/lib/Import/Into.pm b/lib/Import/Into.pm index cc9ef0b..7ca9d0b 100644 --- a/lib/Import/Into.pm +++ b/lib/Import/Into.pm @@ -25,9 +25,13 @@ sub _prelude { sub _make_action { my ($action, $target) = @_; my $version = ref $target && $target->{version}; - my $ver_check = $version ? ', $version' : ''; eval _prelude($target) - . qq{sub { Module::Runtime::use_module( shift$ver_check )->$action(\@_) }} + . q[sub {] + . q[ my $module = shift;] + . q[ Module::Runtime::require_module($module);] + . (ref $target && exists $target->{version} ? q[ $module->VERSION($version);] : q[]) + . q[ $module->].$action.q[(@_);] + . q[}] or die "Failed to build action sub to ${action} for ${target}: $@"; } diff --git a/t/import_into.t b/t/import_into.t index 7566438..8e57085 100644 --- a/t/import_into.t +++ b/t/import_into.t @@ -14,6 +14,7 @@ BEGIN { } my @importcaller; +my @versioncaller; my $version; BEGIN { package CheckFile; @@ -24,6 +25,7 @@ BEGIN { } sub VERSION { $version = $_[1]; + @versioncaller = caller; } } @@ -72,8 +74,10 @@ is $importcaller[1], 'import_into_inline.pl', 'import by level has correct file'; is $importcaller[2], 1, 'import by level has correct line'; +is scalar @versioncaller, 0, 'VERSION not called when not specified'; @importcaller = (); +@versioncaller = (); $version = undef; CheckFile->import::into({ package => 'ExplicitPackage', @@ -88,6 +92,12 @@ is $importcaller[1], 'explicit-file.pl', 'import with hash has correct file'; is $importcaller[2], 42, 'import with hash has correct line'; +is $versioncaller[0], 'ExplicitPackage', + 'VERSION with hash has correct package'; +is $versioncaller[1], 'explicit-file.pl', + 'VERSION with hash has correct file'; +is $versioncaller[2], 42, + 'VERSION with hash has correct line'; is $version, 219, 'import with hash has correct version'; @@ -104,6 +114,7 @@ BEGIN { } @importcaller = (); +@versioncaller = (); $version = undef; eval q{ package ExplicitLevel; @@ -119,6 +130,12 @@ is $importcaller[1], 'explicit-level.pl', 'import with level in hash has correct file'; is $importcaller[2], 42, 'import with level in hash has correct line'; +is $versioncaller[0], 'ExplicitLevel', + 'VERSION with level in hash has correct package'; +is $versioncaller[1], 'explicit-level.pl', + 'VERSION with level in hash has correct file'; +is $versioncaller[2], 42, + 'VERSION with level in hash has correct line'; is $version, 219, 'import with level in hash has correct version';