Change so that we just return the class name, so that roles can permute this class...
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Traits / OnlyWhenBuilt.pm
CommitLineData
76218b46 1package MooseX::Storage::Traits::OnlyWhenBuilt;
2use Moose::Role;
3
4our $VERSION = '0.18';
5our $AUTHORITY = 'cpan:STEVAN';
6
71;
8
9__END__
10
11=pod
12
13=head1 NAME
14
15MooseX::Storage::Traits::OnlyWhenBuilt - A custom trait to bypass serialization
16
17=head1 SYNOPSIS
18
19
20 { package Point;
21 use Moose;
22 use MooseX::Storage;
23
24 with Storage( traits => [qw|OnlyWhenBuilt|] );
25
26 has 'x' => (is => 'rw', lazy_build => 1 );
27 has 'y' => (is => 'rw', lazy_build => 1 );
28 has 'z' => (is => 'rw', builder => '_build_z' );
29
30
31 sub _build_x { 3 }
32 sub _build_y { expensive_computation() }
33 sub _build_z { 3 }
34
35 }
36
37 my $p = Point->new( 'x' => 4 );
38
39 # the result of ->pack will contain:
40 # { x => 4, z => 3 }
41 $p->pack;
42
43=head1 DESCRIPTION
44
45Sometimes you don't want a particular attribute to be part of the
46serialization if it has not been built yet. If you invoke C<Storage()>
47as outlined in the C<Synopsis>, only attributes that have been built
48(ie, where the predicate returns 'true') will be serialized.
49This avoids any potentially expensive computations.
50
51See the SYNOPSIS for a nice example that can be easily cargo-culted.
52
53=head1 METHODS
54
55=head2 Introspection
56
57=over 4
58
59=item B<meta>
60
61=back
62
63=head1 BUGS
64
65All complex software has bugs lurking in it, and this module is no
66exception. If you find a bug please either email me, or add the bug
67to cpan-RT.
68
69=head1 AUTHOR
70
71Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
72
73=head1 COPYRIGHT AND LICENSE
74
75Copyright 2007-2008 by Infinity Interactive, Inc.
76
77L<http://www.iinteractive.com>
78
79This library is free software; you can redistribute it and/or modify
80it under the same terms as Perl itself.
81
82=cut