* add support for Storage( traits => [...] ) to alter the behaviour of the
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage.pm
index 2686d56..e74a606 100644 (file)
@@ -52,6 +52,13 @@ sub _injected_storage_role_generator {
         #    || confess "You must specify a format role in order to use an IO role";
         push @roles => 'MooseX::Storage::IO::' . $params{'io'};
     }
+    
+    # Note:
+    # These traits alter the behaviour of the engine, the user can
+    # specify these per role-usage
+    for my $trait ( @{ $params{'traits'} ||= [] } ) {
+        push @roles, 'MooseX::Storage::Traits::'.$trait;
+    }
         
     Class::MOP::load_class($_) 
         || die "Could not load role (" . $_ . ")"
@@ -164,6 +171,27 @@ to also be used, the expection being the C<StorableFile> role.
 
 =back
 
+=head2 Behaviour modifiers
+
+The serialization behaviour can be changed by supplying C<traits>.
+This can be done as follows:
+
+  use MooseX::Storage;
+  with Storage( traits => [Trait1, Trait2,...] );
+  
+The following traits are currently bundled with C<MooseX::Storage>:
+
+=over 4
+
+=item OnlyWhenBuilt
+
+Only attributes that have been built (ie, where the predicate returns 
+'true') will be serialized. This avoids any potentially expensive computations.
+
+See L<MooseX::Storage::Traits::OnlyWhenBuilt> for details.
+
+=back
+
 =head2 How we serialize
 
 There are always limits to any serialization framework, there are just