1MooseX::Storage::TraitsU:s:eOrnlCyoWnhterniBbuuitletdM(o3Po)esrelX:D:oSctuomreangtea:t:iTornaits::OnlyWhenBuilt(3)
2
3
4
6 MooseX::Storage::Traits::OnlyWhenBuilt - A custom trait to bypass
7 serialization
8
10 { package Point;
11 use Moose;
12 use MooseX::Storage;
13
14 with Storage( traits => [qw|OnlyWhenBuilt|] );
15
16 has 'x' => (is => 'rw', lazy_build => 1 );
17 has 'y' => (is => 'rw', lazy_build => 1 );
18 has 'z' => (is => 'rw', builder => '_build_z' );
19
20 sub _build_x { 3 }
21 sub _build_y { expensive_computation() }
22 sub _build_z { 3 }
23
24 }
25
26 my $p = Point->new( 'x' => 4 );
27
28 # the result of ->pack will contain:
29 # { x => 4, z => 3 }
30 $p->pack;
31
33 Sometimes you don't want a particular attribute to be part of the
34 serialization if it has not been built yet. If you invoke "Storage()"
35 as outlined in the "Synopsis", only attributes that have been built
36 (ie, where the predicate returns 'true') will be serialized. This
37 avoids any potentially expensive computations.
38
39 See the SYNOPSIS for a nice example that can be easily cargo-culted.
40
42 Introspection
43 meta
44
46 All complex software has bugs lurking in it, and this module is no
47 exception. If you find a bug please either email me, or add the bug to
48 cpan-RT.
49
51 Stevan Little <stevan.little@iinteractive.com>
52
54 Copyright 2007-2008 by Infinity Interactive, Inc.
55
56 <http://www.iinteractive.com>
57
58 This library is free software; you can redistribute it and/or modify it
59 under the same terms as Perl itself.
60
61
62
63perl v5.12.0 2009M-o0o7s-e1X4::Storage::Traits::OnlyWhenBuilt(3)