{
    "mode": "perldoc",
    "parameter": "Moose::Util::MetaRole",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3AUtil%3A%3AMetaRole/json",
    "generated": "2026-06-11T12:22:41Z",
    "synopsis": "package MyApp::Moose;\nuse Moose ();\nuse Moose::Exporter;\nuse Moose::Util::MetaRole;\nuse MyApp::Role::Meta::Class;\nuse MyApp::Role::Meta::Method::Constructor;\nuse MyApp::Role::Object;\nMoose::Exporter->setupimportmethods( also => 'Moose' );\nsub initmeta {\nshift;\nmy %args = @;\nMoose->initmeta(%args);\nMoose::Util::MetaRole::applymetaroles(\nfor             => $args{forclass},\nclassmetaroles => {\nclass       => ['MyApp::Role::Meta::Class'],\nconstructor => ['MyApp::Role::Meta::Method::Constructor'],\n},\n);\nMoose::Util::MetaRole::applybaseclassroles(\nfor   => $args{forclass},\nroles => ['MyApp::Role::Object'],\n);\nreturn $args{forclass}->meta();\n}",
    "sections": {
        "NAME": {
            "content": "Moose::Util::MetaRole - Apply roles to any metaclass, as well as the object base class\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 2.2200\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package MyApp::Moose;\n\nuse Moose ();\nuse Moose::Exporter;\nuse Moose::Util::MetaRole;\n\nuse MyApp::Role::Meta::Class;\nuse MyApp::Role::Meta::Method::Constructor;\nuse MyApp::Role::Object;\n\nMoose::Exporter->setupimportmethods( also => 'Moose' );\n\nsub initmeta {\nshift;\nmy %args = @;\n\nMoose->initmeta(%args);\n\nMoose::Util::MetaRole::applymetaroles(\nfor             => $args{forclass},\nclassmetaroles => {\nclass       => ['MyApp::Role::Meta::Class'],\nconstructor => ['MyApp::Role::Meta::Method::Constructor'],\n},\n);\n\nMoose::Util::MetaRole::applybaseclassroles(\nfor   => $args{forclass},\nroles => ['MyApp::Role::Object'],\n);\n\nreturn $args{forclass}->meta();\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This utility module is designed to help authors of Moose extensions write extensions that are\nable to cooperate with other Moose extensions. To do this, you must write your extensions as\nroles, which can then be dynamically applied to the caller's metaclasses.\n\nThis module makes sure to preserve any existing superclasses and roles already set for the meta\nobjects, which means that any number of extensions can apply roles in any order.\n",
            "subsections": []
        },
        "USAGE": {
            "content": "The easiest way to use this module is through Moose::Exporter, which can generate the\nappropriate \"initmeta\" method for you, and make sure it is called when imported.\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "This module provides two functions.\n\napplymetaroles( ... )\nThis function will apply roles to one or more metaclasses for the specified class. It will\nreturn a new metaclass object for the class or role passed in the \"for\" parameter.\n\nIt accepts the following parameters:\n\n*   for => $name\n\nThis specifies the class or for which to alter the meta classes. This can be a package name,\nor an appropriate meta-object (a Moose::Meta::Class or Moose::Meta::Role).\n\n*   classmetaroles => \\%roles\n\nThis is a hash reference specifying which metaroles will be applied to the class metaclass\nand its contained metaclasses and helper classes.\n\nEach key should in turn point to an array reference of role names.\n\nIt accepts the following keys:\n\nclass\nattribute\nmethod\nwrappedmethod\ninstance\nconstructor\ndestructor\nerror\n\n*   rolemetaroles => \\%roles\n\nThis is a hash reference specifying which metaroles will be applied to the role metaclass\nand its contained metaclasses and helper classes.\n\nIt accepts the following keys:\n\nrole\nattribute\nmethod\nrequiredmethod\nconflictingmethod\napplicationtoclass\napplicationtorole\napplicationtoinstance\napplicationrolesummation\nappliedattribute\n\napplybaseclassroles( for => $class, roles => \\@roles )\nThis function will apply the specified roles to the object's base class.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "See \"BUGS\" in Moose for details on reporting bugs.\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::Util::MetaRole - Apply roles to any metaclass, as well as the object base class",
    "flags": [],
    "examples": [],
    "see_also": []
}