Declar...:Scalar(3pm)

πŸ“¦
version 0.03 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’… 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::Simple
  • Declare::Constraints::Simple::Library

πŸŽ€ AUTHOR πŸŽ€

Robert 'phaylon' Sedlacek <phaylon@dunkelheit.at> β€” the icon, the legend, the one who wrote this πŸ’–πŸ‘‘


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