File Coverage

blib/lib/DBIx/NoSQL/Model/Field.pm
Criterion Covered Total %
statement 25 25 100.0
branch 3 4 75.0
condition 1 2 50.0
subroutine 5 5 100.0
pod 0 2 0.0
total 34 38 89.4


line stmt bran cond sub pod time code
1             package DBIx::NoSQL::Model::Field;
2             our $AUTHORITY = 'cpan:YANICK';
3             $DBIx::NoSQL::Model::Field::VERSION = '0.0021';
4 5     5   21 use strict;
  5         7  
  5         138  
5 5     5   204 use warnings;
  5         8  
  5         138  
6              
7 5     5   18 use Moose;
  5         7  
  5         38  
8              
9             has name => qw/ is ro required 1 /;
10              
11             has index => qw/ is rw /;
12             has type => qw/ is rw /;
13              
14             sub setup {
15 14     14 0 17 my $self = shift;
16 14         16 my $model = shift;
17              
18 14         28 my %given = @_;
19              
20 14   50     355 exists $given{ $_ } && $self->$_( $given{ $_ } ) for qw/ index /;
21 14 100       34 if ( my $type_name = $given{ isa } ) {
22 2         48 $self->type( $type_name );
23 2 50       46 if ( my $type = $model->store->type_map->type( $type_name ) ) {
24 2         7 $model->_field2inflate_map->{ $self->name } = $type->inflator;
25 2         10 $model->_field2deflate_map->{ $self->name } = $type->deflator;
26             }
27             }
28              
29 14         32 return $self;
30             }
31              
32             sub install_index {
33 14     14 0 20 my $self = shift;
34 14         18 my $model = shift;
35 14         15 my $result_class = shift;
36              
37 14         311 my $column = $self->name;
38              
39 14         312 $model->_field2column_map->{ $self->name } = $column;
40              
41 14         134 $result_class->add_column( $column => {
42             data_type => 'text',
43             is_nullable => 1,
44             } );
45             }
46              
47             1;
48              
49             __END__
50              
51             =pod
52              
53             =encoding UTF-8
54              
55             =head1 NAME
56              
57             DBIx::NoSQL::Model::Field
58              
59             =head1 VERSION
60              
61             version 0.0021
62              
63             =head1 AUTHORS
64              
65             =over 4
66              
67             =item *
68              
69             Robert Krimen <robertkrimen@gmail.com>
70              
71             =item *
72              
73             Yanick Champoux <yanick@cpan.org>
74              
75             =back
76              
77             =head1 COPYRIGHT AND LICENSE
78              
79             This software is copyright (c) 2017 by Robert Krimen.
80              
81             This is free software; you can redistribute it and/or modify it under
82             the same terms as the Perl 5 programming language system itself.
83              
84             =cut