Framework/Spot/Tick.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 35 CC 3 SCAR 18.4
CC
3
Cov
0%
invert_values
12.0
close
2.0
as_hash
2.0
CRAP 6.3
1 package Quant::Framework::Spot::Tick;
2  
3 =head1 NAME
4  
5 Quant::Framework::Spot::Tick
6  
7 =head1 SYNOPSYS
8  
9 my $tick = Quant::Framework::Spot::Tick->new({
10 symbol => 'frxRMBMNT',
11 epoch => 1340871449,
12 bid => 2.01,
13 ask => 2.03,
14 quote => 2.02,
15 });
16  
17 =head1 DESCRIPTION
18  
19 This class represents tick data
20  
21 =head1 ATTRIBUTES
22  
23 =cut
24  
25 use Moose;
26 use namespace::autoclean;
27  
28 =head2 epoch
29  
30 represent time in epoch of a tick
31  
32 =cut
33  
34 has 'epoch' => (
35 is => 'ro',
36 required => 1,
37 );
38  
39 =head2 symbol
40  
41 underlying symbol
42  
43 =cut
44  
45 has 'symbol' => (
46 is => 'ro',
47 );
48  
49 =head2 quote
50  
51 represents the quote price
52  
53 =cut
54  
55 has quote => (
56 is => 'rw',
57 required => 1,
58 );
59  
60 =head2 bid
61  
62 represents the bid price
63  
64 =head2 ask
65  
66 represents the ask price
67  
68 =cut
69  
70 has [qw(bid ask)] => (
71 is => 'rw',
72 );
73  
74 =head1 METHIODS
75  
76 =cut
77  
78 =head2 $self->close
79  
80 Returns quote, for backward compatibility
81  
82 =cut
83  
84 ## no critic (ProhibitBuiltinHomonyms)
85 sub close { return shift->quote; }
86  
87 =head2 $self->invert_values
88  
89 Invert quote, ask, and bid values
90  
91 =cut
92  
93 sub invert_values {
94 my $self = shift;
95  
96 $self->quote(1 / $self->quote);
97 $self->bid(1 / $self->bid) if $self->bid;
98 $self->ask(1 / $self->ask) if $self->ask;
99  
100 return $self;
101 }
102  
103 =head2 $self->as_hash
104  
105 Returns tick as a hash
106  
107 =cut
108  
109 sub as_hash {
110 my $self = shift;
111  
112 return +{map { $_ => $self->$_ } grep { defined $self->$_ } qw(epoch quote symbol bid ask)};
113 }
114  
115 __PACKAGE__->meta->make_immutable;
116  
117 1;
118  
119