File Coverage

blib/lib/KiokuDB/TypeMap/Default/Canonical.pm
Criterion Covered Total %
statement 14 16 87.5
branch n/a
condition n/a
subroutine 6 7 85.7
pod n/a
total 20 23 86.9


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package KiokuDB::TypeMap::Default::Canonical;
4 7     7   3568 use Moose::Role;
  7         11  
  7         81  
5              
6 7     7   28758 use namespace::clean -except => 'meta';
  7         14  
  7         136  
7              
8             with qw(KiokuDB::TypeMap::Default);
9              
10             sub _build_path_class_typemap {
11 17     17   1199 my $self = shift;
12              
13 17         156 $self->_create_typemap(
14             isa_entries => {
15             'Path::Class::Entity' => {
16             type => "KiokuDB::TypeMap::Entry::Callback",
17             intrinsic => 1,
18             collapse => "stringify",
19             expand => "new",
20             },
21             },
22             );
23             }
24              
25             sub _build_uri_typemap {
26 17     17   1213 my $self = shift;
27              
28 17         192 $self->_create_typemap(
29             isa_entries => {
30             'URI' => {
31             type => "KiokuDB::TypeMap::Entry::Callback",
32             intrinsic => 1,
33             collapse => 'as_string',
34             expand => "new",
35             },
36             },
37             entries => {
38             'URI::WithBase' => {
39             type => "KiokuDB::TypeMap::Entry::Naive",
40             intrinsic => 1,
41             },
42             },
43             );
44             }
45              
46             sub _build_datetime_typemap {
47 17     17   1191 my $self = shift;
48              
49             $self->_create_typemap(
50             isa_entries => {
51             'DateTime' => => {
52             type => 'KiokuDB::TypeMap::Entry::Callback',
53             collapse => "epoch",
54             expand => sub {
55 0     0   0 my ( $class, $epoch ) = @_;
56 0         0 $class->from_epoch( epoch => $epoch );
57             },
58 17         246 intrinsic => 1,
59             },
60             'DateTime::Duration' => => {
61             type => 'KiokuDB::TypeMap::Entry::Naive',
62             intrinsic => 1,
63             },
64             },
65             );
66             }
67              
68             sub _build_authen_passphrase_typemap {
69 17     17   1604 my $self = shift;
70              
71 17         158 $self->_create_typemap(
72             isa_entries => {
73             'Authen::Passphrase' => {
74             type => "KiokuDB::TypeMap::Entry::Callback",
75             intrinsic => 1,
76             collapse => "as_rfc2307",
77             expand => "from_rfc2307",
78             },
79             },
80             );
81             }
82              
83             __PACKAGE__
84              
85             __END__
86              
87             =pod
88              
89             =head1 NAME
90              
91             KiokuDB::TypeMap::Default::Canonical - A L<KiokuDB::TypeMap::Default>
92             implementation that canonicalizes the standard types to simplified versions.
93              
94             =head1 DESCRIPTION
95              
96             This typemap is suitable for serialization using L<JSON>. It stringifies or
97             otherwise converts data structures into primitive representations.