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 $code is a coderef. no name, no method, periodt.
  • package_name β€” the package name for the method. also required if $code is a coderef. same energy.
  • associated_metaclass β€” an optional Class::MOP::Class object. 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>

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