3625a30d8e357e8be153f0097128a2c1df667345
[gitmo/Moose.git] / lib / Moose / Cookbook / Recipe3.pod
1
2 =pod
3
4 =head1 NAME
5
6 Moose::Cookbook::Recipe3 - A binary tree
7
8 =head1 SYNOPSIS
9
10   package BinaryTree;
11   use strict;
12   use warnings;
13   use Moose;
14   
15   has 'parent' => (
16           is        => 'rw',
17           isa       => 'BinaryTree',    
18       predicate => 'has_parent',
19           weak_ref  => 1,
20   );
21   
22   has 'left' => (
23           is        => 'rw',    
24           isa       => 'BinaryTree',            
25       predicate => 'has_left',  
26       lazy      => 1,
27       default   => sub { BinaryTree->new(parent => $_[0]) },       
28   );
29   
30   has 'right' => (
31           is        => 'rw',    
32           isa       => 'BinaryTree',            
33       predicate => 'has_right',   
34       lazy      => 1,       
35       default   => sub { BinaryTree->new(parent => $_[0]) },       
36   );
37   
38   before 'right', 'left' => sub {
39       my ($self, $tree) = @_;
40       $tree->parent($self) if defined $tree;   
41   };
42
43 =head1 DESCRIPTION
44
45 =head1 AUTHOR
46
47 Stevan Little E<lt>stevan@iinteractive.comE<gt>
48
49 =head1 COPYRIGHT AND LICENSE
50
51 Copyright 2006 by Infinity Interactive, Inc.
52
53 L<http://www.iinteractive.com>
54
55 This library is free software; you can redistribute it and/or modify
56 it under the same terms as Perl itself.
57
58 =cut