MooX::Augment - adds "augment method => sub {...}" support to Moo
use v5.14; use strict; use Test::More; package Document { use Moo; use MooX::Augment -class; has recipient => (is => 'ro'); sub as_xml { sprintf "<document>%s</document>", inner } } package Greeting { use Moo; use MooX::Augment -class; extends qw( Document ); augment as_xml => sub { sprintf "<greet>%s</greet>", inner } } package Greeting::English { use Moo; use MooX::Augment -class; extends qw( Greeting ); augment as_xml => sub { my $self = shift; sprintf "Hello %s", $self->recipient; } } my $obj = Greeting::English->new(recipient => "World"); is( $obj->as_xml, "<document><greet>Hello World</greet></document>", ); done_testing();
MooX::Augment extends Moo with the augment method modifier, allowing you to use this Moose abomination for augmenting superclass methods in Moo classes.
augment
You need to indicate whether you are using this within a Moo class or a Moo role:
use MooX::Augment -class; use MooX::Augment -role;
Note that Moo roles cannot provide augment method modifiers. Roles may import inner though it has not been thoroughly tested and may be of limited utility.
inner
See Class::Method::ModifiersX::Augment for further details.
Moo, Class::Method::ModifiersX::Augment.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install Class::Method::ModifiersX::Augment, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Method::ModifiersX::Augment
CPAN shell
perl -MCPAN -e shell install Class::Method::ModifiersX::Augment
For more information on module installation, please visit the detailed CPAN module installation guide.