Class:...::Utils(3pm)
π NAME π
Class::Std::Utils β utility subroutines for building "inside-out" objects. Yes bestie, this is the Class:...::Utils(3pm) page, and we are going to understand it. π«Ά
β¨ VERSION β¨
This document describes Class::Std::Utils version 0.0.3. A tiny little vintage icon, but she does her job. π
π¦ SYNOPSIS π¦
use Class::Std::Utils;
# Constructor for anonymous scalars...
my $new_object = bless anon_scalar(), $class;
# Convert an object reference into a unique ID number...
my $ID_num = ident $new_object;
# Extract class-specific arguments from a hash reference...
my %args = extract_initializers_from($arg_ref);
πΈ DESCRIPTION πΈ
Okay so this module hands you three utility subroutines, and their whole vibe is making "inside-out" classes way easier to build. If you want the full lore, go read Chapters 15 and 16 of "Perl Best Practices" (O'Reilly, 2005). π
π INTERFACE π
π« anon_scalar()
She's always exported, no cap. Takes zero arguments, and gives you back a reference to an anonymous scalar β perfect for blessing as an object. Baby's first object ref. π
π« ident()
Also always exported. You give her exactly one argument β a reference β and she behaves exactly like Scalar::Util::refaddr(), handing you a unique integer value that's good for identifying the referent. It's giving ID card. πͺͺ
π« extract_initializers_from()
Also always exported, of course. One argument β a hash reference β and she returns a "flattened" set of key/value pairs pulled out of that hash.
The typical usage is:
my %class_specific_args = extract_initializers_from($args_ref);
The argument hash gets flattened as described in Chapter 16 of "Perl Best Practices":
The subroutine is always called with the original multi-level argument hash from the constructor. It then looks up the class's own name (i.e. its "caller" package) in the argument hash, to see if an initializer with that key has been defined. Finally, extract_initializers_for() returns the flattened set of key/value pairs for the class's initializer set, by appending the class-specific initializer subhash to the end of the original generic initializer hash. Appending the specific initializers after the generic ones means that any key in the class-specific set will override any key in the generic set, thereby ensuring that the most relevant initializers are always selected, but that generic initializers are still available where no class-specific value has been passed in.
In other words, given:
my $arg_ref = {
key_1 => 'generic value 1',
key_2 => 'generic value 2',
'Base::Class' => {
key_1 => 'base value 1'
},
'Der::Class' => {
key_1 => 'der value 1'
key_2 => 'der value 2'
},
};
package Base::Class;
use Class::Std::Utils;
my %base_args = extract_initializers_from($arg_ref);
package Der::Class;
use Class::Std::Utils;
my %der_args = extract_initializers_from($arg_ref);
then %base_args would be initialized to:
(
key_1 => 'base value 1',
key_2 => 'generic value 2',
'Base::Class' => {
key_1 => 'base value 1',
},
'Der::Class' => {
key_1 => 'der value 1',
key_2 => 'der value 2',
},
)
whilst %der_args would be initialized to:
(
key_1 => 'der value 1',
key_2 => 'der value 2',
'Base::Class' => {
key_1 => 'base value 1',
},
'Der::Class' => {
key_1 => 'der value 1',
key_2 => 'der value 2',
},
)
That is, the top-level entries would be replaced by any second-level entries with the same key that appear in a top-level entry of the same name as the calling package. π§ β¨
This means that each class can just refer to $args{key_1} and $args{key_2} and be confident that the resulting values will be the most specific available for that class. So clean, so demure. πΈ
π©Ί DIAGNOSTICS π©Ί
"%s initializer must be a nested hash"β thrown byextract_initializers_from(). You specified a top-level key that has the same name of the current class, but the value of that key wasn't a hash reference. Girl, that's not a nested hash. π
π§ CONFIGURATION AND ENVIRONMENT π§
Class::Std::Utils requires no configuration files or environment variables. Zero setup, just vibes. π
π¦ DEPENDENCIES π¦
This module requires both the Scalar::Util and List::Util modules, which are standard in Perl 5.8 and available from the CPAN for earlier versions of Perl. π«Ά
π« INCOMPATIBILITIES π«
None reported. Drama-free. π
π SEE ALSO π
- The
Class::Stdmodule - "Perl Best Practices", O'Reilly, 2005.
π BUGS AND LIMITATIONS π
No bugs have been reported. Iconic behaviour, honestly. β
Please report any bugs or feature requests to bug-class-std-utils@rt.cpan.org, or through the web interface at <http://rt.cpan.org>.
π AUTHOR π
Damian Conway <DCONWAY@cpan.org> β main character energy fr fr. π
βοΈ LICENCE AND COPYRIGHT βοΈ
Copyright (c) 2005, Damian Conway <DCONWAY@cpan.org>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
π‘οΈ DISCLAIMER OF WARRANTY π‘οΈ
Okay bestie, legal voice incoming, but it matters, so read it:
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
And that's the whole page, bestie!! π This one was baked with perl v5.34.0 and dated 2022-06-11, and it lives under the manual name Class:...::Utils(3pm). Go forth and build your inside-out classes, you absolute legend. πβ¨π¦
π¦ where this page comes from
- debian bookworm: libclass-std-utils-perl 0.0.3-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-std-utils-perl 0.0.3-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-std-utils-perl 0.0.3-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-std-utils-perl 0.0.3-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-std-utils-perl 0.0.3-3 Β· 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