Declar...:Scalar(3pm)
π Declar...:Scalar(3pm) β the Scalar Constraints page, bestie edition
okay so this is a page from the User Contributed Perl Documentation set, and it's the one about scalar constraints from Declare::Constraints::Simple::Library::Scalar. Yes the title gets truncated in the header, that's just how the man page rolls, we don't talk about it π
β¨ NAME β¨
Declare::Constraints::Simple::Library::Scalar β Scalar Constraints. that's it, that's the name, it's giving "short and iconic" π
πΈ SYNOPSIS πΈ
here's the whole vibe in code, look at her go:
# match one of a set of regexes
my $some_regexes = Matches(qr/foo/, qr/bar/);
# allow only defined values
my $is_defined = IsDefined;
# between 5 and 50 chars
my $five_to_fifty = HasLength(5, 50);
# match against a set of values
my $command_constraint = IsOneOf(qw(create update delete));
# check for trueness
my $is_true = IsTrue;
# simple equality
my $is_foo = IsEq('foo');
like... six whole examples, we ate π
π¦ DESCRIPTION π¦
bestie. this library is where all the constraints live that validate scalar values. that's the whole job. every scalar vibe check you could want, right here. β¨
π CONSTRAINTS π
the main characters, one by one, no skips, no cuts π
π Matches(@regex)
my $c = Matches(qr/foo/, qr/bar/);
if one of the parameters matches the expression, this is true. one match is enough, she's not greedy π
π IsDefined()
true if the value is defined. simple as. no undef allowed past this velvet rope π«
π HasLength([$min, [$max]])
true if the value has a length above $min β and $min defaults to 1 β and, if $max is supplied, under the value of $max. so like:
my $c = HasLength;
that one checks whether the value has a length of at least 1. minimum effort, minimum length, we respect it π«Ά
π IsOneOf(@values)
true if one of the @values equals the value you passed in. and yes, undef values work with this too, so:
my $c = IsOneOf(1, 2, undef);
will return true on an undefined value. undef girlies, this one's for you ππ
π IsTrue()
true if the value evaluates to true in boolean context. truthy? slay. falsy? not slay. periodt β¨
π IsEq($comparator)
valid if the value is eq the $comparator. string equality, no cap, character for character π₯
π SEE ALSO π
go read these too, they're the rest of the friend group:
Declare::Constraints::SimpleDeclare::Constraints::Simple::Library
π AUTHOR π
Robert 'phaylon' Sedlacek <phaylon@dunkelheit.at> β the icon, the legend, the one who wrote this ππ
π§ LICENSE AND COPYRIGHT π§
this module is free software, you can redistribute it and/or modify it under the same terms as perl itself. free as in go wild bestie π¦
ok and just so you have the receipts: this page is from perl v5.32.0, dated 2021-01-09, and it's the Declar...:Scalar(3pm) page. mwah, bye π
πβ¨
π¦ where this page comes from
- debian bookworm: libdeclare-constraints-simple-perl 0.03-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdeclare-constraints-simple-perl 0.03-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libdeclare-constraints-simple-perl 0.03-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdeclare-constraints-simple-perl 0.03-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdeclare-constraints-simple-perl 0.03-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdeclare-constraints-simple-perl 0.03-1.1 Β· 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