KiokuDB::TypeMap::Entry::Callback - Callback based inflation/deflation of objects
version 0.56
KiokuDB::TypeMap->new( entries => { 'My::Class' => KiokuDB::TypeMap::Entry::Callback->new( expand => "new", # My::Class->new(%$self) collapse => sub { my $self = shift; return %$self; # provide args to 'new' in this example }, id => sub { "foo" }, # 'id' callback is optional ), }, );
This KiokuDB::TypeMap entry provides callback based inflation/deflation.
The major limitation of this method is that it cannot be used for self referential structures. This is because the object being inflated is only constructed after all of its arguments are.
For the overwhelming majority of the use cases this is good enough though.
A method name or code reference invoked on the object during collapsing.
This is evaluated in list context, and the list of values it returns will be collapsed by the KiokuDB::Collapser and then stored.
A method name or code reference invoked on the class of the object during loading.
The arguments are as returned by the collapse callback.
collapse
An optional method name or code reference invoked to get an ID for the object.
If one is not provided the default (UUID based) generation is used.
A boolean denoting whether or not the object should be collapsed with no ID, and serialized as part of its parent object.
This is useful for value like objects, for whom the reference address makes no difference (such as URI objects).
Yuval Kogman <nothingmuch@woobling.org>
This software is copyright (c) 2013 by Yuval Kogman, Infinity Interactive.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install KiokuDB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm KiokuDB
CPAN shell
perl -MCPAN -e shell install KiokuDB
For more information on module installation, please visit the detailed CPAN module installation guide.