Data::...Factory(3pm)

πŸ“¦
version 4.88 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Data::...Factory(3pm) πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation and it's literally called Data::...Factory(3pm) β€” yes that's the whole name, don't @ me, we're going with it. buckle up, we're talking constraints πŸŽ€


✨ NAME ✨

Data::FormValidator::ConstraintsFactory β€” a whole module whose entire job is making constraints for HTML::FormValidator. that's it. that's the gig. πŸ‘‘


🌸 DESCRIPTION 🌸

so this module is the plug β€” it's full of functions that help you generate complex constraints. like, constraint-assembly-kit energy.

πŸ’… real talk though: if you're writing new code, go peek at Data::FormValidator::Constraints::MethodsFactory instead. it's the modern alternative to what's living here, and it comes with improved names and syntax. glow-up behavior fr fr.

πŸ¦‹ SYNOPSIS πŸ¦‹

use Data::FormValidator::ConstraintsFactory qw( :set :bool );

constraints => {
param1 => make_or_constraint(
        make_num_set_constraint( -1, ( 1 .. 10 ) ),
        make_set_constraint( 1, ( 20 .. 30 ) ),
      ),
province => make_word_set_constraint( 1, "AB QC ON TN NU" ),
bid  => make_range_constraint( 1, 1, 10 ),
}

look at that. iconic. no notes. ✨


πŸ’€ BOOLEAN CONSTRAINTS πŸ’€

these ones slide in when you use the :bool tag.

🌈 make_not_constraint( $c1 )

makes a constraint that returns the negation of whatever constraint $c1 returned. it's giving contrarian, and honestly? valid.

🌈 make_or_constraint( @constraints )

makes a constraint that returns the result of the first constraint that returns a non-false result. first one to show up wins, periodt.

🌈 make_and_constraint( @constraints )

makes a constraint that returns the result of the first constraint that returns a non-false result β€” but only if all the constraints return non-false results. everybody has to show up to the party or nobody gets in. πŸšͺ


πŸŽ€ SET CONSTRAINTS πŸŽ€

these bad boys are available via the :set tag.

πŸ“ make_set_constraint( $res, @elements )

makes a constraint that returns $res if the value is one of the @elements set β€” otherwise it returns the negation of $res. oh, and the comparison operator is eq.

πŸ“ make_num_set_constraint( $res, @elements )

same vibe, different math: returns $res if the value is one of the @elements set, negation of $res otherwise. the comparison operator here is ==.

πŸ“ make_word_set_constraint( $res, $set )

makes a constraint that returns $res if the value is a word in $set, or the negation of $res otherwise. words words words πŸ“š

πŸ“ make_cmp_set_constraint( $res, $cmp, @elements )

makes a constraint that returns $res if the value is one of the @elements set, or the negation of $res otherwise.

$cmp is a function that takes two arguments and should return true or false depending on whether those two elements are equal. you bring the comparison logic, it brings the constraint. collab. 🀝


πŸ”₯ NUMERICAL LOGICAL CONSTRAINTS πŸ”₯

grab these with the :num tag.

πŸ’œ make_clamp_constraint( $res, $low, $high )

makes a constraint that returns $res if the value is between $low and $high bounds included β€” or its negation otherwise. cozy little range hug.

πŸ’œ make_lt_constraint( $res, $bound )

returns $res if the value is lower than $bound, or the negation of $res otherwise.

πŸ’œ make_le_constraint( $res, $bound )

returns $res if the value is lower or equal than $bound, or the negation of $res otherwise.

πŸ’œ make_gt_constraint( $res, $bound )

returns $res if the value is greater than $bound, or the negation of $res otherwise.

πŸ’œ make_ge_constraint( $res, $bound )

returns $res if the value is greater or equal than $bound, or the negation of $res otherwise.


⭐ OTHER CONSTRAINTS ⭐

🧚 make_length_constraint($max_length)

makes a constraint that returns true if the value has a length of less than or equal to $max_length. short and sweet, literally. πŸ“


πŸ‘€ SEE ALSO πŸ‘€


🫢 AUTHOR 🫢

  • Author: Francis J. Lacoste <francis.lacoste@iNsu.COM>
  • Maintainer: Mark Stosberg <mark@summersault.com>

Copyright (c) 2000 iNsu Innovations Inc. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms as perl itself.


and that's the whole page bestie πŸ’– this was shipped as part of perl v5.34.0 and dated 2022-06-12 β€” go forth and constrain responsibly, mwah πŸ’…βœ¨

πŸ“¦ where this page comes from