From 52e38643859d9b09548c80eec912324fa88f839f Mon Sep 17 00:00:00 2001 From: Slaven Rezic Date: Sun, 4 Feb 2024 20:25:13 +0100 Subject: [PATCH] parse_version: handle "package version" syntax using the "hide from CPAN/PAUSE" hack parse_version cannot parse a "package $package $version" if the line is broken after the "package" keyword, which is usually done for the "hide from CPAN" (or "hide from PAUSE") hack. Sample affected module: https://metacpan.org/release/PEVANS/IO-Async-0.803/source/lib/IO/Async/Internals/Connector.pm#L6 (The previous version found in the 0.802 distribution used the traditional package keyword, and there parse_version worked) --- lib/ExtUtils/MM_Unix.pm | 18 +++++++++++++++++- t/parse_version.t | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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 }