{
    "mode": "info",
    "parameter": "Moose::Cookbook::Basics::Document_AugmentAndInner",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/Moose%3A%3ACookbook%3A%3ABasics%3A%3ADocument_AugmentAndInner/json",
    "generated": "2026-07-05T13:18:22Z",
    "synopsis": "package Document::Page;\nuse Moose;\nhas 'body' => ( is => 'rw', isa => 'Str', default => sub {''} );\nsub create {\nmy $self = shift;\n$self->openpage;\ninner();\n$self->closepage;\n}\nsub appendbody {\nmy ( $self, $appendage ) = @;\n$self->body( $self->body . $appendage );\n}\nsub openpage  { (shift)->appendbody('<page>') }\nsub closepage { (shift)->appendbody('</page>') }\npackage Document::PageWithHeadersAndFooters;\nuse Moose;\nextends 'Document::Page';\naugment 'create' => sub {\nmy $self = shift;\n$self->createheader;\ninner();\n$self->createfooter;\n};\nsub createheader { (shift)->appendbody('<header/>') }\nsub createfooter { (shift)->appendbody('<footer/>') }\npackage TPSReport;\nuse Moose;\nextends 'Document::PageWithHeadersAndFooters';\naugment 'create' => sub {\nmy $self = shift;\n$self->createtpsreport;\ninner();\n};\nsub createtpsreport {\n(shift)->appendbody('<report type=\"tps\"/>');\n}\n# <page><header/><report type=\"tps\"/><footer/></page>\nmy $reportxml = TPSReport->new->create;",
    "sections": {
        "Moose::Cookbook::BasicUsMoose::Cookbook::Basics::DocumentAugmentAndInner(3pm)": {
            "content": "",
            "subsections": []
        },
        "NAME": {
            "content": "Moose::Cookbook::Basics::DocumentAugmentAndInner - The augment\nmodifier, which turns normal method overriding \"inside-out\"\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 2.2200\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package Document::Page;\nuse Moose;\n\nhas 'body' => ( is => 'rw', isa => 'Str', default => sub {''} );\n\nsub create {\nmy $self = shift;\n$self->openpage;\ninner();\n$self->closepage;\n}\n\nsub appendbody {\nmy ( $self, $appendage ) = @;\n$self->body( $self->body . $appendage );\n}\n\nsub openpage  { (shift)->appendbody('<page>') }\nsub closepage { (shift)->appendbody('</page>') }\n\npackage Document::PageWithHeadersAndFooters;\nuse Moose;\n\nextends 'Document::Page';\n\naugment 'create' => sub {\nmy $self = shift;\n$self->createheader;\ninner();\n$self->createfooter;\n};\n\nsub createheader { (shift)->appendbody('<header/>') }\nsub createfooter { (shift)->appendbody('<footer/>') }\n\npackage TPSReport;\nuse Moose;\n\nextends 'Document::PageWithHeadersAndFooters';\n\naugment 'create' => sub {\nmy $self = shift;\n$self->createtpsreport;\ninner();\n};\n\nsub createtpsreport {\n(shift)->appendbody('<report type=\"tps\"/>');\n}\n\n# <page><header/><report type=\"tps\"/><footer/></page>\nmy $reportxml = TPSReport->new->create;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This recipe shows how the \"augment\" method modifier works. This\nmodifier reverses the normal subclass to parent method resolution\norder. With an \"augment\" modifier the least specific method is called\nfirst. Each successive call to \"inner\" descends the inheritance tree,\nending at the most specific subclass.\n\nThe \"augment\" modifier lets you design a parent class that can be\nextended in a specific way. The parent provides generic wrapper\nfunctionality, and the subclasses fill in the details.\n\nIn the example above, we've created a set of document classes, with the\nmost specific being the \"TPSReport\" class.\n\nWe start with the least specific class, \"Document::Page\". Its create\nmethod contains a call to \"inner()\":\n\nsub create {\nmy $self = shift;\n$self->openpage;\ninner();\n$self->closepage;\n}\n\nThe \"inner\" function is exported by \"Moose\", and is like \"super\" for\naugmented methods. When \"inner\" is called, Moose finds the next method\nin the chain, which is the \"augment\" modifier in\n\"Document::PageWithHeadersAndFooters\". You'll note that we can call\n\"inner\" in our modifier:\n\naugment 'create' => sub {\nmy $self = shift;\n$self->createheader;\ninner();\n$self->createfooter;\n};\n\nThis finds the next most specific modifier, in the \"TPSReport\" class.\n\nFinally, in the \"TPSReport\" class, the chain comes to an end:\n\naugment 'create' => sub {\nmy $self = shift;\n$self->createtpsreport;\ninner();\n};\n\nWe do call the \"inner\" function one more time, but since there is no\nmore specific subclass, this is a no-op. Making this call means we can\neasily subclass \"TPSReport\" in the future.\n",
            "subsections": []
        },
        "CONCLUSION": {
            "content": "The \"augment\" modifier is a powerful tool for creating a set of nested\nwrappers. It's not something you will need often, but when you do, it\nis very handy.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "o   Stevan Little <stevan@cpan.org>\n\no   Dave Rolsky <autarch@urth.org>\n\no   Jesse Luehrs <doy@cpan.org>\n\no   Shawn M Moore <sartak@cpan.org>\n\no    ' (Yuval Kogman) <nothingmuch@woobling.org>\n\no   Karen Etheridge <ether@cpan.org>\n\no   Florian Ragwitz <rafl@debian.org>\n\no   Hans Dieter Pearcey <hdp@cpan.org>\n\no   Chris Prather <chris@prather.org>\n\no   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\nthe same terms as the Perl 5 programming language system itself.\n\nperl v5.34.0            Moose::Cookbook::Basics::DocumentAugmentAndInner(3pm)",
            "subsections": []
        }
    },
    "summary": "Moose::Cookbook::Basics::DocumentAugmentAndInner - The augment modifier, which turns normal method overriding \"inside-out\"",
    "flags": [],
    "examples": [],
    "see_also": []
}