TAIFEX/Product.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 42 CC 2 SCAR 11.0
CC
2
Cov
0%
_near_term
6.0
near_term
2.0
near_term_contract
2.0
CRAP 3.0
1 package Finance::TW::TAIFEX::Product;
2 use strict;
3 use Any::Moose;
4  
5 =head1 NAME
6  
7 Finance::TW::TAIFEX::Contract - Product on TAIFEX
8  
9 =head1 METHODS
10  
11 =cut
12  
13 with any_moose('X::Traits');
14  
15 has name => (is => "ro", isa => "Str");
16  
17 has exchange => (is => "ro", isa => "Finance::TW::TAIFEX");
18  
19 has '+_trait_namespace' => ( default => 'Finance::TW::TAIFEX' );
20  
21 sub _near_term {
22 my ($self, $date) = @_;
23 my $settlement = $self->find_settlement_day($date);
24 if ( $date->day > $settlement->day ) {
25 $settlement = $settlement->add( months => 1);
26 }
27 return $settlement;
28 }
29  
30 =head2 near_term DATE
31  
32 Returns the near term contract of the product at DATE in YYYYMM format.
33  
34 =cut
35  
36 sub near_term {
37 my ($self, $date) = @_;
38 return $self->_near_term($date)->strftime('%Y%m');
39 }
40  
41 =head2 near_term_contract DATE
42  
43 Returns the near term contract object for product at DATE.
44  
45 =cut
46  
47 sub near_term_contract {
48 my ($self, $date) = @_;
49 my $near_term = $self->_near_term($date);
50 return Finance::TW::TAIFEX::Contract->new(
51 product => $self,
52 year => $near_term->year,
53 month => $near_term->month);
54 }
55  
56 =head2 find_settlement_day DATE
57  
58 Find the settlement day of the near term contract at DATE.
59  
60 =cut
61  
62 sub find_settlement_day {
63 my ($self, $date) = @_;
64 my $settlement = $self->default_settlement_day($date);
65  
66 while (!$self->exchange->is_trading_day($settlement)) {
67 $settlement->add( days => 1 );
68 }
69  
70 return $settlement
71 }
72  
73 __PACKAGE__->meta->make_immutable;
74 no Any::Moose;
75 1;