Declar...ary::OO(3pm)
β¨ Declare::Constraints::Simple::Library::OO β OO Constraints β¨
okay bestie, so this is part of the User Contributed Perl Documentation situation, and it's the module you want when you're validating stuff in a full object oriented way π like, is this thing an object? is it a class? does it even have the methods you're promising it has? we're checking all of that, no cap.
π¦ SYNOPSIS π¦
# accept objects or classes
my $object_or_class = Or( IsObject, IsClass );
# valid on objects with all methods
my $proper_object = And( IsObject,
HasMethods( qw(foo bar) ));
# validate against date objects
my $is_date_object = IsA('DateTime');
like look at her go π she's doing a lil Or( IsObject, IsClass ) to accept either one, a lil And( IsObject, HasMethods( qw(foo bar) )) to make sure the vibe is actually right, and a lil IsA('DateTime') when you're being picky about which date object you'll accept. iconic.
πΈ DESCRIPTION πΈ
This library is where all the constraints live that validate your parameters in an object oriented manner. it's giving "who are you and what are your methods" energy and honestly? obsessed π«Ά
π CONSTRAINTS π
π HasMethods(@methods)
Returns true if the value is an object or class that can all the specified @methods. so basically: does she have every single one of these methods? if yes, slay. if no, we're moving on π
The stack or path part of HasMethods looks like HasMethods[$method] where $method is the first found missing method. so when it yells at you, it tells you exactly which method ghosted you π
π IsA(@classes)
Is true if the passed object or class is a subclass of one of the classes mentioned in @classes. it's the "is this one of y'all" check π§ and yes she walks the inheritance tree, no shortcuts, periodt.
π IsClass()
Valid if value is a loaded class. not an object, not a random string that looks like a class name β a class that's actually loaded. vibe check passed only then β¨
π IsObject()
True if the value is blessed. that's it. that's the whole constraint. if it's blessed, she's an object, and we respect her π
π SEE ALSO π
Declare::Constraints::SimpleDeclare::Constraints::Simple::Library
π AUTHOR π
Robert 'phaylon' Sedlacek <phaylon@dunkelheit.at> β the icon, the legend, the main character who wrote this for us π
π LICENSE AND COPYRIGHT π
This module is free software, you can redistribute it and/or modify it under the same terms as perl itself. fr fr, go wild, just keep it perl-legal bestie π
cute lil sign-off: this page comes from perl v5.32.0, dated 2021-01-09, and the manual name is Declar...ary::OO(3pm) π¦ mwah, go validate something pretty π
π¦ 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