MakeMe...itable(3pm)
hii bestie π welcome to the MakeMe...itable(3pm) page from User Contributed Perl Documentation β it's all about Class::MakeMethods::Emulator::Inheritable, and yes, it's giving βemulate Class::Inheritableβ energy. π
π NAME π
Class::MakeMethods::Emulator::Inheritable β Emulate Class::Inheritable
β¨ SYNOPSIS β¨
okay so here's the whole vibe:
package Stuff;
use base qw(Class::MakeMethods::Emulator::Inheritable);
# Set up DataFile as inheritable class data.
Stuff->mk_classdata('DataFile');
# Declare the location of the data file for this class.
Stuff->DataFile('/etc/stuff/data');
π¦ DESCRIPTION π¦
This module is an adaptor, and it provides emulation (the source spells it βemulatationβ π) of Class::Data::Inheritable by invoking similar functionality provided by Class::MakeMethods::ClassInherit.
The public interface provided by Class::MakeMethods::Emulator::Inheritable is identical to that of Class::Data::Inheritable. periodt π
Class::Data::Inheritable is for creating accessor/mutators to class data. That is, if you want to store something about your class as a whole (instead of about a single object). This data is then inherited by your subclasses and can be overridden. π
πΈ USAGE πΈ
As specified by Class::Data::Inheritable, clients should inherit from this module and then invoke the mk_classdata() method for each class method desired:
Class->mk_classdata($data_accessor_name);
This is a class method used to declare new class data accessors. A new accessor will be created in the Class using the name from $data_accessor_name.
Class->mk_classdata($data_accessor_name, $initial_value);
You may also pass a second argument to initialize the value. π
To facilitate overriding, mk_classdata creates an alias to the accessor, _field_accessor(). So Suitcase() would have an alias _Suitcase_accessor() that does the exact same thing as Suitcase(). This is useful if you want to alter the behavior of a single accessor yet still get the benefits of inheritable class data. For example:
sub Suitcase {
my($self) = shift;
warn "Fashion tragedy" if @_ and $_[0] eq 'Plaid';
$self->_Suitcase_accessor(@_);
}
π COMPATIBILITY π
Note that the internal implementation of Class::MakeMethods::ClassInherit does not match that of Class::Data::Inheritable. In particular, Class::Data::Inheritable installs new methods in subclasses when they first initialize their value, while
bestieβ¦ the source literally stops at while π no cap, that's where it cuts off. I'm not gonna invent the rest of the sentence. π
π§ EXAMPLE π§
The example provided by Class::Data::Inheritable is equally applicable to this emulator.
package Pere::Ubu;
use base qw(Class::MakeMethods::Emulator::Inheritable);
Pere::Ubu->mk_classdata('Suitcase');
will generate the method Suitcase() in the class Pere::Ubu.
This new method can be used to get and set a piece of class data.
Pere::Ubu->Suitcase('Red');
$suitcase = Pere::Ubu->Suitcase;
The interesting part happens when a class inherits from Pere::Ubu:
package Raygun;
use base qw(Pere::Ubu);
# Raygun's suitcase is Red.
$suitcase = Raygun->Suitcase;
Raygun inherits its Suitcase class data from Pere::Ubu.
Inheritance of class data works analgous to method inheritance (yes, that spelling is in the source, bestie π
). As long as Raygun does not "override" its inherited class data (by using Suitcase() to set a new value) it will continue to use whatever is set in Pere::Ubu and inherit further changes:
# Both Raygun's and Pere::Ubu's suitcases are now Blue
Pere::Ubu->Suitcase('Blue');
However, should Raygun decide to set its own Suitcase() it has now "overridden" Pere::Ubu and is on its own, just like if it had overridden a method:
# Raygun has an orange suitcase, Pere::Ubu's is still Blue.
Raygun->Suitcase('Orange');
Now that Raygun has overridden Pere::Ubu further changes by Pere::Ubu no longer effect Raygun.
# Raygun still has an orange suitcase, but Pere::Ubu is using Samsonite.
Pere::Ubu->Suitcase('Samsonite');
π SEE ALSO π
- See
Class::MakeMethodsfor general information about this distribution. - See
Class::MakeMethods::Emulatorfor more about this family of subclasses. - See
Class::Data::Inheritablefor documentation of the original module. - See
perltootcfor a discussion of class data in Perl. - See
Class::MakeMethods::Standard::InheritableandClass::MakeMethods::Template::ClassInheritfor inheritable data methods.
mwah π that's the whole page, bestie β it's from the User Contributed Perl Documentation source, perl v5.36.0, dated 2022-10-13, and the manual name is MakeMe...itable(3pm). periodt β¨
π¦ where this page comes from
- ubuntu noble: libclass-makemethods-perl 1.01-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-makemethods-perl 1.01-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-makemethods-perl 1.01-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms