StockAccount/Import.pm

filter: Statementstmt 47.2% 26 / 55 Branchbran 11.5% 3 / 26 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 7 totaltotal 37.8% 39 / 103 CC 15 SCAR 35.1
CC
15
Cov
37%
renameMe
90.0
extractPrice
6.0
extractCommission
6.0
CRAP 33.3
↑ Summary StockAccount.pm »
1 package Finance::StockAccount::Import;
2  
3 3 our $VERSION = '0.01';
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Finance::StockAccount;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Finance::StockAccount::AccountTransaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
14 8 my ($class, $file, $tzoffset) = @_;
15 8 ▶ $file or confess "Please pass a file to import.\n";
Branch: 1 branch
BranchTrueFalseTotal
$file or confess("Please pass a file to import.\n") 8 0 8
16 8 ▶ my $self = {
Condition100%2/2
$tzoffset || 0
l!l
71
MC/DC100%1/1
$tzoffset || 0
$tzoffset
Truth table100%2/2
A
A= $tzoffset
Aresult
11
00
17 file => $file,
18 fh => undef,
19 headers => undef,
20 tzoffset => $tzoffset || 0,
21 };
22 8 return bless($self, $class);
23 }
24  
25 0 ▶sub renameMe {
Subroutine renameMe: not called CC=9 SCAR=45.0
Pod undocumented
26 0 my ($self, $key, $value) = @_;
27 0 ▶ if ($key eq 'date') {
Branch: 4 branches
BranchTrueFalseTotal
if ($key eq 'date') { } 0 0 0
elsif ($key eq 'price') { } 0 0 0
elsif ($key eq 'commission') { } 0 0 0
elsif ($key eq 'symbol') { } 0 0 0
28 0 ▶ $self->extractDate($value) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->extractDate($value) or return 0 0 0 0
29 }
30 elsif ($key eq 'price') {
31 0 ▶ $self->extractPrice($value) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->extractPrice($value) or return 0 0 0 0
32 }
33 elsif ($key eq 'commission') {
34 0 ▶ $self->extractCommission($value) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->extractCommission($value) or return 0 0 0 0
35 }
36 elsif ($key eq 'symbol') {
37 0 ▶ $self->extractSymbol($value) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->extractSymbol($value) or return 0 0 0 0
38 }
39 }
40  
41 0 ▶sub extractPrice {
Subroutine extractPrice: not called CC=2 SCAR=17.9
Pod undocumented
42 0 my ($self, $priceString) = @_;
43 0 my $pricePattern = '';
44 0 ▶ if ($priceString =~ /$pricePattern/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($priceString =~ /$pricePattern/) { } 0 0 0
45 0 my $price = $1;
46 0 $price =~ s/,//g;
47 0 $self->{price} = $price;
48 }
49 else {
50 0 warn "Failed to recognize price pattern in string $priceString.\n";
51 0 return 0;
52 }
53 }
54  
55 0 ▶sub extractCommission {
Subroutine extractCommission: not called CC=2 SCAR=17.9
Pod undocumented
56 0 my ($self, $commissionString) = @_;
57 0 my $pricePattern = '';
58 0 ▶ if ($commissionString =~ /$pricePattern/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($commissionString =~ /$pricePattern/) { } 0 0 0
59 0 my $commission = $1;
60 0 $commission =~ s/,//g;
61 0 $self->{commission} = $commission;
62 }
63 else {
64 0 warn "Failed to recognize commission pattern in string $commissionString.\n";
65 0 return 0;
66 }
67 }
68  
69 0 ▶sub extractSymbol {
Subroutine extractSymbol: not called CC=2 SCAR=17.9
Pod undocumented
70 0 my ($self, $symbolString) = @_;
71 0 my $symbolPattern = '';
72 0 ▶ if ($symbolString =~ /$symbolPattern/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbolString =~ /$symbolPattern/) { } 0 0 0
73 0 $self->{symbol} = $1;
74 }
75 else {
76 0 warn "Failed to recognize symbol pattern in string $symbolString.\n";
77 0 return 0;
78 }
79 }
80  
81 0 ▶sub nextAt {
Subroutine nextAt: not called CC=1 SCAR=6.9
Pod undocumented
82 # method that returns the next AccountTransaction object,
83 # to be overridden by child classes
84 0 return 0;
85 }
86  
87 7 ▶sub stockAccount {
Subroutine stockAccount: called CC=2 SCAR=6.9
Pod undocumented
88 7 my $self = shift;
89 7 my $sa = Finance::StockAccount->new();
90 7 ▶ while (my $at = $self->nextAt()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $at = $self->nextAt) 238 7 245
91 238 $sa->addToSet($at);
92 }
93 7 return $sa;
94 }
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106 3 1;
↑ Summary StockAccount.pm »