File Coverage

blib/lib/PGObject/Type/DateTime/Infinite.pm
Criterion Covered Total %
statement 35 35 100.0
branch n/a
condition 2 4 50.0
subroutine 13 13 100.0
pod n/a
total 50 52 96.1


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             PGObject::Util::Type::DateTime::Infinite -- Infinite Date Times in PGObject
4              
5             =head1 VERSION
6              
7             2.1.1
8              
9             =head1 SYNOPSIS
10              
11             # for a timestamp infinitely far in the future
12             my $future = PGObject::Util::Type::DateTime::Infinite::Future->new
13              
14             # or infinitely far in the past
15              
16             my $past = PGObject::Util::Type::DateTime::Infinite::Past->new
17              
18             =cut
19              
20             # This package doesn't do anything, just there for loading
21             # and to make sure other modules are loaded since the modules
22             # we subclass are found in DateTime::Infinite's perl module
23              
24             package PGObject::Util::Type::DateTime::Infinite;
25 6     6   47 use DateTime::Infinite; # loads the classes we will be using.
  6         13  
  6         291  
26 6     6   38 use strict;
  6         14  
  6         170  
27 6     6   28 use warnings;
  6         11  
  6         644  
28              
29             =head1 DESCRIPTION
30              
31             PostgreSQL supports timestamps of 'infinity' (can also be written '+infinity')
32             and '-infinity' and it turns out Perl has support for the same. So this module
33             implements a bridge between PGObject and this functionality.
34              
35             =head1 SUBCLASSES
36              
37             This module offers two subclasses for future and past.
38              
39             =head2 PGObject::Util::Type::DateTime::Infinite::Future
40              
41             This class +infinity and infinity to DateTime::Infinite::Future objects
42              
43             =head2 PGObject::Util::Type::DateTime::Infinite::Past
44              
45             This class maps -infinity to DateTime::Infinite::Past objects.
46              
47             =cut
48              
49             package PGObject::Type::DateTime::Infinite::Future;
50 6     6   38 use parent -norequire, qw(DateTime::Infinite::Future PGObject::Type::DateTime);
  6         12  
  6         58  
51 6     6   398 use strict;
  6         28  
  6         140  
52 6     6   28 use warnings;
  6         35  
  6         916  
53              
54             sub new {
55 2     2   6 my $class = shift;
56 2         21 my $val = DateTime::Infinite::Future->new;
57 2   50     24 bless $val, ($class // __PACKAGE__);
58             }
59              
60 2     2   3039 sub to_db { 'infinity' }
61              
62             package PGObject::Type::DateTime::Infinite::Past;
63 6     6   39 use parent -norequire, qw(DateTime::Infinite::Past PGObject::Type::DateTime);
  6         30  
  6         39  
64 6     6   356 use strict;
  6         33  
  6         187  
65 6     6   37 use warnings;
  6         17  
  6         712  
66              
67             sub new {
68 2     2   6 my $class = shift;
69 2         16 my $val = DateTime::Infinite::Past->new;
70 2   50     19 bless $val, ($class // __PACKAGE__);
71             }
72              
73 2     2   3073 sub to_db { '-infinity' }
74              
75             =head1 SEE ALSO
76              
77             =over
78              
79             =item DateTime::Infinite
80              
81             =item DateTime
82              
83             =item PGObject::Type::DateTime
84              
85             =back
86              
87             =head1 COPYING
88              
89             See the terms of PGObject::Type::DateTime for the license agreement as this
90             is part of that package.
91              
92             =cut
93              
94             1;
95