{
    "mode": "perldoc",
    "parameter": "Moose::Cookbook::Legacy::Table_ClassMetaclass",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3ACookbook%3A%3ALegacy%3A%3ATable_ClassMetaclass/json",
    "generated": "2026-06-12T02:41:45Z",
    "synopsis": "package MyApp::Meta::Class;\nuse Moose;\nextends 'Moose::Meta::Class';\nhas table => (\nis  => 'rw',\nisa => 'Str',\n);",
    "sections": {
        "NAME": {
            "content": "Moose::Cookbook::Legacy::TableClassMetaclass - Adding a \"table\" attribute to the metaclass\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 2.2200\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package MyApp::Meta::Class;\nuse Moose;\nextends 'Moose::Meta::Class';\n\nhas table => (\nis  => 'rw',\nisa => 'Str',\n);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "WARNING: Subclassing metaclasses (as opposed to providing metaclass traits) is strongly\ndiscouraged. This recipe is provided solely for reference when encountering older code that does\nthis.\n\nIn this recipe, we'll create a new metaclass which has a \"table\" attribute. This metaclass is\nfor classes associated with a DBMS table, as one might do for an ORM.\n\nIn this example, the table name is just a string, but in a real ORM the table might be an object\ndescribing the table.\n",
            "subsections": []
        },
        "THE METACLASS": {
            "content": "This really is as simple as the recipe \"SYNOPSIS\" shows. The trick is getting your classes to\nuse this metaclass, and providing some sort of sugar for declaring the table. This is covered in\nMoose::Cookbook::Extending::Recipe2, which shows how to make a module like \"Moose.pm\" itself,\nwith sugar like \"hastable()\".\n",
            "subsections": [
                {
                    "name": "Using this Metaclass in Practice",
                    "content": "Accessing this new \"table\" attribute is quite simple. Given a class named \"MyApp::User\", we\ncould simply write the following:\n\nmy $table = MyApp::User->meta->table;\n\nAs long as \"MyApp::User\" has arranged to use \"MyApp::Meta::Class\" as its metaclass, this method\ncall just works. If we want to be more careful, we can check the metaclass's class:\n\n$table = MyApp::User->meta->table\nif MyApp::User->meta->isa('MyApp::Meta::Class');\n"
                }
            ]
        },
        "CONCLUSION": {
            "content": "Creating custom metaclass is trivial. Using it is a little harder, and is covered in other\nrecipes. We will also talk about applying traits to a class metaclass, which is a more flexible\nand cooperative implementation.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Moose::Cookbook::Meta::Recipe5 - The \"table\" attribute implemented as a metaclass trait\n\nMoose::Cookbook::Extending::Recipe2 - Acting like Moose.pm and providing sugar Moose-style\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::Legacy::TableClassMetaclass - Adding a \"table\" attribute to the metaclass",
    "flags": [],
    "examples": [],
    "see_also": []
}