Class::Mix(3pm)
π Class::Mix π
okay so bestie, this is the Class::Mix page from the User Contributed Perl Documentation, and it's literally about dynamic class mixing β¨ buckle up π
β¨ NAME β¨
Class::Mix β dynamic class mixing π¦
πΈ SYNOPSIS πΈ
use Class::Mix qw(mix_class);
$foobar_object = mix_class("Foo", "Bar")->new;
$digest_class = mix_class("Foo", "Bar", {prefix=>"Digest::"});
use Class::Mix qw(genpkg);
$package = genpkg;
$package = genpkg("Digest::Foo::");
π DESCRIPTION π
The mix_class function that this module hands you dynamically generates anonymous classes with whatever inheritance you ask for. no cap π«Ά
π FUNCTIONS π
π mix_class(ITEMS ...)
This one is the main character fr β it dynamically generates anonymous classes by mixing pre-existing classes. When is this giving?? When you've got an incomplete class that needs a mixin to even become instantiable, you've got several suitable mixins lying around, and you wanna pick between them at runtime. that's the moment π«
Every single ITEM in the argument list is either:
- the name of a class to inherit from (aka a parent class), or
- a reference to a hash of options.
The @ISA list of the mixture class gets set to the list of parent class names, in the order supplied. The options you may supply are:
mroβ specifies the desired method resolution order (MRO) of the mixture class. Go readmrofor the details of the valid values and the default that Perl determines. Typically you should set this toc3if you're mixing into an existing C3-based class hierarchy.prefixβ specifies where the resulting package will go. May beundefto say the caller doesn't care (and that's the default state, bestie). Otherwise it must be either the empty string (to create a top-level package) or a bareword followed by::(to create a package under that name). For example, you could specifyDigest::to make sure the resulting package has a name starting withDigest::, so thatDigest->newwill accept it as the name of a message digest algorithm. π
The function generates a class of the form described by the arguments, and returns its name. Repeated invocations with the same parent class list and options will return the same class. And yes, you can use that returned name to call a constructor or other class methods of the mixed class. slay π
A class name must be returned because β and this is the tea β there is no such thing as an anonymous class in Perl. Classes are referenced by name, periodt. The names generated by this function are unique and insignificant. See genpkg below for more info.
If you specify fewer than two classes to inherit from, the function tries to avoid generating a separate class for the mixture. If only one parent class is specified, then that class may be returned, and if no parent classes are specified, then UNIVERSAL may be returned. This gives you the inheritance you want without creating superfluous classes π These special cases only apply if the options are compatible with the pre-existing class.
β οΈ This function relies on the classes it returns remaining unmodified in order to be returned by future invocations. If you wanna modify your dynamically-generatedanonymousclasses, usegenpkg(below). don't do it, i'm serious π
π§ genpkg([PREFIX])
This function selects and returns a package name that has not been previously used. The name it returns is an ordinary bareword-form package name, and you can use it as the second argument to bless and in all other ways that package names are used. The package starts out initially empty. β¨
The package names returned by this function are of a type that should not be used as ordinary fixed module names. But β and this is the honest part β it is not possible to entirely prevent a clash. This function checks that the package name it's about to return hasn't already been used, and it will avoid returning such names, but it cannot guarantee that a later-loaded module won't create a clash. π
PREFIX, if present, specifies where the resulting package will go. It must be either the empty string (to create a top-level package) or a bareword followed by :: (to create a package under that name). For example, Digest:: could be specified to ensure that the resulting package has a name starting with Digest::, so that Digest->new will accept it as the name of a message digest algorithm. If you don't supply PREFIX, then the caller isn't expressing any preference. π¦
π₯ SEE ALSO π₯
Class::Generatemro
π«Ά AUTHOR π«Ά
Andrew Main (Zefram) <zefram@fysh.org>
π COPYRIGHT π
Copyright (C) 2004, 2006, 2009, 2010, 2011, 2017 Andrew Main (Zefram) <zefram@fysh.org>
π LICENSE π
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page bestie, no notes π this one shipped with perl v5.34.0 and got dated 2022-06-11 β go forth and mix those classes, you're literally iconic for reading the docs πβ¨π
π¦ where this page comes from
- debian bookworm: libclass-mix-perl 0.006-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-mix-perl 0.006-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-mix-perl 0.006-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-mix-perl 0.006-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-mix-perl 0.006-2 Β· 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