Declar...:Array(3pm)

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

✨ NAME ✨

Declare::Constraints::Simple::Library::Array β€” literally just Array Constraints, bestie πŸ’…

It lives in the User Contributed Perl Documentation section, so you already know it's the people's manpage πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

# accept a list of pairs
my $pairs_validation = IsArrayRef( HasArraySize(2,2) );

# integer => object pairs
my $pairs = And( OnEvenElements(IsInt),
                 OnOddElements(IsObject) );

# a three element array
my $tri = And( HasArraySize(3,3),
               OnArrayElements(0, IsInt,
                               1, IsDefined,
                               2, IsClass) );

okay so that first one? accepting a list of pairs? that's the whole vibe ✨ the second one is giving integer => object pairs πŸ’– and the third one is literally a three element array, no notes πŸŽ€


πŸ’– DESCRIPTION πŸ’–

This module contains all the constraints that can be applied to array references. Every single one. Not a crumb left behind πŸ“


πŸ‘‘ CONSTRAINTS πŸ‘‘

🌸 HasArraySize([$min, [$max]])

So $min defaults to 1. Which means a spec like

my $profile = HasArraySize;

checks for at least one value. One (1) lil guy minimum, that's the requirement 🫢

Now. If you want to force an exact size of the array, you just pass the same value for both:

my $profile = HasArraySize(3, 3);

same number twice = exact size, no wiggle room, periodt πŸ’…


🌈 OnArrayElements($key => $constraint, $key => $constraint, ...)

Applies the $constraints to the corresponding $keys if they are present. And if you need keys that are actually required? Go see "HasArraySize". It's giving "read the other section bestie" 😭


πŸ¦‹ OnEvenElements($constraint)

Runs the constraint on all even elements of an array. Also peep "OnOddElements" for the other half of the squad πŸ’œ


🧚 OnOddElements($constraint)

Runs the constraint on all odd elements of an array. And yeah, "OnEvenElements" is right there if you need it β€” they're a matched set, fr fr ✨


🌟 SEE ALSO 🌟

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

go read those, iykyk πŸ“š


πŸ’« AUTHOR πŸ’«

Robert 'phaylon' Sedlacek <phaylon@dunkelheit.at> 🫢 iconic behavior honestly


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


and that's the whole page bestie!! brought to you by perl v5.32.0, dated 2021-01-09 πŸ’…βœ¨ go forth and validate those arrays, mwah πŸŽ€πŸ¦‹
πŸ“¦ where this page comes from