diff --git a/lib/ExtUtils/MM_Unix.pm b/lib/ExtUtils/MM_Unix.pm index fe385984f..eda91d239 100644 --- a/lib/ExtUtils/MM_Unix.pm +++ b/lib/ExtUtils/MM_Unix.pm @@ -3005,16 +3005,32 @@ sub parse_version { my($self,$parsefile) = @_; my $result; + my $package_version_rx = qr{ \w[\w\:\']* \s+ (v?[0-9._]+) \s* (;|\{) }x; + local $/ = "\n"; local $_; open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!"; my $inpod = 0; + my $maybe_hide_from_cpan = 0; while (<$fh>) { $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod; next if $inpod || /^\s*#/; chop; next if /^\s*(if|unless|elsif)/; - if ( m{^ \s* package \s+ \w[\w\:\']* \s+ (v?[0-9._]+) \s* (;|\{) }x ) { + if ($maybe_hide_from_cpan) { + $maybe_hide_from_cpan = 0; + if ( m{^ \s* $package_version_rx }x ) { + no warnings; + $result = $1; + } else { + next; + } + } + elsif ( m{^ \s* package \s+ \# }x) { + $maybe_hide_from_cpan = 1; + next; + } + elsif ( m{^ \s* package \s+ $package_version_rx }x ) { no warnings; $result = $1; } diff --git a/t/parse_version.t b/t/parse_version.t index ecba13d8a..af8bf8f8c 100755 --- a/t/parse_version.t +++ b/t/parse_version.t @@ -78,6 +78,11 @@ END $versions{<<'END'} = '2.34'; package Foo::100; our $VERSION = 2.34; +END + + $versions{<<'END'} = '1.23'; +package # hide from CPAN + Foo 1.23; END }