Declar...:Array(3pm)
β¨ 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::SimpleDeclare::Constraints::Simple::Library
go read those, iykyk π
π« AUTHOR π«
Robert 'phaylon' Sedlacek <phaylon@dunkelheit.at> π«Ά iconic behavior honestly
π 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 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
- 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