1MooseX::Storage::EngineU:s:eTrraCiotn:tM:roOionbslueytXWe:hd:eSnPtBeourrilalgtDe(o:3c:)uEmnegnitnaet:i:oTnrait::OnlyWhenBuilt(3)
2
3
4
6 MooseX::Storage::Engine::Trait::OnlyWhenBuilt - An engine trait to
7 bypass 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 my $p = Point->new( 'x' => 4 );
26
27 # the result of ->pack will contain:
28 # { x => 4, z => 3 }
29 $p->pack;
30
32 Sometimes you don't want a particular attribute to be part of the
33 serialization if it has not been built yet. If you invoke "Storage()"
34 as outlined in the "Synopsis", only attributes that have been built
35 (ie, where the predicate returns 'true') will be serialized. This
36 avoids any potentially expensive computations.
37
38 This trait is applied to an instance of MooseX::Storage::Engine, for
39 the user-visible version shown in the SYNOPSIS, see
40 MooseX::Storage::Traits::OnlyWhenBuilt
41
43 Introspection
44 meta
45
47 All complex software has bugs lurking in it, and this module is no
48 exception. If you find a bug please either email me, or add the bug to
49 cpan-RT.
50
52 Stevan Little <stevan.little@iinteractive.com>
53
55 Copyright 2007-2008 by Infinity Interactive, Inc.
56
57 <http://www.iinteractive.com>
58
59 This library is free software; you can redistribute it and/or modify it
60 under the same terms as Perl itself.
61
62
63
64perl v5.12.0 Moos2e0X0:9:-S0t7o-r1a3ge::Engine::Trait::OnlyWhenBuilt(3)