From: Dave Rolsky Date: Tue, 10 Feb 2009 15:29:39 +0000 (+0000) Subject: Write the description for basics recipe 6. X-Git-Tag: 0.69~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=71181776010b0536310f950c8aae859be6a3667c;p=gitmo%2FMoose.git Write the description for basics recipe 6. Added an inner() call at the bottom of the subclass hierarchy for good style. --- diff --git a/lib/Moose/Cookbook/Basics/Recipe6.pod b/lib/Moose/Cookbook/Basics/Recipe6.pod index 9fb42dd..a46e4c0 100644 --- a/lib/Moose/Cookbook/Basics/Recipe6.pod +++ b/lib/Moose/Cookbook/Basics/Recipe6.pod @@ -50,6 +50,7 @@ Moose::Cookbook::Basics::Recipe6 - The augment/inner example augment 'create' => sub { my $self = shift; $self->create_tps_report; + inner(); }; sub create_tps_report { @@ -61,27 +62,75 @@ Moose::Cookbook::Basics::Recipe6 - The augment/inner example =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 diff --git a/t/000_recipes/basics/006_augment_inner.t b/t/000_recipes/basics/006_augment_inner.t index 04f2f1d..0f6ae60 100644 --- a/t/000_recipes/basics/006_augment_inner.t +++ b/t/000_recipes/basics/006_augment_inner.t @@ -54,6 +54,7 @@ use Test::Exception; augment 'create' => sub { my $self = shift; $self->create_tps_report; + inner(); }; sub create_tps_report {