From: Karen Etheridge Date: Sun, 15 Dec 2024 20:25:18 +0000 (-0800) Subject: fix string comparisons with $] to use numeric comparison instead X-Git-Tag: v0.28~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0429db7fe681a8ced0e664385b4e52777e952e0d;p=p5sagit%2FSub-Name.git fix string comparisons with $] to use numeric comparison instead The fix follows Zefram's suggestion from https://www.nntp.perl.org/group/perl.perl5.porters/2012/05/msg186846.html On older perls, however, $] had a numeric value that was built up using floating-point arithmetic, such as 5+0.006+0.000002. This would not necessarily match the conversion of the complete value from string form [perl #72210]. You can work around that by explicitly stringifying $] (which produces a correct string) and having that numify (to a correctly-converted floating point value) for comparison. I cultivate the habit of always stringifying $] to work around this, regardless of the threshold where the bug was fixed. So I'd write use if "$]" >= 5.014, warnings => "non_unicode"; This ensures that the comparisons will still work when Perl's major version changes to anything greater than 9. --- diff --git a/Changes b/Changes index 99e8912..e7a9e65 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for Sub-Name {{$NEXT}} + - fix version comparison logic for forward compatibility 0.27 2023-04-29 12:32:26Z - skip quote-separator tests on newer perls that deprecate this behaviour diff --git a/t/exotic_names.t b/t/exotic_names.t index 02887b5..c1c23cf 100644 --- a/t/exotic_names.t +++ b/t/exotic_names.t @@ -101,8 +101,8 @@ for my $ord (@ordinal) { my $expected; SKIP: { skip 'single quote as a package separator has been '. - ("$]" gt '5.041001' ? 'removed' : 'deprecated'), 3 - if $ord == 39 and "$]" gt '5.037009'; + ("$]" > 5.041001 ? 'removed' : 'deprecated'), 3 + if $ord == 39 and "$]" > 5.037009; if ( chr($ord) =~ m/^[$legal_ident_char]$/o ) { # compile directly $expected = "native::$fullname"; diff --git a/t/quotes-bug.t b/t/quotes-bug.t index 3ea3242..621ea34 100644 --- a/t/quotes-bug.t +++ b/t/quotes-bug.t @@ -6,9 +6,9 @@ use if $ENV{AUTHOR_TESTING}, 'Test::Warnings'; use Sub::Name; plan skip_all => 'single quote as a package separator has been removed' - if "$]" gt '5.041001'; + if "$]" > 5.041001; plan skip_all => 'single quote as a package separator has been deprecated' - if "$]" gt '5.037009'; + if "$]" > 5.037009; my $sub = sub { (caller(0))[3] }; subname "foo::quz'bar::baz", $sub;