Class:...:Method(3pm)

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

πŸ’– Class::Meta::Method β€” the introspective method baddie πŸ’–

okay bestie, welcome to the Class::Meta::Method page, part of the User Contributed Perl Documentation for Class:...:Method(3pm). she's a perl module and she's here to spill the tea on class method introspection. pull up a chair 🫢


✨ NAME ✨

Class::Meta::Method β€” Class::Meta class method introspection. literally her whole job. πŸ’…


🌸 SYNOPSIS 🌸

# Assuming MyApp::Thingy was generated by Class::Meta.
my $class = MyApp::Thingy->my_class;
my $thingy = MyApp::Thingy->new;

print "\nMethods:\n";
for my $meth ($class->methods) {
    print "  o ", $meth->name, $/;
    $meth->call($thingy);
}

like. look at her go. she's printing every method name and then calling it. main character energy fr. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so this class hands you an interface to the Class::Meta objects that describe methods. she supports a simple description of the method, a label, and its visibility β€” and the visibility options are private, protected, trusted, or public. yes bestie, four whole vibes. 🌈

now important: Class::Meta::Method objects are created by Class::Meta. they are never instantiated directly in client code. do not try it. i'm serious. 😭

so how do you get to them?? you call the my_class() method on a Class::Meta-generated class to retrieve its Class::Meta::Class object, and then you call the methods() method on that Class::Meta::Class object. that's the whole pipeline, no cap. ✨


πŸ’… INTERFACE πŸ’…

πŸŽ€ Constructors πŸŽ€

  • new β€” a protected method for constructing a Class::Meta::Method object. do NOT call this method directly!! instead, call the add_method() method on a Class::Meta object. that's the move. πŸ™ˆ

πŸ‘‘ Instance Methods πŸ‘‘

  • name
my $name = $meth->name;

returns the method name. simple. iconic. πŸ“

  • package
my $package = $meth->package;

returns the method package.

  • desc
my $desc = $meth->desc;

returns the description of the method.

  • label
my $desc = $meth->label;

returns label for the method.

  • view
my $view = $meth->view;

returns the view of the method, reflecting its visibility. the possible values are defined by the following constants:

  • Class::Meta::PUBLIC
  • Class::Meta::PRIVATE
  • Class::Meta::TRUSTED
  • Class::Meta::PROTECTED
  • context
my $context = $meth->context;

returns the context of the method β€” essentially whether it is a class or object method. the possible values are defined by the following constants:

  • Class::Meta::CLASS
  • Class::Meta::OBJECT
  • args β€” a description of the arguments to the method. this can be anything you like, but the recommendation is something like a string for a single argument, an array reference for a list of arguments, or a hash reference for parameter arguments. you do you bestie, but that's the suggested layout. 🌸
  • returns β€” a description of the return value or values of the method.
  • class
my $class = $meth->class;

returns the Class::Meta::Class object that this method is associated with. note that this object will always represent the class in which the method is defined, and not any of its subclasses. periodt. ⭐

  • call
my $ret = $meth->call($obj, @args);

calls the method on the $obj object, passing in any arguments. heads up though: it uses a goto to execute the method, so the call to call() itself will not appear in a call stack trace. sneaky little thing. πŸ’€

  • build
$meth->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 method was defined. once it checks to make sure that it is only called by Class::Meta or a subclass of Class::Meta or of Class::Meta::Method, build() installs the method if it was specified via the code parameter to new().

and even though you should never call this method directly, subclasses of Class::Meta::Method may need to override it in order to add behavior. iykyk. 🧚


🫢 SUPPORT 🫢

this module is stored in an open GitHub repository at <http://github.com/theory/class-meta/>. feel free to fork and contribute! bestie behavior honestly. πŸŽ€

please file bug reports via GitHub Issues at <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::Constructor
  • Class::Meta::Attribute

go read those next, they're the whole squad. πŸ”₯


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 a wrap on Class:...:Method(3pm) bestie!! this page was served up by perl v5.34.0 on 2022-06-11 β€” she's a lil vintage but she still slays πŸ’–βœ¨πŸŽ€
πŸ“¦ where this page comes from