File Coverage

blib/lib/Business/Payment/Types.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Business::Payment::Types;
2 5     5   2293 use MooseX::Types;
  5         149483  
  5         17  
3              
4 5     5   12148 use MooseX::Types::Moose qw/Num Str/;
  5         49080  
  5         38  
5              
6 5     5   18944 use Math::Currency;
  5         313997  
  5         217  
7 5     5   3525 use DateTime;
  5         1537679  
  5         1154  
8              
9             class_type 'DateTime';
10             class_type 'Math::Currency';
11              
12             coerce 'Math::Currency',
13             from Num,
14             via { Math::Currency->new(@_) };
15              
16             coerce 'DateTime',
17             from Str,
18             via {
19             my ($date) = @_;
20             my ($m, $y); # Predeclare M and Y that we will use for DT
21             # Catch things in the form of MM/YY
22             if($date =~ /^(\d+)\/(\d+)$/) {
23             ($m, $y) = ($1,$2);
24             } else {
25             die "Expiration date must be in the form of MM/YY or MM/YYYY (not $date)";
26             }
27              
28             # Build a 4 digit year by prepending the first two digits of the
29             # current year.
30             if(length($y) == 2) {
31             my $now = DateTime->now;
32             $y = substr($now->year, 0, 2).$y;
33             }
34              
35             DateTime->new(month => $m, year => $y);
36             };
37              
38             1;