File Coverage

blib/lib/Finance/TW/TAIFEX/Contract.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 2 4 50.0
total 26 28 92.8


line stmt bran cond sub pod time code
1             package Finance::TW::TAIFEX::Contract;
2 4     4   26 use strict;
  4         8  
  4         143  
3 4     4   22 use Any::Moose;
  4         7  
  4         32  
4              
5             =head1 NAME
6              
7             Finance::TW::TAIFEX::Contract - Contract traded on TAIFEX
8              
9             =head1 METHODS
10              
11             =cut
12              
13             has year => (is => "ro", isa => "Int", required => 1);
14             has month => (is => "ro", isa => "Int", required => 1);
15             has product => (is => "ro", isa => "Finance::TW::TAIFEX::Product",
16             handles => [qw(name exchange find_settlement_day)],
17             );
18              
19             =head2 is_settlement_day DATE
20              
21             Check if DATE is a settlement day
22              
23             =cut
24              
25             sub is_settlement_day {
26 1     1 1 749 my ($self, $date) = @_;
27 1         6 return $date->ymd eq $self->settlement_day->ymd
28             }
29              
30             =head2 settlement_day
31              
32             Returns the settlement day of the contract.
33              
34             =cut
35              
36             sub settlement_day {
37 2     2 1 486 my $self = shift;
38              
39 2         19 $self->find_settlement_day(
40             DateTime->new( year => $self->year, month => $self->month, day => 1)
41             );
42             }
43              
44              
45             my $local_month_code = ['A'..'L'];
46             sub encode_local {
47 1     1 0 4 my $self = shift;
48 1         16 return $local_month_code->[$self->month-1].substr($self->year, -1, 1);
49             }
50              
51             my $month_code = [qw(F G H J K M N Q U V X Z)];
52             sub encode {
53 1     1 0 424 my $self = shift;
54 1         16 return $month_code->[$self->month-1].substr($self->year, -1, 1);
55             }
56              
57             __PACKAGE__->meta->make_immutable;
58 4     4   3519 no Any::Moose;
  4         7  
  4         23  
59             1;
60