Class::Gomor(3pm)

πŸ“¦
version 1.03 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Class::Gomor πŸ’–

okay bestie, gather round, because this is Class::Gomor β€” another class and object builder, from perl's User Contributed Perl Documentation, living in section 3pm like the icon it is. she's not like the other class builders, and you're gonna see why. πŸŽ€


✨ NAME ✨

Class::Gomor β€” another class and object builder. yes, that's literally it, she says what she is. πŸ’…


🌸 DESCRIPTION 🌸

so this module is yet another class builder, right, but here's the twist that makes her special: she adds parameter checking in the new constructor. like, she actually checks that your attributes exist, and that they're defined. she's looking out for you fr fr. 🫢

and the way she validates params? she needs to find the attributes first, which is the entire reason you declare them in global variables named @AS, @AA and @AO. they respectively stand for Attributes Scalar, Attributes Array, and Attributes Other. that last one (@AO) exists so you can avoid autocreation of accessors β€” basically it lets you declare your own ones, your own way, no notes. πŸ‘‘

the attribute validation happens by looking at the classes hierarchy, following the @ISA tree inheritance. it's giving detective energy honestly. πŸ”

now, the loss in speed from validating all attributes is quite negligeable on a decent machine (they say Pentium IV, 2.4 GHz, with Perl 5.8.x β€” vintage vibes, we love a throwback). but if you want to avoid checking entirely, you absolutely can, see below bestie. πŸ’œ

also important: this class is the base class for Class::Gomor::Array and Class::Gomor::Hash, so those two will inherite the following methods. slay. 🌈


πŸ’€ GLOBAL VARIABLES πŸ’€

  • $NoCheck β€” import it into your namespace like this:
use Class::Gomor qw($NoCheck);

if you want to disable cgCheckParams to improve speed once your program is frozen, this is your girl. set it to 1 to disable parameter checking. bye bye validation, hello speed. πŸ”₯

  • $Debug β€” import it into your namespace like this:
use Class::Gomor qw($Debug);

this variable is used by the cgDebugPrint method. that's the whole vibe. ✨


πŸ¦‹ METHODS πŸ¦‹

  • cgCheckParams (hash ref, array ref) β€” the attribute checking method, and she takes two arguments: the first is user passed attributes (as a hash reference), the second is the list of valid attributes, gathered via the cgGetAttributes method (as an array ref). if the passed parameters are not valid, a message gets displayed. she will literally tell you. 😭
  • cgGetIsaTree (array ref) β€” a recursive method. you pass a class in an array reference as an argument, and then the @ISA array gets browsed, recursively. the array reference you passed as an argument is increased with new classes, pushed into it. it returns nothing β€” the result is stored in the array ref. sneaky but effective. πŸ’…
  • cgGetAttributes β€” this method returns available attributes for the caller's object class. it uses cgGetIsaTree to search recursively in class hierarchy. then it returns an array reference with all possible attributes. the full roster. πŸ‘‘
  • cgBuildAccessorsScalar (array ref) β€” accessor creation method. takes an array reference containing all scalar attributes to create. scalar accessors are stored in a global variable names @AS. so you call this method at the beginning of your class like that:
__PACKAGE__->cgBuildAccessorsScalar(\@AS);
  • cgBuildAccessorsArray (array ref) β€” accessor creation method. takes an array reference containing all array attributes to create. array accessors are stored in a global variable names @AA. so you call this method at the beginning of your class like that:
__PACKAGE__->cgBuildAccessorsArray(\@AA);
  • cgClone [ (scalar) ] β€” you can clone one of your objects by calling this method. an optional parameter may be used to create multiple clones. but heads up: cloning will occure only on the first level attributes, that is, if you have attributes containing other objects, they will not be cloned. shallow queen behavior, know that going in. πŸ™ˆ
  • cgFullClone [ (scalar) ] β€” this method is the same as cgClone, but will clone all attributes recursively β€” but only if they are subclassed from Class::Gomor. so objects created with other modules than Class::Gomor::Array or Class::Gomor::Hash will not be cloned. ngl that's the boundary, respect it.

another thing to note: there is no catch for cycling references (when you link two objects with each others). you have been warned. πŸ’€πŸ’€πŸ’€

  • cgDebugPrint (scalar, scalar) β€” first argument is a debug level. it gets compared with global $Debug, and if it's less than it, the second argument (a message string) is displayed. this method exists because the author uses it β€” maybe you will not like it. honestly? fair. 😭

πŸ”₯ SEE ALSO πŸ”₯

Class::Gomor::Array, Class::Gomor::Hash

the whole family, go say hi. 🫢


πŸ‘‘ AUTHOR πŸ‘‘

Patrice <GomoR> Auffret β€” the legend herself. πŸ’œ


Copyright (c) 2004-2015, Patrice <GomoR> Auffret

You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.


and that's the whole page bestie, no cap, every last detail. this was perl v5.36.0, dated 2022-10-13 β€” mwah, iconic, periodt. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from