{
    "mode": "perldoc",
    "parameter": "Role::Tiny",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Role%3A%3ATiny/json",
    "generated": "2026-06-10T16:57:52Z",
    "synopsis": "package Some::Role;\nuse Role::Tiny;\nsub foo { ... }\nsub bar { ... }\naround baz => sub { ... };\n1;\nelsewhere\npackage Some::Class;\nuse Role::Tiny::With;\n# bar gets imported, but not foo\nwith 'Some::Role';\nsub foo { ... }\n# baz is wrapped in the around modifier by Class::Method::Modifiers\nsub baz { ... }\n1;\nIf you wanted attributes as well, look at Moo::Role.",
    "sections": {
        "NAME": {
            "content": "Role::Tiny - Roles: a nouvelle cuisine portion size slice of Moose\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package Some::Role;\n\nuse Role::Tiny;\n\nsub foo { ... }\n\nsub bar { ... }\n\naround baz => sub { ... };\n\n1;\n\nelsewhere\n\npackage Some::Class;\n\nuse Role::Tiny::With;\n\n# bar gets imported, but not foo\nwith 'Some::Role';\n\nsub foo { ... }\n\n# baz is wrapped in the around modifier by Class::Method::Modifiers\nsub baz { ... }\n\n1;\n\nIf you wanted attributes as well, look at Moo::Role.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"Role::Tiny\" is a minimalist role composition tool.\n",
            "subsections": []
        },
        "ROLE COMPOSITION": {
            "content": "Role composition can be thought of as much more clever and meaningful multiple inheritance. The\nbasics of this implementation of roles is:\n\n* If a method is already defined on a class, that method will not be composed in from the role.\nA method inherited by a class gets overridden by the role's method of the same name, though.\n\n* If a method that the role \"requires\" to be implemented is not implemented, role application\nwill fail loudly.\n\nUnlike Class::C3, where the last class inherited from \"wins,\" role composition is the other way\naround, where the class wins. If multiple roles are applied in a single call (single with\nstatement), then if any of their provided methods clash, an exception is raised unless the class\nprovides a method since this conflict indicates a potential problem.\n\nROLE METHODS\nAll subs created after importing Role::Tiny will be considered methods to be composed. For\nexample:\n\npackage MyRole;\nuse List::Util qw(min);\nsub mysub { }\nuse Role::Tiny;\nuse List::Util qw(max);\nsub mymethod { }\n\nIn this role, \"max\" and \"mymethod\" will be included when composing MyRole, and \"min\" and \"mysub\"\nwill not. For additional control, namespace::clean can be used to exclude undesired subs from\nroles.\n",
            "subsections": []
        },
        "IMPORTED SUBROUTINES": {
            "content": "requires\nrequires qw(foo bar);\n\nDeclares a list of methods that must be defined to compose role.\n\nwith\nwith 'Some::Role1';\n\nwith 'Some::Role1', 'Some::Role2';\n\nComposes another role into the current role (or class via Role::Tiny::With).\n\nIf you have conflicts and want to resolve them in favour of Some::Role1 you can instead write:\n\nwith 'Some::Role1';\nwith 'Some::Role2';\n\nIf you have conflicts and want to resolve different conflicts in favour of different roles,\nplease refactor your codebase.\n\nbefore\nbefore foo => sub { ... };\n\nSee \"before method(s) => sub { ... };\" in Class::Method::Modifiers for full documentation.\n\nNote that since you are not required to use method modifiers, Class::Method::Modifiers is lazily\nloaded and we do not declare it as a dependency. If your Role::Tiny role uses modifiers you must\ndepend on both Class::Method::Modifiers and Role::Tiny.\n\naround\naround foo => sub { ... };\n\nSee \"around method(s) => sub { ... };\" in Class::Method::Modifiers for full documentation.\n\nNote that since you are not required to use method modifiers, Class::Method::Modifiers is lazily\nloaded and we do not declare it as a dependency. If your Role::Tiny role uses modifiers you must\ndepend on both Class::Method::Modifiers and Role::Tiny.\n\nafter\nafter foo => sub { ... };\n\nSee \"after method(s) => sub { ... };\" in Class::Method::Modifiers for full documentation.\n\nNote that since you are not required to use method modifiers, Class::Method::Modifiers is lazily\nloaded and we do not declare it as a dependency. If your Role::Tiny role uses modifiers you must\ndepend on both Class::Method::Modifiers and Role::Tiny.\n",
            "subsections": [
                {
                    "name": "Strict and Warnings",
                    "content": "In addition to importing subroutines, using \"Role::Tiny\" applies strict and warnings to the\ncaller.\n"
                }
            ]
        },
        "SUBROUTINES": {
            "content": "doesrole\nif (Role::Tiny::doesrole($foo, 'Some::Role')) {\n...\n}\n\nReturns true if class has been composed with role.\n\nThis subroutine is also installed as ->does on any class a Role::Tiny is composed into unless\nthat class already has an ->does method, so\n\nif ($foo->does('Some::Role')) {\n...\n}\n\nwill work for classes but to test a role, one must use ::doesrole directly.\n\nAdditionally, Role::Tiny will override the standard Perl \"DOES\" method for your class. However,\nif \"any\" class in your class' inheritance hierarchy provides \"DOES\", then Role::Tiny will not\noverride it.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "makerole\nRole::Tiny->makerole('Some::Role');\n\nMakes a package into a role, but does not export any subs into it.\n\napplyrolestopackage\nRole::Tiny->applyrolestopackage(\n'Some::Package', 'Some::Role', 'Some::Other::Role'\n);\n\nComposes role with package. See also Role::Tiny::With.\n\napplyrolestoobject\nRole::Tiny->applyrolestoobject($foo, qw(Some::Role1 Some::Role2));\n\nComposes roles in order into object directly. Object is reblessed into the resulting class. Note\nthat the object's methods get overridden by the role's ones with the same names.\n\ncreateclasswithroles\nRole::Tiny->createclasswithroles('Some::Base', qw(Some::Role1 Some::Role2));\n\nCreates a new class based on base, with the roles composed into it in order. New class is\nreturned.\n\nisrole\nRole::Tiny->isrole('Some::Role1')\n\nReturns true if the given package is a role.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "*   On perl 5.8.8 and earlier, applying a role to an object won't apply any overloads from the\nrole to other copies of the object.\n\n*   On perl 5.16 and earlier, applying a role to a class won't apply any overloads from the role\nto any existing instances of the class.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Role::Tiny is the attribute-less subset of Moo::Role; Moo::Role is a meta-protocol-less subset\nof the king of role systems, Moose::Role.\n\nOvid's Role::Basic provides roles with a similar scope, but without method modifiers, and having\nsome extra usage restrictions.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "dg - David Leadbeater (cpan:DGL) <dgl@dgl.cx>\n\nfrew - Arthur Axel \"fREW\" Schmidt (cpan:FREW) <frioux@gmail.com>\n\nhobbs - Andrew Rodland (cpan:ARODLAND) <arodland@cpan.org>\n\njnap - John Napiorkowski (cpan:JJNAPIORK) <jjn1056@yahoo.com>\n\nribasushi - Peter Rabbitson (cpan:RIBASUSHI) <ribasushi@cpan.org>\n\nchip - Chip Salzenberg (cpan:CHIPS) <chip@pobox.com>\n\najgb - Alex J. G. Burzyński (cpan:AJGB) <ajgb@cpan.org>\n\ndoy - Jesse Luehrs (cpan:DOY) <doy at tozt dot net>\n\nperigrin - Chris Prather (cpan:PERIGRIN) <chris@prather.org>\n\nMithaldu - Christian Walde (cpan:MITHALDU) <walde.christian@googlemail.com>\n\nilmari - Dagfinn Ilmari Mannsåker (cpan:ILMARI) <ilmari@ilmari.org>\n\ntobyink - Toby Inkster (cpan:TOBYINK) <tobyink@cpan.org>\n\nhaarg - Graham Knop (cpan:HAARG) <haarg@haarg.org>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (c) 2010-2012 the Role::Tiny \"AUTHOR\" and \"CONTRIBUTORS\" as listed above.\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This library is free software and may be distributed under the same terms as perl itself.\n",
            "subsections": []
        }
    },
    "summary": "Role::Tiny - Roles: a nouvelle cuisine portion size slice of Moose",
    "flags": [],
    "examples": [],
    "see_also": []
}