1 package MooseX::Storage::Traits::OnlyWhenBuilt;
5 our $AUTHORITY = 'cpan:STEVAN';
15 MooseX::Storage::Traits::OnlyWhenBuilt - A custom trait to bypass serialization
24 with Storage( traits => [qw|OnlyWhenBuilt|] );
26 has 'x' => (is => 'rw', lazy_build => 1 );
27 has 'y' => (is => 'rw', lazy_build => 1 );
28 has 'z' => (is => 'rw', builder => '_build_z' );
32 sub _build_y { expensive_computation() }
37 my $p = Point->new( 'x' => 4 );
39 # the result of ->pack will contain:
45 Sometimes you don't want a particular attribute to be part of the
46 serialization if it has not been built yet. If you invoke C<Storage()>
47 as outlined in the C<Synopsis>, only attributes that have been built
48 (ie, where the predicate returns 'true') will be serialized.
49 This avoids any potentially expensive computations.
51 See the SYNOPSIS for a nice example that can be easily cargo-culted.
65 All complex software has bugs lurking in it, and this module is no
66 exception. If you find a bug please either email me, or add the bug
71 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
73 =head1 COPYRIGHT AND LICENSE
75 Copyright 2007-2008 by Infinity Interactive, Inc.
77 L<http://www.iinteractive.com>
79 This library is free software; you can redistribute it and/or modify
80 it under the same terms as Perl itself.