line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::StockAccount::Import; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
1110
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
89
|
|
6
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
67
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
10
|
use Carp; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
157
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
1068
|
use Finance::StockAccount; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
75
|
|
11
|
3
|
|
|
3
|
|
15
|
use Finance::StockAccount::AccountTransaction; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1171
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
8
|
|
|
8
|
0
|
11
|
my ($class, $file, $tzoffset) = @_; |
15
|
8
|
50
|
|
|
|
22
|
$file or confess "Please pass a file to import.\n"; |
16
|
8
|
|
100
|
|
|
36
|
my $self = { |
17
|
|
|
|
|
|
|
file => $file, |
18
|
|
|
|
|
|
|
fh => undef, |
19
|
|
|
|
|
|
|
headers => undef, |
20
|
|
|
|
|
|
|
tzoffset => $tzoffset || 0, |
21
|
|
|
|
|
|
|
}; |
22
|
8
|
|
|
|
|
27
|
return bless($self, $class); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub renameMe { |
26
|
0
|
|
|
0
|
0
|
0
|
my ($self, $key, $value) = @_; |
27
|
0
|
0
|
|
|
|
0
|
if ($key eq 'date') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
0
|
$self->extractDate($value) or return 0; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ($key eq 'price') { |
31
|
0
|
0
|
|
|
|
0
|
$self->extractPrice($value) or return 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif ($key eq 'commission') { |
34
|
0
|
0
|
|
|
|
0
|
$self->extractCommission($value) or return 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
elsif ($key eq 'symbol') { |
37
|
0
|
0
|
|
|
|
0
|
$self->extractSymbol($value) or return 0; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub extractPrice { |
42
|
0
|
|
|
0
|
0
|
0
|
my ($self, $priceString) = @_; |
43
|
0
|
|
|
|
|
0
|
my $pricePattern = ''; |
44
|
0
|
0
|
|
|
|
0
|
if ($priceString =~ /$pricePattern/) { |
45
|
0
|
|
|
|
|
0
|
my $price = $1; |
46
|
0
|
|
|
|
|
0
|
$price =~ s/,//g; |
47
|
0
|
|
|
|
|
0
|
$self->{price} = $price; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
0
|
|
|
|
|
0
|
warn "Failed to recognize price pattern in string $priceString.\n"; |
51
|
0
|
|
|
|
|
0
|
return 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub extractCommission { |
56
|
0
|
|
|
0
|
0
|
0
|
my ($self, $commissionString) = @_; |
57
|
0
|
|
|
|
|
0
|
my $pricePattern = ''; |
58
|
0
|
0
|
|
|
|
0
|
if ($commissionString =~ /$pricePattern/) { |
59
|
0
|
|
|
|
|
0
|
my $commission = $1; |
60
|
0
|
|
|
|
|
0
|
$commission =~ s/,//g; |
61
|
0
|
|
|
|
|
0
|
$self->{commission} = $commission; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
0
|
warn "Failed to recognize commission pattern in string $commissionString.\n"; |
65
|
0
|
|
|
|
|
0
|
return 0; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub extractSymbol { |
70
|
0
|
|
|
0
|
0
|
0
|
my ($self, $symbolString) = @_; |
71
|
0
|
|
|
|
|
0
|
my $symbolPattern = ''; |
72
|
0
|
0
|
|
|
|
0
|
if ($symbolString =~ /$symbolPattern/) { |
73
|
0
|
|
|
|
|
0
|
$self->{symbol} = $1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else { |
76
|
0
|
|
|
|
|
0
|
warn "Failed to recognize symbol pattern in string $symbolString.\n"; |
77
|
0
|
|
|
|
|
0
|
return 0; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub nextAt { |
82
|
|
|
|
|
|
|
# method that returns the next AccountTransaction object, |
83
|
|
|
|
|
|
|
# to be overridden by child classes |
84
|
0
|
|
|
0
|
0
|
0
|
return 0; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub stockAccount { |
88
|
7
|
|
|
7
|
0
|
18
|
my $self = shift; |
89
|
7
|
|
|
|
|
35
|
my $sa = Finance::StockAccount->new(); |
90
|
7
|
|
|
|
|
22
|
while (my $at = $self->nextAt()) { |
91
|
238
|
|
|
|
|
518
|
$sa->addToSet($at); |
92
|
|
|
|
|
|
|
} |
93
|
7
|
|
|
|
|
30
|
return $sa; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |