Class:...ructor(3pm)
π Class::Meta::Constructor β the 3pm page, bestie edition β¨
okay so real quick: this is the Class:...ructor(3pm) page from the User Contributed Perl Documentation crew, and it's all about peeking inside your class constructors. no cap, it's lowkey iconic. π
πΈ NAME πΈ
Class::Meta::Constructor β the whole vibe of Class::Meta class constructor introspection. it's giving "look inside your constructor and see what's up." π
β¨ SYNOPSIS β¨
here's the tea, fr fr β assuming MyApp::Thingy was generated by Class::Meta:
# Assuming MyApp::Thingy was generated by Class::Meta.
my $class = MyApp::Thingy->my_class;
print "\nConstructors:\n";
for my $ctor ($class->constructors) {
print " o ", $ctor->name, $/;
my $thingy = $ctor->call($class->package);
}
like, you grab the class object, loop through its constructors, print their names, and actually call them. slay. π₯
π¦ DESCRIPTION π¦
so this class is the little interface to the Class::Meta objects that describe class constructors. it supports a simple description of the constructor, a label, and the constructor visibility (private, protected, trusted, or public). cute, right? π
and here's the important bit β Class::Meta::Constructor objects are created by Class::Meta; they are never instantiated directly in client code. not me trying to new one up. π
to access the constructor objects for a Class::Meta-generated class, just call its my_class() method to retrieve its Class::Meta::Class object, and then call the constructors() method on the Class::Meta::Class object. that's the whole ritual. β¨
π INTERFACE π
π§ Constructors
newβ a protected method for constructing aClass::Meta::Constructorobject. do not call this method directly; call theadd_constructor()method on aClass::Metaobject instead. periodt. π
π Instance Methods
name
my $name = $ctor->name;
Returns the constructor name. π·οΈ
package
my $package = $ctor->package;
Returns the package name of the class that constructor is associated with. π¦
desc
my $desc = $ctor->desc;
Returns the description of the constructor. π
label
my $desc = $ctor->label;
Returns label for the constructor. (yes, the example variable in the original is $desc β we don't question it, we respect it. π)
view
my $view = $ctor->view;
Returns the view of the constructor, reflecting its visibility. the possible values are defined by these constants, and they are:
Class::Meta::PUBLICClass::Meta::PRIVATEClass::Meta::TRUSTEDClass::Meta::PROTECTED
class
my $class = $ctor->class;
Returns the Class::Meta::Class object that this constructor is associated with. β οΈ heads up bestie: this object will always represent the class in which the constructor is defined, and not any of its subclasses.
call
my $obj = $ctor->call($package, @params);
Executes the constructor. pass in the name of the class for which it is being executed (since, thanks to subclassing, it may be different than the class with which the constructor is associated). all other parameters will be passed to the constructor. π and note that it uses a goto to execute the constructor, so the call to call() itself will not appear in a call stack trace. sneaky. stealth mode. π₯·
build
$ctor->build($class);
This is a protected method, designed to be called only by the Class::Meta class or a subclass of Class::Meta. it takes a single argument β the Class::Meta::Class object for the class in which the constructor was defined β and generates constructor method for the Class::Meta::Constructor, either by installing the code reference passed in the code parameter or by creating the constructor from scratch. π οΈ
Although you should never call this method directly, subclasses of Class::Meta::Constructor may need to override its behavior. iykyk. π«
π BUGS π
Please send bug reports to <bug-class-meta@rt.cpan.org> or report them via the CPAN Request Tracker at <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Meta>.
(not me asking you to actually file them instead of just complaining in the group chat π)
π«Ά SUPPORT π«Ά
This module is stored in an open GitHub repository <http://github.com/theory/class-meta/>. Feel free to fork and contribute! π±
Please file bug reports via GitHub Issues <http://github.com/theory/class-meta/issues/> or by sending mail to bug-Class-Meta@rt.cpan.org <mailto:bug-Class-Meta@rt.cpan.org>.
π AUTHOR π
David E. Wheeler <david@justatheory.com>
π SEE ALSO π
Other classes of interest within the Class::Meta distribution include:
Class::MetaClass::Meta::ClassClass::Meta::MethodClass::Meta::Attribute
the whole friend group, basically. π―ββοΈ
π COPYRIGHT AND LICENSE π
Copyright (c) 2002-2011, David E. Wheeler. Some Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the page, bestie! π
this lil tour was brought to you by perl v5.34.0, dated 2022-06-11, and the Class:...ructor(3pm) page. go forth and introspect your constructors, queen. πβ¨
π¦ where this page comes from
- debian bookworm: libclass-meta-perl 0.66-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-meta-perl 0.66-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-meta-perl 0.66-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