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..aa8881b 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 { - 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"; + confess "Expecting two arguments" unless @_ == 2; + confess "Left side must be simple" if ref($_[0]); + match::simple::match($_[0],$_[1]) } #=============================================================================