Class::MOP::Method(3)
π Class::MOP::Method π
okay so bestie, welcome to Class::MOP::Method β the Method Meta Object, straight out of the User Contributed Perl Documentation crew π«Ά
β¨ VERSION β¨
version 2.4000 β she's giving vintage but make it iconic π
πΈ DESCRIPTION πΈ
so like. the Method Protocol is tiny. itty bitty. because in Perl 5, methods are literally just subroutines living in a specific package π£ like that's the whole thing, that's the vibe.
what we give you here is a very basic introspection interface β just enough to peek at what's going on inside a method without being weird about it. lowkey minimal, highkey useful β¨
π METHODS π
Class::MOP::Method->wrap($code, %options)
this is the constructor, bestie, the main character of the whole page π
she accepts a method body β and that body can be either a code reference or a Class::MOP::Method instance β followed by a hash of options.
the options are, and I need you to read these carefully:
nameβ the method name (no package name attached, okay?). this one is required if$codeis a coderef. no name, no method, periodt.package_nameβ the package name for the method. also required if$codeis a coderef. same energy.associated_metaclassβ an optionalClass::MOP::Classobject. this is the metaclass for the method's class. cute little extra, take it or leave it π
$metamethod->clone(%params)
makes a shallow clone of the method object. and listen, the important bit: the subroutine reference itself is shared between all clones of a given method. so it's not a deep copy situation, it's a "we're all holding hands" situation π«Ά
when a method gets cloned, you can still reach the original method object by calling "original_method" on the clone. the family tree is preserved, slay.
$metamethod->body
returns a reference to the method's subroutine. just the body, the whole body, nothing but the body πͺ
$metamethod->name
returns the method's name. that's it. that's the whole function. iconic minimalism.
$metamethod->package_name
returns the method's package name π¦
$metamethod->fully_qualified_name
returns the method's fully qualified name β that's package name and method name, glued together like they were always meant to be β¨
$metamethod->associated_metaclass
returns the Class::MOP::Class object for the method β if one exists. if there isn't one, well. there isn't one. π
$metamethod->original_method
if this method object was created as a clone of some other method object, this returns the object that was cloned. your origin story, basically π±
$metamethod->original_name
returns the method's original name β wherever it was first defined. the birthplace name, the government name, if you will.
and here's the twist: if this method is a clone of a clone (of a clone, etc. β you get it, it goes deep), this returns the name from the first method in the chain of clones. so no matter how many generations deep you are, you always get the OG π
$metamethod->original_package_name
returns the method's original package name, wherever it was first defined.
same rule as above: if this method is a clone of a clone (of a clone, etc.), this returns the package name from the first method in the chain of clones. first one, always π
$metamethod->original_fully_qualified_name
returns the method's original fully qualified name, wherever it was first defined.
and yeah, you guessed it: if this method is a clone of a clone (of a clone, etc.), this returns the fully qualified name from the first method in the chain of clones. three for three, consistent queen π
$metamethod->is_stub
returns true if the method is just a stub. a lil placeholder. a "she's here but she's not here here". like this:
sub foo;
$metamethod->attach_to_class($metaclass)
given a Class::MOP::Class object, this sets the associated metaclass for the method.
β οΈ heads up bestie: this will overwrite any existing associated metaclass. no merge, no negotiation, just straight replacement. π
$metamethod->detach_from_class
removes any associated metaclass object for the method. she's free now π¦
$metamethod->execute(...)
this executes the method. any arguments you hand over get passed on to the method itself. so like, whatever you put in the ... goes straight through, no filter π
Class::MOP::Method->meta
returns a Class::MOP::Class instance for this class. meta on meta, we love to see it π₯
also worth noting (and this is a real thing, not me being dramatic): Class::MOP will actually bootstrap this module by installing a number of attribute meta-objects into its metaclass. so she's not just sitting there, she's built different β¨
π AUTHORS π
the legends themselves, in order:
- Stevan Little <stevan@cpan.org>
- Dave Rolsky <autarch@urth.org>
- Jesse Luehrs <doy@cpan.org>
- Shawn M Moore <sartak@cpan.org>
- ΧΧΧΧ Χ§ΧΧ'ΧΧ (Yuval Kogman) <nothingmuch@woobling.org>
- Karen Etheridge <ether@cpan.org>
- Florian Ragwitz <rafl@debian.org>
- Hans Dieter Pearcey <hdp@cpan.org>
- Chris Prather <chris@prather.org>
- Matt S Trout <mstrout@cpan.org>
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2006 by Infinity Interactive, Inc.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π
and that's the whole page bestie!! sign-off time: this was Class::MOP::Method(3) from the perl v5.42.0 manual, dated 2025-07-25 β go forth and introspect responsibly πΈπ
π¦
π¦ where this page comes from
- fedora 43: perl-Moose 2.4000-4.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms