Syntax...or::Is(3pm)
π Syntax::Operator::Is π
okay bestie, so we're talking about Syntax::Operator::Is β the 3pm manual page, the Perl module one, from the User Contributed Perl Documentation corner of the world. It's a match operator that uses Data::Checks constraints. Iconic behavior, honestly. π
β¨ NAME β¨
"Syntax::Operator::Is" β a match operator using Data::Checks constraints. That's the whole vibe. The name is the plot. π
β¨ SYNOPSIS β¨
So here's how we're doing this on Perl v5.38 or later, bestie:
use v5.38;
use Syntax::Operator::Is;
use Data::Checks qw( Num Object );
my $x = ...;
if($x is Num) {
say "x can be used as a number";
}
elsif($x is Object) {
say "x can be used as an object";
}
Orrrrr you can go via Syntax::Keyword::Match on Perl v5.14 or later, if that's more your main character energy:
use v5.14;
use Syntax::Operator::Is;
use Syntax::Keyword::Match;
use Data::Checks qw( Num Object );
my $x = ...;
match($x : is) {
case(Num) { say "x can be used as a number"; }
case(Object) { say "x can be used as an object"; }
}
β¨ DESCRIPTION β¨
This module hands you an infix operator that checks if a given value matches a value constraint provided by Data::Checks. That's it, that's the whole job. Serving cunt, no notes. π
Support for custom infix operators was added in the Perl 5.37.x development cycle, and it's been available from development release v5.37.7 onwards, which means it's in Perl v5.38 onwards too. If you want the whole lore, the documentation of XS::Parse::Infix describes the situation in more detail. π
Now, Perl versions before all that don't support custom infix operators β but you can still totally use them via "XS::Parse::Infix" and hence XS::Parse::Keyword. Custom keywords that attempt to parse operator syntax may be able to use these. One such module is Syntax::Keyword::Match; go look at the SYNOPSIS example I gave you above. It's right there. π«Ά
π Operator Name vs "Test::More" / "Test2::V0" π
This module provides a named operator called is. And here's the tea: the same name is used by both Test::More and Test2::V0 as a unit test assertion function. π Since each has to be imported by request, this does not cause issues for code that does not try to use both of them at once. Most real use-cases will not be unit test scripts, and most unit test scripts will not need to use this operator. So like, mostly we're fine.
But in situations where you do need to use this is operator and one of the testing modules at the same time (for example, during a unit test of some check-related code), note this: because of the way infix operator plugins work, the named operator will always take precedence, and thus you will need to call the is() testing function by its fully-qualified name:
use Test2::V0;
use Syntax::Operator::Is;
Test2::V0::is( 1 is Num, builtin::true, '1 is Num' );
Alternatively β and this is the slick move β use the ability of XS::Parse::Infix to import the operator with a different name and avoid the collision entirely:
use Test2::V0;
use Syntax::Operator::Is is => { -as => "is_checked" };
is( 1 is_checked Num, builtin::true, '1 is Num' );
Like. Problem? Gone. We love a workaround. π
β¨ OPERATORS β¨
π¦ is π¦
my $ok = $value is $Constraint;
Yields true if the given value is accepted by the given constraint checker. Yields false but should not otherwise throw an exception if the value is rejected. So no dramatic exits, no tantrums β just a chill little bool. π
ngl bestie, "should not otherwise throw an exception" is doing a lot of heavy lifting there β that's the contract, respect it.
β¨ AUTHOR β¨
Paul Evans <leonerd@leonerd.org.uk> β the icon who made this all happen. π
okay that's the whole page, bestie, you're officially educated π
this lil sign-off brought to you by perl v5.42.3, dated 2026-08-21, and yes the manual page is Syntax...or::Is(3pm) β go forth and is responsibly. mwah. π
β¨
π¦ where this page comes from
- ubuntu stonking: libsyntax-operator-is-perl 0.02-3build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms