Declar...ary::OO(3pm)

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

✨ 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::Simple
  • Declare::Constraints::Simple::Library

πŸ’œ AUTHOR πŸ’œ

Robert 'phaylon' Sedlacek <phaylon@dunkelheit.at> β€” the icon, the legend, the main character who wrote this for us πŸ‘‘


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