Declar...eneral(3pm)
β¨ 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:$namemust already be chilling in$scopefrom 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::SimpleDeclare::Constraints::Simple::Library
π AUTHOR π
Robert 'phaylon' Sedlacek <phaylon@dunkelheit.at> β ty king π«Ά
β LICENSE AND COPYRIGHT β
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
- 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