| 1 | #!/usr/bin/perl | ||||||||||
| 2 | |||||||||||
| 3 | package KiokuDB::TypeMap::Entry::Passthrough; | ||||||||||
| 4 | 13 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 13 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 13 | ▶ | use KiokuDB::TypeMap::Entry::Compiled; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 13 | ▶ | no warnings 'recursion'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 13 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 13 | with qw(KiokuDB::TypeMap::Entry); | |||||||||
| 15 | |||||||||||
| 16 | 13 | has intrinsic => ( | |||||||||
| 17 | isa => "Bool", | ||||||||||
| 18 | is => "ro", | ||||||||||
| 19 | default => 0, | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | sub compile { | ||||||||||
| 23 | 82 | ▶ | my ( $self, $class ) = @_; | ||||||||
|
Subroutine
compile: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 24 | |||||||||||
| 25 | 82 | ▶ | if ( $self->intrinsic ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | return KiokuDB::TypeMap::Entry::Compiled->new( | ||||||||||
| 27 | 78 | ▶ | collapse_method => sub { $_[1] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 1 | ▶ | expand_method => sub { $_[1]->data }, # only called on an Entry, if the object is just an object, this won't be called | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 29 | id_method => "generate_uuid", | ||||||||||
| 30 | refresh_method => sub { | ||||||||||
| 31 | 0 | ▶ | croak "Refreshing Passthrough typemap entries is not supported ($class)"; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 32 | }, | ||||||||||
| 33 | 81 | entry => $self, | |||||||||
| 34 | class => $class, | ||||||||||
| 35 | ); | ||||||||||
| 36 | } else { | ||||||||||
| 37 | return KiokuDB::TypeMap::Entry::Compiled->new( | ||||||||||
| 38 | collapse_method => sub { | ||||||||||
| 39 | 1 | ▶ | my ( $collapser, @args ) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 40 | |||||||||||
| 41 | $collapser->collapse_first_class( | ||||||||||
| 42 | sub { | ||||||||||
| 43 | 1 | ▶ | my ( $collapser, %args ) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 44 | return $collapser->make_entry( | ||||||||||
| 45 | %args, | ||||||||||
| 46 | data => $args{object}, | ||||||||||
| 47 | 1 | ); | |||||||||
| 48 | }, | ||||||||||
| 49 | 1 | @args, | |||||||||
| 50 | ); | ||||||||||
| 51 | }, | ||||||||||
| 52 | expand_method => sub { | ||||||||||
| 53 | 1 | ▶ | my ( $linker, $entry ) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 54 | |||||||||||
| 55 | 1 | my $obj = $entry->data; | |||||||||
| 56 | |||||||||||
| 57 | 1 | $linker->register_object( $entry => $obj ); | |||||||||
| 58 | |||||||||||
| 59 | 1 | return $obj; | |||||||||
| 60 | }, | ||||||||||
| 61 | id_method => "generate_uuid", | ||||||||||
| 62 | refresh_method => sub { | ||||||||||
| 63 | 0 | ▶ | croak "Refreshing Passthrough typemap entries is not supported ($class)"; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 64 | }, | ||||||||||
| 65 | 1 | entry => $self, | |||||||||
| 66 | class => $class, | ||||||||||
| 67 | ); | ||||||||||
| 68 | } | ||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 13 | __PACKAGE__->meta->make_immutable; | |||||||||
| 72 | |||||||||||
| 73 | 13 | __PACKAGE__ | |||||||||
| 74 | |||||||||||
| 75 | __END__ | ||||||||||
| 76 | |||||||||||
| 77 | =pod | ||||||||||
| 78 | |||||||||||
| 79 | =head1 NAME | ||||||||||
| 80 | |||||||||||
| 81 | KiokuDB::TypeMap::Entry::Passthrough - A typemap entry of objects that will be | ||||||||||
| 82 | serialized by the backend. | ||||||||||
| 83 | |||||||||||
| 84 | =head1 SYNOPSIS | ||||||||||
| 85 | |||||||||||
| 86 | KiokuDB::TypeMap->new( | ||||||||||
| 87 | entires => { | ||||||||||
| 88 | 'Value::Object' => KiokuDB::TypeMap::Entry::Naive->new, | ||||||||||
| 89 | }, | ||||||||||
| 90 | ); | ||||||||||
| 91 | |||||||||||
| 92 | =head1 DESCRIPTION | ||||||||||
| 93 | |||||||||||
| 94 | This typemap entry delegates the handling of certain objects to the backend. | ||||||||||
| 95 | |||||||||||
| 96 | A prime example is L<DateTime> being handled by | ||||||||||
| 97 | L<KiokuDB::Backend::Serialize::Storable>. L<DateTime> has efficient L<Storable> | ||||||||||
| 98 | hooks, and does not refer to any domain objects, so it is safe to assume that | ||||||||||
| 99 | it can just be passed through for serialization. | ||||||||||
| 100 | |||||||||||
| 101 | =head1 ATTRIBUTES | ||||||||||
| 102 | |||||||||||
| 103 | =over 4 | ||||||||||
| 104 | |||||||||||
| 105 | =item intrinsic | ||||||||||
| 106 | |||||||||||
| 107 | If true the object will be just left in place. | ||||||||||
| 108 | |||||||||||
| 109 | If false, the object will get its own ID and entry, and the object will be in | ||||||||||
| 110 | the C<data> field of that entry. | ||||||||||
| 111 | |||||||||||
| 112 | =back | ||||||||||