Non hashref instances are no longer a pipe dream, update the caveat in Recipe1
[gitmo/Moose.git] / lib / Moose / Cookbook / Recipe6.pod
index 42c2381..6381776 100644 (file)
@@ -3,73 +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 Eq;
-  use strict;
-  use warnings;
-  use Moose::Role;
-  
-  requires 'equal_to';
+  has 'body' => (is => 'rw', isa => 'Str', default => sub {''});
   
-  sub not_equal_to { 
-      my ($self, $other) = @_;
-      !$self->equal_to($other);
+  sub create {
+      my $self = shift;
+      $self->open_page;
+      inner();
+      $self->close_page;
   }
   
-  package Ord;
-  use strict;
-  use warnings;
-  use Moose::Role;
-  
-  with 'Eq';
-  
-  requires 'compare';
+  sub append_body { 
+      my ($self, $appendage) = @_;
+      $self->body($self->body . $appendage);
+  }
   
-  sub equal_to {
-      my ($self, $other) = @_;
-      $self->compare($other) == 0;
-  }    
+  sub open_page  { (shift)->append_body('<page>') }
+  sub close_page { (shift)->append_body('</page>') }  
   
-  sub greater_than {
-      my ($self, $other) = @_;
-      $self->compare($other) == 1;
-  }    
+  package Document::PageWithHeadersAndFooters;
+  use Moose;
   
-  sub less_than {
-      my ($self, $other) = @_;
-      $self->compare($other) == -1;
-  }
+  extends 'Document::Page';
   
-  sub greater_than_or_equal_to {
-      my ($self, $other) = @_;
-      $self->greater_than($other) || $self->equal_to($other);
-  }        
+  augment 'create' => sub {
+      my $self = shift;
+      $self->create_header;
+      inner();
+      $self->create_footer;
+  };
   
-  sub less_than_or_equal_to {
-      my ($self, $other) = @_;
-      $self->less_than($other) || $self->equal_to($other);
-  }    
+  sub create_header { (shift)->append_body('<header/>') }
+  sub create_footer { (shift)->append_body('<footer/>') }  
   
-  package US::Currency;
-  use strict;
-  use warnings;
+  package TPSReport;
   use Moose;
   
-  with 'Ord';
+  extends 'Document::PageWithHeadersAndFooters';
   
-  has 'amount' => (is => 'rw', isa => 'Int', default => 0);
+  augment 'create' => sub {
+      my $self = shift;
+      $self->create_tps_report;
+  };
   
-  sub compare {
-      my ($self, $other) = @_;
-      $self->amount <=> $other->amount;
+  sub create_tps_report {
+     (shift)->append_body('<report type="tps"/>') 
   }
   
+  print TPSReport->new->create # <page><header/><report type="tps"/><footer/></page>
+
 =head1 DESCRIPTION
 
-Coming Soon. 
+Coming Soon.
+
+=head1 CONCLUSION
+
+=head1 FOOTNOTES
+
+=over 4
+
+=back
 
 =head1 AUTHOR
 
@@ -77,7 +76,7 @@ Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006 by Infinity Interactive, Inc.
+Copyright 2007 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>
 
@@ -85,4 +84,3 @@ This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut       
-       
\ No newline at end of file