{
    "mode": "perldoc",
    "parameter": "Moose::Manual::MOP",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3AManual%3A%3AMOP/json",
    "generated": "2026-06-11T04:11:09Z",
    "sections": {
        "NAME": {
            "content": "Moose::Manual::MOP - The Moose (and Class::MOP) meta API\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 2.2200\n",
            "subsections": []
        },
        "INTRODUCTION": {
            "content": "Moose provides a powerful introspection API built on top of \"Class::MOP\". \"MOP\" stands for\nMeta-Object Protocol. In plainer English, a MOP is an API for performing introspection on\nclasses, attributes, methods, and so on.\n\nIn fact, it is \"Class::MOP\" that provides many of Moose's core features, including attributes,\nbefore/after/around method modifiers, and immutability. In most cases, Moose takes an existing\n\"Class::MOP\" class and subclasses it to add additional features. Moose also adds some entirely\nnew features of its own, such as roles, the augment modifier, and types.\n\nIf you're interested in the MOP, it's important to know about \"Class::MOP\" so you know what docs\nto read. Often, the introspection method that you're looking for is defined in a \"Class::MOP\"\nclass, rather than Moose itself.\n\nThe MOP provides more than just *read-only* introspection. It also lets you add attributes and\nmethods, apply roles, and much more. In fact, all of the declarative Moose sugar is simply a\nthin layer on top of the MOP API.\n\nIf you want to write Moose extensions, you'll need to learn some of the MOP API. The\nintrospection methods are also handy if you want to generate docs or inheritance graphs, or do\nsome other runtime reflection.\n\nThis document is not a complete reference for the meta API. We're just going to cover some of\nthe highlights, and give you a sense of how it all works. To really understand it, you'll have\nto read a lot of other docs, and possibly even dig into the Moose guts a bit.\n",
            "subsections": []
        },
        "GETTING STARTED": {
            "content": "The usual entry point to the meta API is through a class's metaclass object, which is a\nMoose::Meta::Class. This is available by calling the \"meta\" method on a class or object:\n\npackage User;\n\nuse Moose;\n\nmy $meta = PACKAGE->meta;\n\nThe \"meta\" method is added to a class when it uses Moose.\n\nYou can also use \"Class::MOP::Class->initialize($name)\" to get a metaclass object for any class.\nThis is safer than calling \"$class->meta\" when you're not sure that the class has a meta method.\n\nThe \"Class::MOP::Class->initialize\" constructor will return an existing metaclass if one has\nalready been created (via Moose or some other means). If it hasn't, it will return a new\n\"Class::MOP::Class\" object. This will work for classes that use Moose, meta API classes, and\nclasses which don't use Moose at all.\n",
            "subsections": []
        },
        "USING THE METACLASS OBJECT": {
            "content": "The metaclass object can tell you about a class's attributes, methods, roles, parents, and more.\nFor example, to look at all of the class's attributes:\n\nfor my $attr ( $meta->getallattributes ) {\nprint $attr->name, \"\\n\";\n}\n\nThe \"getallattributes\" method is documented in \"Class::MOP::Class\". For Moose-using classes,\nit returns a list of Moose::Meta::Attribute objects for attributes defined in the class and its\nparents.\n\nYou can also get a list of methods:\n\nfor my $method ( $meta->getallmethods ) {\nprint $method->fullyqualifiedname, \"\\n\";\n}\n\nNow we're looping over a list of Moose::Meta::Method objects. Note that some of these objects\nmay actually be a subclass of Moose::Meta::Method, as Moose uses different classes to represent\nwrapped methods, delegation methods, constructors, etc.\n\nWe can look at a class's parent classes and subclasses:\n\nfor my $class ( $meta->linearizedisa ) {\nprint \"$class\\n\";\n}\n\nfor my $subclass ( $meta->subclasses ) {\nprint \"$subclass\\n\";\n}\n\nNote that both these methods return class *names*, not metaclass objects.\n",
            "subsections": []
        },
        "ALTERING CLASSES WITH THE MOP": {
            "content": "The metaclass object can change the class directly, by adding attributes, methods, etc.\n\nAs an example, we can add a method to a class:\n\n$meta->addmethod( 'say' => sub { print @, \"\\n\" } );\n\nOr an attribute:\n\n$meta->addattribute( 'size' => ( is => 'rw', isa  => 'Int' ) );\n\nObviously, this is much more cumbersome than using Perl syntax or Moose sugar for defining\nmethods and attributes, but this API allows for very powerful extensions.\n\nYou might remember that we've talked about making classes immutable elsewhere in the manual.\nThis is a good practice. However, once a class is immutable, calling any of these update methods\nwill throw an exception.\n\nYou can make a class mutable again simply by calling \"$meta->makemutable\". Once you're done\nchanging it, you can restore immutability by calling \"$meta->makeimmutable\".\n\nHowever, the most common use for this part of the meta API is as part of Moose extensions. These\nextensions should assume that they are being run before you make a class immutable.\n",
            "subsections": []
        },
        "GOING FURTHER": {
            "content": "If you're interested in extending Moose, we recommend reading all of the \"Meta\" and \"Extending\"\nrecipes in the Moose::Cookbook. Those recipes show various practical applications of the MOP.\n\nIf you'd like to write your own extensions, one of the best ways to learn more about this is to\nlook at other similar extensions to see how they work. You'll probably also need to read various\nAPI docs, including the docs for the various \"Moose::Meta::*\" and \"Class::MOP::*\" classes.\n\nFinally, we welcome questions on the Moose mailing list and IRC. Information on the mailing\nlist, IRC, and more references can be found in the Moose.pm docs.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "*   Stevan Little <stevan@cpan.org>\n\n*   Dave Rolsky <autarch@urth.org>\n\n*   Jesse Luehrs <doy@cpan.org>\n\n*   Shawn M Moore <sartak@cpan.org>\n\n*   יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>\n\n*   Karen Etheridge <ether@cpan.org>\n\n*   Florian Ragwitz <rafl@debian.org>\n\n*   Hans Dieter Pearcey <hdp@cpan.org>\n\n*   Chris Prather <chris@prather.org>\n\n*   Matt S Trout <mstrout@cpan.org>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is copyright (c) 2006 by Infinity Interactive, Inc.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        }
    },
    "summary": "Moose::Manual::MOP - The Moose (and Class::MOP) meta API",
    "flags": [],
    "examples": [],
    "see_also": []
}