match::smart(3pm)

match::smart3pm

Clone of smartmatch operator

Usage

   use v5.10;
   use match::smart;
   
   if ($this |M| $that)
   {
      say "$this matches $that";
   }

Overview

match::smart provides a match operator "|M|" that acts like more or less identically to the (as of Perl 5.18) deprecated smart match operator.

If you don't like the crazy Sub::Infix operator, you can alternatively export a more normal function:

   use v5.10;
   use match::smart qw(match);
   
   if (match($this, $that))
   {
      say "$this matches $that";
   }

Differences with ~~

There were major changes to smart match between 5.10.0 and 5.10.1. This module attempts to emulate the behaviour of the operator in more recent versions of Perl. In particular, 5.18.0 (minus the warnings). Divergences not noted below should be considered bugs.

While the real smart match operator implicitly takes references to operands that are hashes or arrays, match::smart's operator does not.

   @foo ~~ %bar       # means: \@foo ~~ \%bar
   @foo |M| %bar      # means: scalar(@foo) |M| scalar(%bar)

If you want the "\@foo ~~ \%bar" behaviour, you need to add the backslashes yourself:

   \@foo |M| \%bar

Similarly:

   "foo" ~~  /foo/    # works
   "foo" |M| /foo/    # no worky!
   "foo" |M| qr/foo/  # do this instead

match::smart treats the "MATCH" method on blessed objects (if it exists) like an overloaded "~~". This is for compatibility with match::simple, and for compatibility with versions of Perl that don't have documented support for overloading "~~".

Disclaimer of warranties

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Releases

6 releases since Debian 8 (Jessie); the text changed 5 times.

  1. 8
  2. 9
  3. 10
  4. 11
  5. 12
  6. 13

Bugs

Please report any bugs to <https://github.com/tobyink/p5-match-simple/issues>.

Author

Toby Inkster <[email protected]>.

From libmatch-simple-perl 0.012-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.