StockAccount/Acquisition.pm

filter: Statementstmt 92.7% 64 / 69 Branchbran 62.5% 5 / 8 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 13 totaltotal 71.4% 90 / 126 CC 9 SCAR 12.1
CC
9
Cov
82%
init
7.3
at
6.5
BEGIN
1.0
CRAP 3.3
« StockAccount/AccountTransaction.pm ↑ Summary
1 package Finance::StockAccount::Acquisition;
2  
3 8 our $VERSION = '0.01';
4  
5 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 ▶use Finance::StockAccount::AccountTransaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 1505 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 1505 my ($class, $at, $shares) = @_;
15 1505 my $self = {
16 at => undef,
17 shares => 0,
18 cashEffect => 0,
19 commission => 0,
20 regulatoryFees => 0,
21 otherFees => 0,
22 };
23 1505 bless($self, $class);
24 1505 $self->init($at, $shares);
25 1505 return $self;
26 }
27  
28 3010 ▶sub at {
Subroutine at: called CC=5 SCAR=18.7
Pod undocumented
29 3010 my ($self, $at) = @_;
30 3010 ▶ if ($at) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at) { } 1505 1505 3010
31 1505 ▶ if (ref($at) and ($at->buy() or $at->short())) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $at and $at->buy || $at->short) { } 1505 0 1505
Condition33%2/6
ref $at and $at->buy || $at->short
!ll&&!rl&&r
001505
$at->buy or $at->short
l!l&&r!l&&!r
150500
MC/DC0%0/3
ref $at and $at->buy || $at->short
ref $at $at->buy $at->short
Truth table25%1/4
A and B or C
A= ref $atB= $at->buyC= $at->short
ABCresult
0XX0
1000
11X1
1011
32 1505 $self->{at} = $at;
33 1505 return 1;
34 }
35 else {
36 0 confess "Acquisition requires a valid AccountTransaction object of type buy or short.";
37 0 return 0;
38 }
39 }
40 else {
41 1505 return $self->{at};
42 }
43 }
44  
45 2150 ▶sub cashEffect { return shift->{cashEffect}; }
Subroutine cashEffect: called CC=1 SCAR=0.0
Pod undocumented
46 1505 ▶sub commission { return shift->{commission}; }
Subroutine commission: called CC=1 SCAR=0.0
Pod undocumented
47 1504 ▶sub regulatoryFees { return shift->{regulatoryFees}; }
Subroutine regulatoryFees: called CC=1 SCAR=0.0
Pod undocumented
48 1504 ▶sub otherFees { return shift->{otherFees}; }
Subroutine otherFees: called CC=1 SCAR=0.0
Pod undocumented
49 1504 ▶sub shares { return shift->{shares}; }
Subroutine shares: called CC=1 SCAR=0.0
Pod undocumented
50  
51 7891 ▶sub tm {
Subroutine tm: called CC=1 SCAR=0.0
Pod undocumented
52 7891 my $self = shift;
53 7891 my $at = $self->{at};
54 7891 return $at->tm();
55 }
56  
57 1505 ▶sub proportion {
Subroutine proportion: called CC=1 SCAR=0.0
Pod undocumented
58 1505 my $self = shift;
59 1505 my $shares = $self->{shares};
60 1505 my $at = $self->{at};
61 1505 my $quantity = $at->quantity();
62 1505 return $shares / $quantity;
63 }
64  
65 1505 ▶sub compute {
Subroutine compute: called CC=1 SCAR=0.0
Pod undocumented
66 1505 my $self = shift;
67 1505 my $proportion = $self->proportion();
68 1505 my $at = $self->at();
69 1505 $self->{cashEffect} = $at->cashEffect() * $proportion;
70 1505 $self->{commission} = $at->commission() * $proportion;
71 1505 $self->{regulatoryFees} = $at->regulatoryFees() * $proportion;
72 1505 $self->{otherFees} = $at->otherFees() * $proportion;
73 1505 return 1;
74 }
75  
76 1505 ▶sub init {
Subroutine init: called CC=5 SCAR=19.8
Pod undocumented
77 1505 my ($self, $at, $shares) = @_;
78 1505 ▶ if (!($at and $shares)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($at and $shares) 0 1505 1505
Condition33%1/3
$at and $shares
!ll&&!rl&&r
001505
MC/DC0%0/2
$at and $shares
$at $shares
Truth table33%1/3
A and B
A= $atB= $shares
ABresult
0X0
100
111
79 0 confess "Acquisition->new constructor requires \$at (AccountTransaction) and shares count parameters.\n";
80 }
81 1505 ▶ if ($shares =~ /^[0-9]+$/ and $shares > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shares =~ /^[0-9]+$/ and $shares > 0) { } 1505 0 1505
Condition33%1/3
$shares =~ /^[0-9]+$/ and $shares > 0
!ll&&!rl&&r
001505
MC/DC0%0/2
$shares =~ /^[0-9]+$/ and $shares > 0
$shares =~ /^[0-9]+$/ $shares > 0
Truth table33%1/3
A and B
A= $shares =~ /^[0-9]+$/B= $shares > 0
ABresult
0X0
100
111
82 1505 $self->at($at);
83 1505 $self->{shares} = $shares;
84 1505 $self->compute();
85 1505 return 1;
86 }
87 else {
88 0 confess "Acquisition::Init requires numeric positive shares value, got $shares.\n";
89 0 return 0;
90 }
91 }
92  
93 93 ▶sub lineFormatValues {
Subroutine lineFormatValues: called CC=1 SCAR=0.0
Pod undocumented
94 93 my $self = shift;
95 93 my $at = $self->{at};
96 93 my $lineFormatValues = $at->lineFormatValues();
97 93 $lineFormatValues->[3] = $self->{shares};
98 93 $lineFormatValues->[5] = $self->{commission};
99 93 $lineFormatValues->[6] = $self->{regulatoryFees} + $self->{otherFees};
100 93 $lineFormatValues->[7] = $self->{cashEffect};
101 93 return $lineFormatValues;
102 }
103  
104 93 ▶sub lineFormatString {
Subroutine lineFormatString: called CC=1 SCAR=0.0
Pod undocumented
105 93 my $self = shift;
106 93 return sprintf(Finance::StockAccount::Transaction->lineFormatPattern(), @{$self->lineFormatValues()});
107 }
108  
109  
110  
111  
112 8 1;
« StockAccount/AccountTransaction.pm ↑ Summary