Class:...ructor(3pm)

πŸ“¦
version 0.66 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble

πŸ’– 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 a Class::Meta::Constructor object. do not call this method directly; call the add_constructor() method on a Class::Meta object 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::PUBLIC
  • Class::Meta::PRIVATE
  • Class::Meta::TRUSTED
  • Class::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::Meta
  • Class::Meta::Class
  • Class::Meta::Method
  • Class::Meta::Attribute

the whole friend group, basically. πŸ‘―β€β™€οΈ


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