| 1 | #!/usr/bin/perl | ||||||||||
| 2 | |||||||||||
| 3 | package KiokuDB::Serializer; | ||||||||||
| 4 | 22 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 22 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 22 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 22 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 22 | with qw(KiokuDB::Backend::Serialize); | |||||||||
| 13 | |||||||||||
| 14 | 22 | requires "serialize_to_stream"; | |||||||||
| 15 | 22 | requires "deserialize_from_stream"; | |||||||||
| 16 | |||||||||||
| 17 | 22 | my %types = ( | |||||||||
| 18 | storable => "KiokuDB::Serializer::Storable", | ||||||||||
| 19 | json => "KiokuDB::Serializer::JSON", | ||||||||||
| 20 | yaml => "KiokuDB::Serializer::YAML", | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | coerce( __PACKAGE__, | ||||||||||
| 24 | from Str => via { | ||||||||||
| 25 | 0 | ▶ | my $class = $types{lc($_)} or croak "unknown format: $_";; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||
| 26 | 0 | Class::MOP::load_class($class); | |||||||||
| 27 | 0 | $class->new; | |||||||||
| 28 | }, | ||||||||||
| 29 | from HashRef => via { | ||||||||||
| 30 | 0 | ▶ | my %args = %$_; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 31 | 0 | ▶ | my $class = $types{lc(delete $args{format})} or croak "unknown format: $args{format}"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | Class::MOP::load_class($class); | |||||||||
| 33 | 0 | $class->new(%args); | |||||||||
| 34 | }, | ||||||||||
| 35 | 22 | ); | |||||||||
| 36 | |||||||||||
| 37 | 22 | __PACKAGE__ | |||||||||
| 38 | |||||||||||
| 39 | __END__ | ||||||||||
| 40 | |||||||||||
| 41 | =pod | ||||||||||
| 42 | |||||||||||
| 43 | =head1 NAME | ||||||||||
| 44 | |||||||||||
| 45 | KiokuDB::Serializer - Standalone serializer object | ||||||||||
| 46 | |||||||||||
| 47 | =head1 SYNOPSIS | ||||||||||
| 48 | |||||||||||
| 49 | Backend->new( | ||||||||||
| 50 | serializer => KiokuDB::Serializer::Storable->new( ... ), | ||||||||||
| 51 | ); | ||||||||||
| 52 | |||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||
| 54 | |||||||||||
| 55 | This role is for objects which perform the serialization roles (e.g. | ||||||||||
| 56 | L<KiokuDB::Backend::Serialize::Storable>) but can be used independently. | ||||||||||
| 57 | |||||||||||
| 58 | This is used by L<KiokuDB::Backend::Serialize::Delegate> and | ||||||||||
| 59 | L<KiokuDB::Cmd::DumpFormatter>. | ||||||||||