smartmatch(3)
π smartmatch β pluggable smart matching backends π
okay bestie, so this is smartmatch, a page from the User Contributed Perl Documentation corner of the manual universe, and it is exactly the kind of chaotic little module that makes perl perl. buckle up π
β¨ VERSION β¨
version 0.05 β yes queen, we're on 0.05, keep up π
πΈ SYNOPSIS πΈ
here's the whole vibe, verbatim, no notes:
1 ~~ 2; # false
{
use smartmatch sub { 1 };
1 ~~ 2; # true
no smartmatch;
1 ~~ 2; # false
use smartmatch 'custom';
1 ~~ 2; # smartmatch::engine::custom::match(1, 2)
}
1 ~~ 2; # false
see how the truthiness of 1 ~~ 2 keeps flip-flopping depending on which block you're standing in? that's the whole point, and it's giving main character energy ngl π
π¦ DESCRIPTION π¦
NOTE: This module is still experimental, and the API may change at any point. You have been warned! π¨
so basically, this module lets you override the behavior of the smart match operator (~~). when you write use smartmatch $matcher, it hooks into the compiler and swaps out the smartmatch opcode for a call to a custom subroutine instead. that subroutine gets specified either as a coderef, or as a string β and if it's a string, smartmatch::engine:: gets prepended to it, and the result is used as the name of a package where it'll go looking for a subroutine called match. π
that subroutine gets called with two arguments: the values on the left and right sides of the smart match operator. whatever it returns is the result. simple as that, no cap.
also, this module is lexically scoped, which means when you're done with your little custom-match era you can just call no smartmatch and boom β you're back to the core perl smart matching behavior. closure, but make it syntax. π
π FUNCTIONS π
π«Ά callback_at_level($level)
returns a coderef. when you call that coderef with two arguments, it'll do a smartmatch on them β using the smartmatch implementation that was in effect at caller level $level. so like, time-travel but for match semantics. iconic honestly β³β¨
π BUGS π
no known bugs. she's perfect, she's booked, she's busy. π
...okay but fr fr, if you do find one, please report it through RT: email bug-smartmatch at rt.cpan.org, or browse on over to <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=smartmatch>. do it for the culture π
β SEE ALSO β
"Smart matching in detail" in perlsynβ the lore, the canon, the required reading πsmartmatch::engine::coreβ the original flavor engine π
π SUPPORT π
you can find this documentation for this module with the perldoc command:
perldoc smartmatch
you can also go looking for information at:
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/smartmatch>
- CPAN Ratings
<http://cpanratings.perl.org/d/smartmatch>
- RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=smartmatch>
- Search CPAN
<http://search.cpan.org/dist/smartmatch>
four whole places to lurk. we love a supportive ecosystem π«Ά
π AUTHOR π
Jesse Luehrs <doy at tozt dot net> β absolute legend, respect the craft π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2012 by Jesse Luehrs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie! this one ships out of perl v5.42.0, dated 2025-07-25, and it's the smartmatch(3) page we've been yapping about this entire time. go forth and override some operators responsibly π¦β¨π
π¦ where this page comes from
- fedora 43: perl-smartmatch 0.05-39.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms