X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FCookbook%2FRecipe6.pod;h=6381776c67ee72a7935cadb4df4d22f6adef2b80;hb=1eca36fc96204137a3ddf5038610fde40c55e39e;hp=ed8d57212e332b0b1872d892edafd786b4589ffa;hpb=a7d0cd00a63c674bb47b228e7d1158db25968e16;p=gitmo%2FMoose.git diff --git a/lib/Moose/Cookbook/Recipe6.pod b/lib/Moose/Cookbook/Recipe6.pod index ed8d572..6381776 100644 --- a/lib/Moose/Cookbook/Recipe6.pod +++ b/lib/Moose/Cookbook/Recipe6.pod @@ -3,100 +3,72 @@ =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('') } + sub close_page { (shift)->append_body('') } - 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('
') } + sub create_footer { (shift)->append_body('