{
    "mode": "perldoc",
    "parameter": "Moose::Util",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3AUtil/json",
    "generated": "2026-06-10T15:04:57Z",
    "synopsis": "use Moose::Util qw/findmeta doesrole searchclassbyrole/;\nmy $meta = findmeta($object) || die \"No metaclass found\";\nif (doesrole($object, $role)) {\nprint \"The object can do $role!\\n\";\n}\nmy $class = searchclassbyrole($object, 'FooRole');\nprint \"Nearest class with 'FooRole' is $class\\n\";",
    "sections": {
        "NAME": {
            "content": "Moose::Util - Utilities for working with Moose classes\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 2.2200\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Moose::Util qw/findmeta doesrole searchclassbyrole/;\n\nmy $meta = findmeta($object) || die \"No metaclass found\";\n\nif (doesrole($object, $role)) {\nprint \"The object can do $role!\\n\";\n}\n\nmy $class = searchclassbyrole($object, 'FooRole');\nprint \"Nearest class with 'FooRole' is $class\\n\";\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides a set of utility functions. Many of these functions are intended for use in\nMoose itself or MooseX modules, but some of them may be useful for use in your own code.\n",
            "subsections": []
        },
        "EXPORTED FUNCTIONS": {
            "content": "findmeta($classorobj)\nThis method takes a class name or object and attempts to find a metaclass for the class, if one\nexists. It will not create one if it does not yet exist.\n\nisrole($packageorobj)\nReturns true if the provided package name or object is a Moose::Role.\n\ndoesrole($classorobj, $roleorobj)\nReturns true if $classorobj does the given $roleorobj. The role can be provided as a name or\na Moose::Meta::Role object.\n\nThe class must already have a metaclass for this to work. If it doesn't, this function simply\nreturns false.\n\nsearchclassbyrole($classorobj, $roleorobj)\nReturns the first class in the class's precedence list that does $roleorobj, if any. The role\ncan be either a name or a Moose::Meta::Role object.\n\nThe class must already have a metaclass for this to work.\n\napplyallroles($applicant, @roles)\nThis function applies one or more roles to the given $applicant. The applicant can be a role\nname, class name, or object.\n\nThe $applicant must already have a metaclass object.\n\nThe list of @roles should a list of names or Moose::Meta::Role objects, each of which can be\nfollowed by an optional hash reference of options (\"-excludes\" and \"-alias\").\n\nensureallroles($applicant, @roles)\nThis function is similar to \"applyallroles\", but only applies roles that $applicant does not\nalready consume.\n\nwithtraits($classname, @rolenames)\nThis function creates a new class from $classname with each of @rolenames applied. It returns\nthe name of the new class.\n\ngetallattributevalues($meta, $instance)\nReturns a hash reference containing all of the $instance's attributes. The keys are attribute\nnames.\n\ngetallinitargs($meta, $instance)\nReturns a hash reference containing all of the \"initarg\" values for the instance's attributes.\nThe values are the associated attribute values. If an attribute does not have a defined\n\"initarg\", it is skipped.\n\nThis could be useful in cloning an object.\n\nresolvemetaclassalias($category, $name, %options)\nresolvemetatraitalias($category, $name, %options)\nResolves a short name to a full class name. Short names are often used when specifying the\n\"metaclass\" or \"traits\" option for an attribute:\n\nhas foo => (\nmetaclass => \"Bar\",\n);\n\nThe name resolution mechanism is covered in \"Metaclass and Trait Name Resolution\" in Moose.\n\nmetaclassalias($to[, $from])\nmetaattributealias($to[, $from])\nCreate an alias from the class $from (or the current package, if $from is unspecified), so that\n\"Metaclass and Trait Name Resolution\" in Moose works properly.\n\nenglishlist(@items)\nGiven a list of scalars, turns them into a proper list in English (\"one and two\", \"one, two,\nthree, and four\"). This is used to help us make nicer error messages.\n\nthrowexception( $classname, %argumentstoexception)\nCalls die with an object of Moose::Exception::$classname, with %argumentstoexception passed\nas arguments.\n",
            "subsections": []
        },
        "TODO": {
            "content": "Here is a list of possible functions to write\n\ndiscovering original method from modified method\nsearch for origin class of a method or attribute\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 - Utilities for working with Moose classes",
    "flags": [],
    "examples": [],
    "see_also": []
}