| 1 | #!/usr/bin/perl | ||||||||||
| 2 | |||||||||||
| 3 | package KiokuDB::Backend::Serialize::Storable; | ||||||||||
| 4 | 20 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 20 | ▶ | use Storable qw(nfreeze thaw nstore_fd fd_retrieve); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 20 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 20 | with qw( | |||||||||
| 11 | KiokuDB::Backend::Serialize | ||||||||||
| 12 | KiokuDB::Backend::Role::UnicodeSafe | ||||||||||
| 13 | KiokuDB::Backend::Role::BinarySafe | ||||||||||
| 14 | KiokuDB::Backend::TypeMap::Default::Storable | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | sub serialize { | ||||||||||
| 18 | 2013 | ▶ | my ( $self, $entry ) = @_; | ||||||||
|
Subroutine
serialize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 19 | |||||||||||
| 20 | 2013 | return nfreeze($entry); | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | sub deserialize { | ||||||||||
| 24 | 8518 | ▶ | my ( $self, $blob ) = @_; | ||||||||
|
Subroutine
deserialize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 25 | |||||||||||
| 26 | 8518 | return thaw($blob); | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | sub serialize_to_stream { | ||||||||||
| 30 | 3 | ▶ | my ( $self, $fh, $entry ) = @_; | ||||||||
|
Subroutine
serialize_to_stream: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 31 | 3 | nstore_fd($entry, $fh); | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | sub deserialize_from_stream { | ||||||||||
| 35 | 4 | ▶ | my ( $self, $fh ) = @_; | ||||||||
|
Subroutine
deserialize_from_stream: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 36 | |||||||||||
| 37 | 4 | ▶ | if ( $fh->eof ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 1 | return; | |||||||||
| 39 | } else { | ||||||||||
| 40 | 3 | return fd_retrieve($fh); | |||||||||
| 41 | } | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 20 | __PACKAGE__ | |||||||||
| 45 | |||||||||||
| 46 | __END__ | ||||||||||
| 47 | |||||||||||
| 48 | =pod | ||||||||||
| 49 | |||||||||||
| 50 | =head1 NAME | ||||||||||
| 51 | |||||||||||
| 52 | KiokuDB::Backend::Serialize::Storable - L<Storable> based serialization of | ||||||||||
| 53 | L<KiokuDB::Entry> objects. | ||||||||||
| 54 | |||||||||||
| 55 | =head1 SYNOPSIS | ||||||||||
| 56 | |||||||||||
| 57 | package MyBackend; | ||||||||||
| 58 | |||||||||||
| 59 | with qw(KiokuDB::Backend::Serialize::Storable; | ||||||||||
| 60 | |||||||||||
| 61 | =head1 DESCRIPTION | ||||||||||
| 62 | |||||||||||
| 63 | This role provides L<Storable> based serialization of L<KiokuDB::Entry> objects | ||||||||||
| 64 | for a backend, with streaming capabilities. | ||||||||||
| 65 | |||||||||||
| 66 | L<KiokuDB::Backend::Serialize::Delegate> is preferred to using this directly. | ||||||||||
| 67 | |||||||||||
| 68 | =head1 METHODS | ||||||||||
| 69 | |||||||||||
| 70 | =over 4 | ||||||||||
| 71 | |||||||||||
| 72 | =item serialize $entry | ||||||||||
| 73 | |||||||||||
| 74 | Uses L<Storable/nstore> | ||||||||||
| 75 | |||||||||||
| 76 | =item deserialize $blob | ||||||||||
| 77 | |||||||||||
| 78 | Uses L<Storable/thaw> | ||||||||||
| 79 | |||||||||||
| 80 | =item serialize_to_stream $fh, $entry | ||||||||||
| 81 | |||||||||||
| 82 | Uses L<Storable/nstore_fd>. | ||||||||||
| 83 | |||||||||||
| 84 | =item deserialize_from_stream $fh | ||||||||||
| 85 | |||||||||||
| 86 | Uses L<Storable/fd_retrieve>. | ||||||||||
| 87 | |||||||||||
| 88 | =back | ||||||||||