{
    "mode": "perldoc",
    "parameter": "Moose::Cookbook::Extending::Mooseish_MooseSugar",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3ACookbook%3A%3AExtending%3A%3AMooseish_MooseSugar/json",
    "generated": "2026-06-11T07:35:13Z",
    "synopsis": "package MyApp::Mooseish;\nuse Moose::Exporter;\nMoose::Exporter->setupimportmethods(\nwithmeta       => ['hastable'],\nclassmetaroles => {\nclass => ['MyApp::Meta::Class::Trait::HasTable'],\n},\n);\nsub hastable {\nmy $meta = shift;\n$meta->table(shift);\n}\npackage MyApp::Meta::Class::Trait::HasTable;\nuse Moose::Role;\nhas table => (\nis  => 'rw',\nisa => 'Str',\n);",
    "sections": {
        "NAME": {
            "content": "Moose::Cookbook::Extending::MooseishMooseSugar - Acting like Moose.pm and providing sugar\nMoose-style\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 2.2200\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package MyApp::Mooseish;\n\nuse Moose::Exporter;\n\nMoose::Exporter->setupimportmethods(\nwithmeta       => ['hastable'],\nclassmetaroles => {\nclass => ['MyApp::Meta::Class::Trait::HasTable'],\n},\n);\n\nsub hastable {\nmy $meta = shift;\n$meta->table(shift);\n}\n\npackage MyApp::Meta::Class::Trait::HasTable;\nuse Moose::Role;\n\nhas table => (\nis  => 'rw',\nisa => 'Str',\n);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This recipe expands on the use of Moose::Exporter we saw in\nMoose::Cookbook::Extending::ExtensionOverview and the class metaclass trait we saw in\nMoose::Cookbook::Meta::TableMetaclassTrait. In this example we provide our own metaclass trait,\nand we also export a \"hastable\" sugar function.\n\nThe \"withmeta\" parameter specifies a list of functions that should be wrapped before exporting.\nThe wrapper simply ensures that the importing package's appropriate metaclass object is the\nfirst argument to the function, so we can do \"my $meta = shift;\".\n\nSee the Moose::Exporter docs for more details on its API.\n\nUSING MyApp::Mooseish\nThe purpose of all this code is to provide a Moose-like interface. Here's what it would look\nlike in actual use:\n\npackage MyApp::User;\n\nuse namespace::autoclean;\n\nuse Moose;\nuse MyApp::Mooseish;\n\nhastable 'User';\n\nhas 'username' => ( is => 'ro' );\nhas 'password' => ( is => 'ro' );\n\nsub login { ... }\n",
            "subsections": []
        },
        "CONCLUSION": {
            "content": "Providing sugar functions can make your extension look much more Moose-ish. See Fey::ORM for a\nmore extensive example.\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::MooseishMooseSugar - Acting like Moose.pm and providing sugar Moose-style",
    "flags": [],
    "examples": [],
    "see_also": []
}