NAME

Syntax::Infix::Smartmatch - Smartmatch done right

VERSION

version 0.002

SYNOPSIS

say "YES" if $value ~~ [1, 2, qr/42/];

DESCRIPTION

NOTE: This module is currently still experimental and the details of its behavior may still change.

This module implements a new, much simplified version of smartmatch. In particular the behavior only depends on the right side argument. In particular it will do the following based on the right side argument:

  • undef

    This will return not defined $left.

  • object

    If the object has smartmatch overloading (note: this might disappear in a future Perl version), that is called. Otherwise it returns object identity.

  • regex

    This is equivalent to $left =~ $right.

  • sub

    It will return the value of $right->($left)

  • array

    This will compare every element of @$left to see if it smartmatches every element of @$right. E.g. $left->[0] ~~ $right->[0] && $left->[1] ~~ $right->[1] && ...

  • bool

    This will always return $right. This particularly is useful in second order constructs such as Syntax::Keyword::Match (e.g. case($topic > 1). Bools are only available on perl v5.36 and up.

  • other

    This will return $left equ $right (defined $left and $left equ $right).

AUTHOR

Leon Timmermans <leont@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by Leon Timmermans.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.