X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FCookbook%2FBasics%2FRecipe6.pod;h=a46e4c023314d1cfdca3a6a187c466240d1e6692;hb=ccea63ce44db05da6bbc1a51a136ead4c275f8e4;hp=bce383d66450c8c65d5a42f5503b4cc7e8273f2c;hpb=021b8139fcacfbd1c0d4dc26e07936457f1ba12b;p=gitmo%2FMoose.git
diff --git a/lib/Moose/Cookbook/Basics/Recipe6.pod b/lib/Moose/Cookbook/Basics/Recipe6.pod
index bce383d..a46e4c0 100644
--- a/lib/Moose/Cookbook/Basics/Recipe6.pod
+++ b/lib/Moose/Cookbook/Basics/Recipe6.pod
@@ -6,81 +6,131 @@
Moose::Cookbook::Basics::Recipe6 - The augment/inner example
=head1 SYNOPSIS
-
+
package Document::Page;
use Moose;
-
- has 'body' => (is => 'rw', isa => 'Str', default => sub {''});
-
+
+ has 'body' => ( is => 'rw', isa => 'Str', default => sub {''} );
+
sub create {
my $self = shift;
$self->open_page;
inner();
$self->close_page;
}
-
- sub append_body {
- my ($self, $appendage) = @_;
- $self->body($self->body . $appendage);
+
+ sub append_body {
+ my ( $self, $appendage ) = @_;
+ $self->body( $self->body . $appendage );
}
-
+
sub open_page { (shift)->append_body('') }
- sub close_page { (shift)->append_body('') }
-
+ sub close_page { (shift)->append_body('') }
+
package Document::PageWithHeadersAndFooters;
use Moose;
-
+
extends 'Document::Page';
-
+
augment 'create' => sub {
my $self = shift;
$self->create_header;
inner();
$self->create_footer;
};
-
+
sub create_header { (shift)->append_body('') }
- sub create_footer { (shift)->append_body('') }
-
+ sub create_footer { (shift)->append_body('') }
+
package TPSReport;
use Moose;
-
+
extends 'Document::PageWithHeadersAndFooters';
-
+
augment 'create' => sub {
my $self = shift;
$self->create_tps_report;
+ inner();
};
-
+
sub create_tps_report {
- (shift)->append_body('')
+ (shift)->append_body('');
}
-
- print TPSReport->new->create #
+
+ #
+ print TPSReport->new->create;
=head1 DESCRIPTION
-Coming Soon.
+This recipe shows how the C method modifier works. This
+modifier reverses the normal subclass to parent method resolution
+order. With an C modifier the I specific method is
+called first. Each successive call to C descends the
+inheritance tree, ending at the most specific subclass.
-=head1 CONCLUSION
+The C modifier lets you design a parent class that can be
+extended in a specific way. The parent provides generic wrapper
+functionality, and the subclasses fill in the details.
-=head1 FOOTNOTES
+In the example above, we've created a set of document classes, with
+the most specific being the C class.
-=over 4
+We start with the least specific class, C. Its create
+method contains a call to C:
-=back
+ sub create {
+ my $self = shift;
+ $self->open_page;
+ inner();
+ $self->close_page;
+ }
+
+The C function is exported by C, and is like C
+for augmented methods. When C is called, Moose finds the next
+method in the chain, which is the C modifier in
+C. You'll note that we can call
+C in our modifier:
+
+ augment 'create' => sub {
+ my $self = shift;
+ $self->create_header;
+ inner();
+ $self->create_footer;
+ };
+
+This finds the next most specific modifier, in the C class.
+
+Finally, in the C class, the chain comes to an end:
+
+ augment 'create' => sub {
+ my $self = shift;
+ $self->create_tps_report;
+ inner();
+ };
+
+We do call the C function one more time, but since there is no
+more specific subclass, this is a no-op. Making this call means we can
+easily subclass C in the future.
+
+=head1 CONCLUSION
+
+The C modifier is a powerful tool for creating a set of
+nested wrappers. It's not something you will need often, but when you
+do it is very handy.
=head1 AUTHOR
Stevan Little Estevan@iinteractive.comE
+Dave Rolsky Eautarch@urth.orgE
+
=head1 COPYRIGHT AND LICENSE
-Copyright 2007 by Infinity Interactive, Inc.
+Copyright 2007-2009 by Infinity Interactive, Inc.
L
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
-=cut
+=cut