Declar...eneral(3pm)

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

✨ NAME ✨

Declare::Constraints::Simple::Library::General β€” the General Constraints library, bestie. it's Declar...eneral if you're squinting at your terminal header, but we know her πŸ’…


🌸 SYNOPSIS 🌸

okay so like, here's the vibe:

# custom error messages
my $constraint =
  And( Message( 'You need to specify a Value', IsDefined ),
       Message( 'The specified Value is not an Int', IsInt ));

# build results
my $valid   = ReturnTrue;
my $invalid = ReturnFalse('Just because');

πŸ¦‹ DESCRIPTION πŸ¦‹

This library is literally the home base for the constraints and constraint-adjacent elements that apply generally to the whole framework. general girlies, this one's for you πŸ’–


πŸ‘‘ CONSTRAINTS πŸ‘‘

πŸ’Œ Message($message, $constraint)

Overrides the "message" that's set on the result object whenever $constraint fails. example time:

my $message = 'How hard is it to give me a number?';
my $constraint = Message($message, IsNumber);

my $result = $constraint->('duh...');
print $result->message, "\n";

ok so here's the tea: Message overrides the error message returned by its whole subtree. BUT β€” and this is the important part, no cap β€” the Message spec nearest to the point of failure is the one that wins. so watch this:

my $constraint = Message( 'Foo',
                          IsArrayRef( Message( 'Bar', IsInt )));

my $result = $constraint->(['I am not an Integer']);
print $result->message;

that one prints "Bar". but this one:

my $result = $constraint->('I\'m not even an ArrayRef');
print $result->message;

outputs "Foo". see how that works?? closest to the fail = main character 🌟

πŸŽ€ Scope($name, $constraint)

Runs the $constraint you passed in, but inside a freshly generated scope named $name. new scope, who dis ✨

πŸ“ SetResult($scope, $name, $constraint)

Stores the result of evaluating $constraint in $scope, filed under $name. like a lil save file for your results πŸ’Ύ

🧚 IsValid($scope, $name)

Returns a true result if the result called $name β€” which has to have been stored earlier in the scope named $scope, no exceptions β€” was valid.

heads up bestie: $name must already be chilling in $scope from a previous store. don't come in here with a fresh name and expect results πŸ™ˆ

πŸ’œ ReturnTrue()

Returns a true result. that's it. that's the whole function. iconic behaviour honestly πŸ‘‘

🌈 ReturnFalse($msg)

Returns a false result with $msg as its error message. sometimes you just gotta say no, and say why πŸ’€


πŸ”₯ SEE ALSO πŸ”₯

  • Declare::Constraints::Simple
  • Declare::Constraints::Simple::Library

πŸ’– AUTHOR πŸ’–

Robert 'phaylon' Sedlacek <phaylon@dunkelheit.at> β€” ty king 🫢


This module is free software, you can redistribute it and/or modify it under the same terms as perl itself. slay, open source legend πŸ’…


and that's the whole page, bestie!! this was pulled from perl v5.32.0, dated 2021-01-09, and it lives in the User Contributed Perl Documentation section of your manual β€” Declar...eneral(3pm), mwah 😘

πŸ“¦ where this page comes from