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

parse_version: handle "package version" syntax using the "hide from CPAN/PAUSE" hack #450

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
18 changes: 17 additions & 1 deletion lib/ExtUtils/MM_Unix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions t/parse_version.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down