{
    "mode": "perldoc",
    "parameter": "Moose::Cookbook::Extending::Debugging_BaseClassRole",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3ACookbook%3A%3AExtending%3A%3ADebugging_BaseClassRole/json",
    "generated": "2026-11-21T22:18:35Z",
    "synopsis": "package MooseX::Debugging;\nuse Moose::Exporter;\nMoose::Exporter->setupimportmethods(\nbaseclassroles => ['MooseX::Debugging::Role::Object'],\n);\npackage MooseX::Debugging::Role::Object;\nuse Moose::Role;\nsub BUILD {}\nafter BUILD => sub {\nmy $self = shift;\nwarn \"Made a new \" . ( ref $self ) . \" object\\n\";\n};",
    "sections": {
        "NAME": {
            "content": "Moose::Cookbook::Extending::DebuggingBaseClassRole - Providing a role for the base object class\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 2.2207\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package MooseX::Debugging;\n\nuse Moose::Exporter;\n\nMoose::Exporter->setupimportmethods(\nbaseclassroles => ['MooseX::Debugging::Role::Object'],\n);\n\npackage MooseX::Debugging::Role::Object;\n\nuse Moose::Role;\n\nsub BUILD {}\nafter BUILD => sub {\nmy $self = shift;\n\nwarn \"Made a new \" . ( ref $self ) . \" object\\n\";\n};\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "In this example, we provide a role for the base object class that adds some simple debugging\noutput. Every time an object is created, it spits out a warning saying what type of object it\nwas.\n\nObviously, a real debugging role would do something more interesting, but this recipe is all\nabout how we apply that role.\n\nIn this case, with the combination of Moose::Exporter and Moose::Util::MetaRole, we ensure that\nwhen a module does \"use MooseX::Debugging\", it automatically gets the debugging role applied to\nits base object class.\n\nThere are a few pieces of code worth looking at more closely.\n\nMoose::Exporter->setupimportmethods(\nbaseclassroles => ['MooseX::Debugging::Role::Object'],\n);\n\nThis creates an \"import\" method in the \"MooseX::Debugging\" package. Since we are not actually\nexporting anything, we do not pass \"setupimportmethods\" any parameters related to exports, but\nwe need to have an \"import\" method to ensure that our \"initmeta\" method is called. The\n\"initmeta\" is created by \"setupimportmethods\" for us, since we passed the \"baseclassroles\"\nparameter. The generated \"initmeta\" will in turn call\nMoose::Util::MetaRole::applybaseclassroles.\n\nsub BUILD {}\nafter BUILD => sub {\n...\n};\n\nDue to the way role composition currently works, if the class that a role is composed into\ncontains a \"BUILD\" method, then that will override the \"BUILD\" method in any roles it composes,\nwhich is typically not what you want. Using a method modifier on \"BUILD\" avoids this issue,\nsince method modifiers compose together rather than being overridden. Method modifiers require\nthat a method exists in order to wrap, however, so we also provide a stub method to wrap if no\n\"BUILD\" method exists in the class.\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::Cookbook::Extending::DebuggingBaseClassRole - Providing a role for the base object class",
    "flags": [],
    "examples": [],
    "see_also": []
}