Declar...encial(3pm)
π Declare::Constraints::Simple::Library::Referencial β Ref Constraints π
okay bestie, so this is a page from the User Contributed Perl Documentation collection, and it's literally all about checking whether your refs are valid and what kind of refs they are. no cap. it's giving "who even are you, reference?" energy and i'm obsessed. π¦
β¨ NAME β¨
Declare::Constraints::Simple::Library::Referencial β Ref Constraints. that's it, that's the whole name. say it three times fast, i dare you. π
πΈ SYNOPSIS πΈ
here's the vibe, in code, exactly as the ancestors wrote it:
# scalar or array references
my $scalar_or_array = IsRefType( qw(SCALAR ARRAY) );
# scalar reference
my $int_ref = IsScalarRef( IsInt );
# accept mappings of ids to objects with "name" methods
my $id_obj_map =
IsHashRef( -keys => IsInt,
-values => And( IsObject,
HasMethods('name') ));
# an integer list
my $int_list = IsArrayRef( IsInt );
# accept code references
my $is_closure = IsCodeRef;
# accept a regular expression
my $is_regex = IsRegex;
likeβ¦ look at her. she's beautiful. she checks ALL the refs. π
π¦ DESCRIPTION π¦
so this library is where all the constraints live that test the validity of references and their types. if you've got a ref and you're like "girl, what ARE you," this is the library that answers. periodt.
π CONSTRAINTS π
π IsRefType(@types)
valid if the value is a reference of a kind that's in @types. that's the whole check. simple, iconic, no notes.
π IsScalarRef($constraint)
this one's true if the value is a scalar reference. and get this β you can pass a possible constraint for the scalar reference's target value too. e.g.
my $test_integer_ref = IsScalarRef(IsInt);
so like, not just "is it a scalar ref" but "is it a scalar ref holding an int." main character behavior fr fr.
β IsArrayRef($constraint)
the value is valid if the value is an array reference. and you can validate the contents of the array by passing another $constraint as an argument. slay.
the stack or path part of IsArrayRef is IsArrayRef[$index] where $index is the index of the failing element. so when something goes wrong, she tells you exactly which one. queen behavior. π«Ά
π IsHashRef(-keys => $constraint, -values => $constraint)
true if the value is a hash reference. it can also take two named parameters:
-keyscan pass a constraint to check the hash's keys-valuesdoes the same for its values
the stack or path part of IsHashRef looks like IsHashRef[$type $key] where $type is either "val" or "key" depending on what was validated, and $key being the key that didn't pass validation. she names names. π
π§ IsCodeRef()
code references have to be valid to pass this constraint. that's the bar. clear it or don't. β¨
πΈ IsRegex()
true if the value is a regular expression built with qr.
β οΈ note however, that a simple string that could be used like /$rx/ will not pass this constraint. i know. devastating. π
you can combine multiple constraints with And(@constraints) though, so it's not over, bestie. we adapt. π
π₯ SEE ALSO π₯
Declare::Constraints::SimpleDeclare::Constraints::Simple::Library
go read those too, iykyk. π
π AUTHOR π
Robert 'phaylon' Sedlacek <phaylon@dunkelheit.at>
π LICENSE AND COPYRIGHT π
this module is free software, you can redistribute it and/or modify it under the same terms as perl itself. go off, legally. π«Ά
and that's the whole page, bestie!! this beauty shipped with perl v5.32.0, dated 2021-01-09, and yeah β the header and footer said the same thing three times, which is so on brand. 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