File Coverage

blib/lib/DBIx/Class/Schema/PopulateMore/Inflator/Date.pm
Criterion Covered Total %
statement 9 10 90.0
branch 1 2 50.0
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 14 16 87.5


line stmt bran cond sub pod time code
1             package DBIx::Class::Schema::PopulateMore::Inflator::Date;
2              
3 3     3   3987 use Moo;
  3         5  
  3         19  
4 3     3   2691 use DateTimeX::Easy;
  3         790724  
  3         874  
5             extends 'DBIx::Class::Schema::PopulateMore::Inflator';
6              
7             =head1 NAME
8              
9             DBIx::Class::Schema::PopulateMore::Inflator::Date - Returns A L<DateTime> object
10              
11             =head1 DESCRIPTION
12              
13             Sometimes you need to put dates into your table rows, but this can be a big
14             hassle to do, particularly in a crossplatform way. This plugin will assist
15             in this. It also makes it easy to insert relative date/times. such as 'now',
16             'last week', etc. See L<DateTimeX::Easy> for more information on how we
17             coerce dates.
18              
19             =head1 ATTRIBUTES
20              
21             This class defines the following attributes.
22              
23             =head1 METHODS
24              
25             This module defines the following methods.
26              
27             =head2 inflate($command, $string)
28              
29             This is called by Populate's dispatcher, when there is a match.
30              
31             =cut
32              
33             sub inflate
34             {
35 4     4 1 10 my ($self, $command, $string) = @_;
36            
37 4 50       36 if(my $dt = DateTimeX::Easy->new($string, default_time_zone=>'UTC'))
38             {
39 4         49184 return $dt;
40             }
41             else
42             {
43 0           $command->exception_cb->("Couldn't deal with $string as a date");
44             }
45              
46             }
47              
48             =head1 AUTHOR
49              
50             Please see L<DBIx::Class::Schema::PopulateMore> For authorship information
51              
52             =head1 LICENSE
53              
54             Please see L<DBIx::Class::Schema::PopulateMore> For licensing terms.
55              
56             =cut
57              
58              
59             1;