=head1 NAME
-Moose::Cookbook::Recipe6 - The Moose::Role example
+Moose::Cookbook::Recipe6 - The augment/inner example
=head1 SYNOPSIS
+
+ package Document::Page;
+ use Moose;
- package Constraint;
- use strict;
- use warnings;
- use Moose::Role;
-
- has 'value' => (isa => 'Int', is => 'ro');
+ has 'body' => (is => 'rw', isa => 'Str', default => sub {''});
- around 'validate' => sub {
- my $c = shift;
- my ($self, $field) = @_;
- if ($c->($self, $self->validation_value($field))) {
- return undef;
- }
- else {
- return $self->error_message;
- }
- };
+ sub create {
+ my $self = shift;
+ $self->open_page;
+ inner();
+ $self->close_page;
+ }
- sub validation_value {
- my ($self, $field) = @_;
- return $field;
+ sub append_body {
+ my ($self, $appendage) = @_;
+ $self->body($self->body . $appendage);
}
- sub error_message { confess "Abstract method!" }
+ sub open_page { (shift)->append_body('<page>') }
+ sub close_page { (shift)->append_body('</page>') }
- package Constraint::OnLength;
- use strict;
- use warnings;
- use Moose::Role;
+ package Document::PageWithHeadersAndFooters;
+ use Moose;
- has 'units' => (isa => 'Str', is => 'ro');
+ extends 'Document::Page';
- override 'validation_value' => sub {
- return length(super());
+ augment 'create' => sub {
+ my $self = shift;
+ $self->create_header;
+ inner();
+ $self->create_footer;
};
- override 'error_message' => sub {
- my $self = shift;
- return super() . ' ' . $self->units;
- };
+ sub create_header { (shift)->append_body('<header/>') }
+ sub create_footer { (shift)->append_body('<footer/>') }
- package Constraint::AtLeast;
- use strict;
- use warnings;
+ package TPSReport;
use Moose;
- with 'Constraint';
-
- sub validate {
- my ($self, $field) = @_;
- ($field >= $self->value);
- }
-
- sub error_message { 'must be at least ' . (shift)->value; }
-
- package Constraint::NoMoreThan;
- use strict;
- use warnings;
- use Moose;
+ extends 'Document::PageWithHeadersAndFooters';
- with 'Constraint';
+ augment 'create' => sub {
+ my $self = shift;
+ $self->create_tps_report;
+ };
- sub validate {
- my ($self, $field) = @_;
- ($field <= $self->value);
+ sub create_tps_report {
+ (shift)->append_body('<report type="tps"/>')
}
- sub error_message { 'must be no more than ' . (shift)->value; }
-
- package Constraint::LengthNoMoreThan;
- use strict;
- use warnings;
- use Moose;
-
- extends 'Constraint::NoMoreThan';
- with 'Constraint::OnLength';
-
- package Constraint::LengthAtLeast;
- use strict;
- use warnings;
- use Moose;
-
- extends 'Constraint::AtLeast';
- with 'Constraint::OnLength';
-
+ print TPSReport->new->create # <page><header/><report type="tps"/><footer/></page>
+
=head1 DESCRIPTION
-Coming Soon.
+Coming Soon.
+
+=head1 CONCLUSION
+
+=head1 FOOTNOTES
+
+=over 4
-(the other 4 recipes kinda burned me out a bit)
+=back
=head1 AUTHOR
=head1 COPYRIGHT AND LICENSE
-Copyright 2006 by Infinity Interactive, Inc.
+Copyright 2007 by Infinity Interactive, Inc.
L<http://www.iinteractive.com>
it under the same terms as Perl itself.
=cut
-
\ No newline at end of file