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

Add $self->{inc} to @INC whilst evaluating version #26

Open
wants to merge 1 commit 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: 4 additions & 0 deletions lib/Module/Metadata.pm
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,10 @@ sub _evaluate_version_line {
$eval = $1 if $eval =~ m{^(.+)}s;

local $^W;

# if inc has been set, look there for any required modules
local @INC = (@{$self->{inc}}, @INC) if defined $self->{inc};

# Try to get the $VERSION
my $vsub = __clean_eval($eval);
# some modules say $VERSION <equal sign> $Foo::Bar::VERSION, but Foo::Bar isn't
Expand Down
12 changes: 12 additions & 0 deletions t/lib/0_1/Bar.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package Bar;
our $VERSION = '0.1';

package Bar::History;

# adapted from WWW::Scripter
<<'mldistwatch' if 0;
use Bar; $VERSION = $Bar'VERSION;
mldistwatch
our $VERSION = $Bar'VERSION;

1;
10 changes: 4 additions & 6 deletions t/version.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Test::More;
use Module::Metadata;
use lib "t/lib/0_2";

plan tests => 4;
plan tests => 6;

require Foo;
is($Foo::VERSION, 0.2, 'affirmed version of loaded module');
Expand All @@ -17,8 +17,6 @@ is($Foo::VERSION, 0.2, 'loaded module still retains its version');
ok(eval "use Foo 0.2; 1", 'successfully loaded module again')
or diag 'got exception: ', $@;






my $bar_meta = Module::Metadata->new_from_module("Bar", inc => [ "t/lib/0_1" ] );
is scalar @{$bar_meta->{packages}}, 2, 'found 2 packages in Bar';
is $bar_meta->{versions}{'Bar::History'}, $bar_meta->{versions}{'Bar'}, 'Bars version gets passed to Bar::History';