1match::simple(3)      User Contributed Perl Documentation     match::simple(3)
2
3
4

NAME

6       match::simple - simplified clone of smartmatch operator
7

SYNOPSIS

9          use v5.10;
10          use match::simple;
11
12          if ($this |M| $that)
13          {
14             say "$this matches $that";
15          }
16

DESCRIPTION

18       match::simple provides a simple match operator "|M|" that acts like a
19       sane subset of the (as of Perl 5.18) deprecated smart match operator.
20       Unlike smart match, the behaviour of the match is determined entirely
21       by the operand on the right hand side.
22
23       •   If the right hand side is "undef", then there is only a match if
24           the left hand side is also "undef".
25
26       •   If the right hand side is a non-reference, then the match is a
27           simple string match.
28
29       •   If the right hand side is a reference to a regexp, then the left
30           hand is evaluated .
31
32       •   If the right hand side is a code reference, then it is called in a
33           boolean context with the left hand side being passed as an
34           argument.
35
36       •   If the right hand side is an object which provides a "MATCH"
37           method, then it this is called as a method, with the left hand side
38           being passed as an argument.
39
40       •   If the right hand side is an object which overloads "~~", then a
41           true smart match is performed.
42
43       •   If the right hand side is an arrayref, then the operator recurses
44           into the array, with the match succeeding if the left hand side
45           matches any array element.
46
47       •   If any other value appears on the right hand side, the operator
48           will croak.
49
50       If you don't like the crazy Sub::Infix operator, you can alternatively
51       export a more normal function:
52
53          use v5.10;
54          use match::simple qw(match);
55
56          if (match($this, $that))
57          {
58             say "$this matches $that";
59          }
60
61       If you're making heavy use of this module, then this is probably your
62       best option, as it runs significantly faster.
63
64   XS Backend
65       If you install match::simple::XS, a faster XS-based implementation will
66       be used instead of the pure Perl functions. Depending on what sort of
67       match you are doing, this is likely to be several times faster. In
68       extreme cases, such as matching a string in an arrayref, it can be
69       twenty-five times faster, or more. However, where $that is a single
70       regexp, it's around 30% slower.  Overall though, I think the
71       performance improvement is worthwhile.
72
73       If you want to take advantage of this speed up, use the "match"
74       function rather than the "|M|" operator. Otherwise all your gains will
75       be lost to the slow implementation of operator overloading.
76
77       The constant "match::simple::IMPLEMENTATION" tells you which backend is
78       currently in use.
79
80   Environment
81       Setting the "MATCH_SIMPLE_IMPLEMENTATION" environment variable to "PP"
82       encourages match::simple to use the pure Perl backend.
83

BUGS

85       Please report any bugs to
86       <http://rt.cpan.org/Dist/Display.html?Queue=match-simple>.
87

SEE ALSO

89       match::smart.
90
91       This module uses Exporter::Tiny.
92

AUTHOR

94       Toby Inkster <tobyink@cpan.org>.
95
97       This software is copyright (c) 2013-2014, 2017 by Toby Inkster.
98
99       This is free software; you can redistribute it and/or modify it under
100       the same terms as the Perl 5 programming language system itself.
101

DISCLAIMER OF WARRANTIES

103       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
104       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
105       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
106
107
108
109perl v5.36.0                      2022-07-22                  match::simple(3)
Impressum