Framework/Utils/Types.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Framework/Utils/MarketData.pm ↑ Summary Framework/Utils/Test.pm »
1 package Quant::Framework::Utils::Types;
2  
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use MooseX::Types::Moose qw(Int Num Str);
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use Moose::Util::TypeConstraints;
8  
9 subtype 'qf_date_object', as 'Date::Utility';
10 coerce 'qf_date_object', from 'Str', via { Date::Utility->new($_) };
11  
12 =head2 qf_timestamp
13  
14 A valid ISO8601 timestamp, restricted specifically to the YYYY-MM-DDTHH:MI:SS format. Optionally, "Z", "UTC", or "GMT" can be appended to the end. No other time zones are supported.
15  
16 qf_timestamp can be coerced from C<Date::Utility>
17  
18 =cut
19  
20 subtype 'qf_timestamp', as Str, where {
21 if (/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|GMT|UTC)?$/) {
22 my $date = try {
23 DateTime->new(
24 year => $1,
25 month => $2,
26 day => $3,
27 hour => $4,
28 minute => $5,
29 second => $6,
30 time_zone => 'GMT'
31 );
32 };
33 return $date ? 1 : 0;
34 } else {
35 return 0;
36 }
37 }, message {
38 "Invalid timestamp $_, please use YYYY-MM-DDTHH:MM:SSZ format";
39 };
40  
41 coerce 'qf_timestamp', from 'qf_date_object', via { $_->datetime_iso8601 };
42  
43 my @interest_rate_types = qw(implied market);
44 subtype 'qf_interest_rate_type', as Str, where {
45 my $regex = '(' . join('|', @interest_rate_types) . ')';
46 /^$regex$/
47 }, message {
48 "Invalid interest_rate type $_. Must be one of: " . join(', ', @interest_rate_types)
49 };
50  
51 =head2 qf_surface_type
52  
53 Volatility surface types.
54  
55 =cut
56  
57 my @surface_types = qw( delta flat moneyness);
58 subtype 'qf_surface_type', as Str, where {
59 my $regex = '(' . join('|', @surface_types) . ')';
60 /^$regex$/;
61 }, message {
62 "Invalid surface type $_. Must be one of: " . join(', ', @surface_types);
63 };
64  
65 1;
« Framework/Utils/MarketData.pm ↑ Summary Framework/Utils/Test.pm »