File Coverage

blib/lib/DBIx/NoSQL/TypeMap.pm
Criterion Covered Total %
statement 28 28 100.0
branch 1 2 50.0
condition n/a
subroutine 13 13 100.0
pod 0 7 0.0
total 42 50 84.0


line stmt bran cond sub pod time code
1             package DBIx::NoSQL::TypeMap;
2             our $AUTHORITY = 'cpan:YANICK';
3             $DBIx::NoSQL::TypeMap::VERSION = '0.0021';
4 3     3   81749 use strict;
  3         5  
  3         84  
5 3     3   11 use warnings;
  3         3  
  3         72  
6              
7 3     3   458 use Moose;
  3         293931  
  3         21  
8              
9             has _map => qw/ is ro isa HashRef /, default => sub { {} };
10              
11             sub BUILD {
12 3     3 0 2060 my $self = shift;
13              
14             $self->create( 'DateTime',
15 3     3   22 inflate => sub { return DateTime->from_epoch( epoch => $_[0] ) },
16 3     3   16 deflate => sub { return $_[0]->epoch },
17 3         25 );
18             }
19              
20             sub type {
21 3     3 0 11 my $self = shift;
22 3         5 my $name = shift;
23              
24 3         65 return $self->_map->{ $name };
25             }
26              
27             #has _cache => qw/ is rw isa HashRef /, default => sub { {} };
28             #sub find {
29             #my $self = shift;
30             #my $package = shift;
31              
32             #my $type;
33             #my $cache = $self->_cache;
34             #while( ! $type ) {
35             #}
36             #}
37              
38             sub create {
39 3     3 0 5 my $self = shift;
40 3         6 my $name = shift;
41              
42 3 50       83 die "Already have type ($name)" if $self->_map->{ $name };
43              
44 3         23 my $type = $self->_map->{ $name } = DBIx::NoSQL::TypeMap::Type->new( name => $name, @_ );
45 3         11 return $type;
46             }
47              
48             package DBIx::NoSQL::TypeMap::Type;
49             our $AUTHORITY = 'cpan:YANICK';
50             $DBIx::NoSQL::TypeMap::Type::VERSION = '0.0021';
51 3     3   15656 use Moose;
  3         3  
  3         10  
52              
53             has name => qw/ is ro required 1 isa Str /;
54              
55             has inflate => qw/ accessor _inflate isa Maybe[CodeRef] /;
56             has deflate => qw/ accessor _deflate isa Maybe[CodeRef] /;
57 2     2 0 53 sub inflator { return shift->_inflate( @_ ) }
58 2     2 0 70 sub deflator { return shift->_deflate( @_ ) }
59              
60 1     1 0 525 sub inflate { return $_[0]->_inflate->( $_[1] ) }
61 1     1 0 296 sub deflate { return $_[0]->_deflate->( $_[1] ) }
62              
63             1;
64              
65             __END__
66              
67             =pod
68              
69             =encoding UTF-8
70              
71             =head1 NAME
72              
73             DBIx::NoSQL::TypeMap
74              
75             =head1 VERSION
76              
77             version 0.0021
78              
79             =head1 AUTHORS
80              
81             =over 4
82              
83             =item *
84              
85             Robert Krimen <robertkrimen@gmail.com>
86              
87             =item *
88              
89             Yanick Champoux <yanick@cpan.org>
90              
91             =back
92              
93             =head1 COPYRIGHT AND LICENSE
94              
95             This software is copyright (c) 2017 by Robert Krimen.
96              
97             This is free software; you can redistribute it and/or modify it under
98             the same terms as the Perl 5 programming language system itself.
99              
100             =cut