diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm index 0066535..0de3075 100644 --- a/lib/Module/Metadata.pm +++ b/lib/Module/Metadata.pm @@ -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 $Foo::Bar::VERSION, but Foo::Bar isn't diff --git a/t/lib/0_1/Bar.pm b/t/lib/0_1/Bar.pm new file mode 100644 index 0000000..bb3303d --- /dev/null +++ b/t/lib/0_1/Bar.pm @@ -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; diff --git a/t/version.t b/t/version.t index f97a19d..99d7208 100644 --- a/t/version.t +++ b/t/version.t @@ -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'); @@ -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';