From a08064a10e5254e9c982e562b6fdab0ee5e277af Mon Sep 17 00:00:00 2001 From: Jim Avera Date: Sun, 9 Feb 2025 17:59:43 -0800 Subject: [PATCH 1/2] Make fake_smartmatch() use match::simple --- META.json | 1 + META.yml | 1 + lib/ODF/lpOD/Common.pm | 44 +++++------------------------------------- 3 files changed, 7 insertions(+), 39 deletions(-) diff --git a/META.json b/META.json index 178787d..fc8c656 100644 --- a/META.json +++ b/META.json @@ -41,6 +41,7 @@ "IO::File" : "1.14", "Image::Size" : "0", "LWP::Simple" : "0", + "match::simple" : "0.012", "Time::Local" : "1.07", "XML::Twig" : "3.34", "experimental" : "0", diff --git a/META.yml b/META.yml index 003034a..90a2646 100644 --- a/META.yml +++ b/META.yml @@ -27,6 +27,7 @@ requires: IO::File: 1.14 Image::Size: 0 LWP::Simple: 0 + match::simple: 0.012 Time::Local: 1.07 XML::Twig: 3.34 experimental: 0 diff --git a/lib/ODF/lpOD/Common.pm b/lib/ODF/lpOD/Common.pm index 800c637..cc34bca 100644 --- a/lib/ODF/lpOD/Common.pm +++ b/lib/ODF/lpOD/Common.pm @@ -900,48 +900,14 @@ sub not_implemented # supposedly remove them entirely. To preserve existing semantics of # existing code including user-visible functions, I'm emulating (a subset of) # the ~~ operator here. -Jim Avera 6/10/2024 +# +# 2/9/2025[jima]: Using CPAN's match::simple instead (my code was buggy...) +use match::simple 0.012; sub fake_smartmatch { + confess "Expecting two arguments" unless @_ == 2; my ($L, $R) = @_; - my $err; - if (@_ != 2) { - $err = "expects two args"; - } - elsif (! defined($L)) { - return ! defined($R); - } - elsif (ref($L) ne "") { - $err = "only handles a simple left operand"; - } - elsif (! defined($R)) { - return ! defined($L); - } - elsif ((my $rtype = ref($R)) ne "") { - if ($rtype eq "ARRAY") { - return any { __SUB__->($L,$_) } @$R; - } - elsif ($rtype eq "HASH") { - return exists($R->{$L}); - } - elsif ($rtype eq "CODE") { - return $R->($L); - } - elsif ($rtype eq "RegExp") { - return $L =~ /$R/; - } - else { - $err = "does not handle operand of type $rtype" - } - } - else { - if (Scalar::Util::looks_like_number($R) || - Scalar::Util::looks_like_number($L)) { - return $L == $R; - } else { - return $L eq $R; - } - } - confess "fake_smartmatch $err"; + match::simple::match($L,$R) } #============================================================================= From a53dfe53590ca2027132365ca37eb1127ad743e1 Mon Sep 17 00:00:00 2001 From: Jim Avera Date: Sun, 9 Feb 2025 18:50:44 -0800 Subject: [PATCH 2/2] More arg checking in fake_smartmatch() --- lib/ODF/lpOD/Common.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ODF/lpOD/Common.pm b/lib/ODF/lpOD/Common.pm index cc34bca..aa8881b 100644 --- a/lib/ODF/lpOD/Common.pm +++ b/lib/ODF/lpOD/Common.pm @@ -906,8 +906,8 @@ use match::simple 0.012; sub fake_smartmatch { confess "Expecting two arguments" unless @_ == 2; - my ($L, $R) = @_; - match::simple::match($L,$R) + confess "Left side must be simple" if ref($_[0]); + match::simple::match($_[0],$_[1]) } #=============================================================================