File Coverage

blib/lib/DBIx/Class/InflateColumn/TimePiece.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 2 100.0
condition 8 8 100.0
subroutine 8 8 100.0
pod 1 1 100.0
total 42 42 100.0


line stmt bran cond sub pod time code
1             package DBIx::Class::InflateColumn::TimePiece;
2              
3             # ABSTRACT: Auto-create Time::Piece objects from integer columns
4 2     2   292225 use v5.10;
  2         13  
5              
6 2     2   10 use strict;
  2         5  
  2         30  
7 2     2   8 use warnings;
  2         4  
  2         50  
8              
9 2     2   10 use parent 'DBIx::Class';
  2         5  
  2         21  
10              
11 2     2   524 use Time::Piece;
  2         7855  
  2         13  
12              
13             our $VERSION = '0.02';
14              
15             sub register_column {
16 14     14 1 162053 my ($self, $column, $info, @rest) = @_;
17              
18 14         55 $self->next::method( $column, $info, @rest );
19              
20 14   100     5154 my $data_type = $info->{data_type} || '';
21 14   100     58 my $is_integer = $data_type eq 'integer' || $data_type eq 'int';
22              
23 14 100 100     64 return if !$info->{inflate_time_piece} || !$is_integer;
24              
25             $self->inflate_column(
26             $column => {
27             inflate => sub {
28 6     6   400414 my $dt = localtime shift;
29 6         252 return $dt;
30             },
31             deflate => sub {
32 6     6   399138 return shift->epoch;
33             },
34             }
35 4         64 );
36             }
37              
38             1;
39              
40             __END__