README
1NAME
2 match::simple - simplified clone of smartmatch operator
3
4SYNOPSIS
5 use v5.10;
6 use match::simple;
7
8 if ($this |M| $that)
9 {
10 say "$this matches $that";
11 }
12
13DESCRIPTION
14 match::simple provides a simple match operator `|M|` that acts like a sane
15 subset of the (as of Perl 5.18) deprecated smart match operator. Unlike
16 smart match, the behaviour of the match is determined entirely by the
17 operand on the right hand side.
18
19 * If the right hand side is `undef`, then there is only a match if the
20 left hand side is also `undef`.
21
22 * If the right hand side is a non-reference, then the match is a simple
23 string match.
24
25 * If the right hand side is a reference to a regexp, then the left hand
26 is evaluated .
27
28 * If the right hand side is a code reference, then it is called in a
29 boolean context with the left hand side being passed as an argument.
30
31 * If the right hand side is an object which provides a `MATCH` method,
32 then it this is called as a method, with the left hand side being
33 passed as an argument.
34
35 * If the right hand side is an object which overloads `~~`, then a true
36 smart match is performed.
37
38 * If the right hand side is an arrayref, then the operator recurses into
39 the array, with the match succeeding if the left hand side matches any
40 array element.
41
42 * If any other value appears on the right hand side, the operator will
43 croak.
44
45 If you don't like the crazy Sub::Infix operator, you can alternatively
46 export a more normal function:
47
48 use v5.10;
49 use match::simple qw(match);
50
51 if (match($this, $that))
52 {
53 say "$this matches $that";
54 }
55
56 If you're making heavy use of this module, then this is probably your best
57 option, as it runs significantly faster.
58
59 XS Backend
60 If you install match::simple::XS, a faster XS-based implementation will be
61 used instead of the pure Perl functions. Depending on what sort of match
62 you are doing, this is likely to be several times faster. In extreme
63 cases, such as matching a string in an arrayref, it can be twenty-five
64 times faster, or more. However, where $that is a single regexp, it's
65 around 30% slower. Overall though, I think the performance improvement is
66 worthwhile.
67
68 If you want to take advantage of this speed up, use the `match` function
69 rather than the `|M|` operator. Otherwise all your gains will be lost to
70 the slow implementation of operator overloading.
71
72 The constant `match::simple::IMPLEMENTATION` tells you which backend is
73 currently in use.
74
75 Environment
76 Setting the `MATCH_SIMPLE_IMPLEMENTATION` environment variable to "PP"
77 encourages match::simple to use the pure Perl backend.
78
79BUGS
80 Please report any bugs to
81 <http://rt.cpan.org/Dist/Display.html?Queue=match-simple>.
82
83SEE ALSO
84 match::smart.
85
86 This module uses Exporter::Tiny.
87
88AUTHOR
89 Toby Inkster <tobyink@cpan.org>.
90
91COPYRIGHT AND LICENCE
92 This software is copyright (c) 2013-2014, 2017 by Toby Inkster.
93
94 This is free software; you can redistribute it and/or modify it under the
95 same terms as the Perl 5 programming language system itself.
96
97DISCLAIMER OF WARRANTIES
98 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
99 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
100 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
101
102