File Coverage

blib/lib/KiokuDB/TypeMap/Entry/Passthrough.pm
Criterion Covered Total %
statement 2 4 50.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 4 6 66.6


line stmt bran cond sub pod time code
1             package KiokuDB::TypeMap::Entry::Passthrough;
2             BEGIN {
3 1     1   25696 $KiokuDB::TypeMap::Entry::Passthrough::AUTHORITY = 'cpan:NUFFIN';
4             }
5             $KiokuDB::TypeMap::Entry::Passthrough::VERSION = '0.57';
6 1     1   1873 use Moose;
  0            
  0            
7             # ABSTRACT: A typemap entry of objects that will be serialized by the backend.
8              
9             use Carp qw(croak);
10              
11             use KiokuDB::TypeMap::Entry::Compiled;
12              
13             no warnings 'recursion';
14              
15             use namespace::clean -except => 'meta';
16              
17             with qw(KiokuDB::TypeMap::Entry);
18              
19             has intrinsic => (
20             isa => "Bool",
21             is => "ro",
22             default => 0,
23             );
24              
25             sub compile {
26             my ( $self, $class ) = @_;
27              
28             if ( $self->intrinsic ) {
29             return KiokuDB::TypeMap::Entry::Compiled->new(
30             collapse_method => sub { $_[1] },
31             expand_method => sub { $_[1]->data }, # only called on an Entry, if the object is just an object, this won't be called
32             id_method => "generate_uuid",
33             refresh_method => sub {
34             croak "Refreshing Passthrough typemap entries is not supported ($class)";
35             },
36             entry => $self,
37             class => $class,
38             );
39             } else {
40             return KiokuDB::TypeMap::Entry::Compiled->new(
41             collapse_method => sub {
42             my ( $collapser, @args ) = @_;
43              
44             $collapser->collapse_first_class(
45             sub {
46             my ( $collapser, %args ) = @_;
47             return $collapser->make_entry(
48             %args,
49             data => $args{object},
50             );
51             },
52             @args,
53             );
54             },
55             expand_method => sub {
56             my ( $linker, $entry ) = @_;
57              
58             my $obj = $entry->data;
59              
60             $linker->register_object( $entry => $obj );
61              
62             return $obj;
63             },
64             id_method => "generate_uuid",
65             refresh_method => sub {
66             croak "Refreshing Passthrough typemap entries is not supported ($class)";
67             },
68             entry => $self,
69             class => $class,
70             );
71             }
72             }
73              
74             __PACKAGE__->meta->make_immutable;
75              
76             __PACKAGE__
77              
78             __END__
79              
80             =pod
81              
82             =encoding UTF-8
83              
84             =head1 NAME
85              
86             KiokuDB::TypeMap::Entry::Passthrough - A typemap entry of objects that will be serialized by the backend.
87              
88             =head1 VERSION
89              
90             version 0.57
91              
92             =head1 SYNOPSIS
93              
94             KiokuDB::TypeMap->new(
95             entires => {
96             'Value::Object' => KiokuDB::TypeMap::Entry::Naive->new,
97             },
98             );
99              
100             =head1 DESCRIPTION
101              
102             This typemap entry delegates the handling of certain objects to the backend.
103              
104             A prime example is L<DateTime> being handled by
105             L<KiokuDB::Backend::Serialize::Storable>. L<DateTime> has efficient L<Storable>
106             hooks, and does not refer to any domain objects, so it is safe to assume that
107             it can just be passed through for serialization.
108              
109             =head1 ATTRIBUTES
110              
111             =over 4
112              
113             =item intrinsic
114              
115             If true the object will be just left in place.
116              
117             If false, the object will get its own ID and entry, and the object will be in
118             the C<data> field of that entry.
119              
120             =back
121              
122             =head1 AUTHOR
123              
124             Yuval Kogman <nothingmuch@woobling.org>
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.
129              
130             This is free software; you can redistribute it and/or modify it under
131             the same terms as the Perl 5 programming language system itself.
132              
133             =cut