info > Class::MOP::Class

Not found locally for Class::MOP::Class. Try Google search

📛 NAME

Class::MOP::Class - Class Meta Object

🔖 VERSION

version 2.2200

🚀 Quick Reference

Use CaseCommandDescription
Create a new classClass::MOP::Class->create('Foo', ...)Create a new class with superclasses, methods, attributes
Add a method to a class$metaclass->add_method('bar', sub { ... })Add a method to the class
Get class precedence list$metaclass->class_precedence_list()Return ancestor classes in method dispatch order
Make class immutable$metaclass->make_immutable()Freeze class definition and optimize

📖 SYNOPSIS

# assuming that class Foo
# has been defined, you can

# use this for introspection ...

# add a method to Foo ...
Foo->meta->add_method( 'bar' => sub {...} )

# get a list of all the classes searched
# the method dispatcher in the correct order
Foo->meta->class_precedence_list()

# remove a method from Foo
Foo->meta->remove_method('bar');

# or use this to actually create classes ...

Class::MOP::Class->create(
    'Bar' => (
        version      => '0.01',
        superclasses => ['Foo'],
        attributes   => [
            Class::MOP::Attribute->new('$bar'),
            Class::MOP::Attribute->new('$baz'),
        ],
        methods => {
            calculate_bar => sub {...},
            construct_baz => sub {...}
        }
    )
);

📚 DESCRIPTION

The Class Protocol is the largest and most complex part of the Class::MOP meta-object protocol. It controls the introspection and manipulation of Perl 5 classes, and it can create them as well. The best way to understand what this module can do is to read the documentation for each of its methods.

đŸ§Ŧ INHERITANCE

Class::MOP::Class is a subclass of Class::MOP::Module.

🔧 METHODS

đŸ—ī¸ Class construction

These methods all create new Class::MOP::Class objects. These objects can represent existing classes or they can be used to create new classes from scratch.

The metaclass object for a given class is a singleton. If you attempt to create a metaclass for the same class twice, you will just get the existing object.

đŸ§Ŧ Object instance construction and cloning

These methods are all related to creating and/or cloning object instances.

â„šī¸ Informational predicates

These are a few predicate methods for asking information about the class itself.

🔗 Inheritance Relationships

🔍 Method introspection and creation

Because Perl 5 does not have a core concept of attributes in classes, we can only return information about attributes which have been added via this class's methods. We cannot discover information about attributes which are defined in terms of "regular" Perl 5 methods.

📋 Attribute introspection and creation

Because Perl 5 does not have a core concept of attributes in classes, we can only return information about attributes which have been added via this class's methods. We cannot discover information about attributes which are defined in terms of "regular" Perl 5 methods.

âš™ī¸ Overload introspection and creation

These methods provide an API to the core overload functionality.

â„ī¸ Class Immutability

Making a class immutable "freezes" the class definition. You can no longer call methods which alter the class, such as adding or removing methods or attributes. Making a class immutable lets us optimize the class by inlining some methods, and also allows us to optimize some methods on the metaclass object itself. After immutabilization, the metaclass object will cache most informational methods that returns information about methods or attributes. Methods which would alter the class, such as add_attribute and add_method, will throw an error on an immutable metaclass object. The immutabilization system in Moose takes much greater advantage of the inlining features than Class::MOP itself does.

🔧 Method Modifiers

Method modifiers are hooks which allow a method to be wrapped with before, after and around method modifiers. Every time a method is called, its modifiers are also called. A class can modify its own methods, as well as methods defined in parent classes.

How method modifiers work? Method modifiers work by wrapping the original method and then replacing it in the class's symbol table. The wrappers will handle calling all the modifiers in the appropriate order and preserving the calling context for the original method. The return values of before and after modifiers are ignored. This is because their purpose is not to filter the input and output of the primary method (this is done with an around modifier). This may seem like an odd restriction to some, but doing this allows for simple code to be added at the beginning or end of a method call without altering the function of the wrapped method or placing any extra responsibility on the code of the modifier. Of course if you have more complex needs, you can use the around modifier which allows you to change both the parameters passed to the wrapped method, as well as its return value. Before and around modifiers are called in last-defined-first-called order, while after modifiers are called in first-defined-first-called order. So the call tree might looks something like this:

 before 2
  before 1
   around 2
    around 1
     primary
    around 1
   around 2
  after 1
 after 2

What is the performance impact? Of course there is a performance cost associated with method modifiers, but we have made every effort to make that cost directly proportional to the number of modifier features you use. The wrapping method does its best to only do as much work as it absolutely needs to. In order to do this we have moved some of the performance costs to set-up time, where they are easier to amortize. All this said, our benchmarks have indicated the following:

These numbers may seem daunting, but you must remember, every feature comes with some cost. To put things in perspective, just doing a simple AUTOLOAD which does nothing but extract the name of the method called and return it costs about 400% over a normal method call.

🔎 Introspection

đŸ‘Ĩ AUTHORS

📜 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.

perl v5.34.0 2022-02-06 Class::MOP::Class(3pm)

Class::MOP::Class
📛 NAME 🔖 VERSION 🚀 Quick Reference 📖 SYNOPSIS 📚 DESCRIPTION đŸ§Ŧ INHERITANCE 🔧 METHODS
đŸ—ī¸ Class construction đŸ§Ŧ Object instance construction and cloning â„šī¸ Informational predicates 🔗 Inheritance Relationships 🔍 Method introspection and creation 📋 Attribute introspection and creation âš™ī¸ Overload introspection and creation â„ī¸ Class Immutability 🔧 Method Modifiers 🔎 Introspection
đŸ‘Ĩ AUTHORS 📜 COPYRIGHT AND LICENSE

Generated by phpman v4.10.0-7-g98e9fd5 Author: Che Dong Under GNU General Public License
2026-09-09 00:31 @2600:1f28:365:80b0:8430:39a8:2b19:a7ca
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!