StockAccount/AccountTransaction.pm

filter: Statementstmt 82.6% 43 / 52 Branchbran 71.4% 10 / 14 Conditioncond 60.0% 9 / 15 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 9 totaltotal 68.8% 75 / 109 CC 13 SCAR 13.3
CC
13
Cov
77%
possiblePurchase
6.4
accountShares
6.4
accounted
2.3
CRAP 3.8
« StockAccount/Realization.pm ↑ Summary StockAccount/Acquisition.pm »
1 package Finance::StockAccount::AccountTransaction;
2  
3 9 our $VERSION = '0.01';
4  
5 9 ▶use parent 'Finance::StockAccount::Transaction';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 275 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
12 275 my ($class, $init) = @_;
13 275 my $self = $class->SUPER::new($init);
14 275 $self->{accounted} = 0;
15 275 return $self;
16 }
17  
18 2161 ▶sub accounted {
Subroutine accounted: called CC=2 SCAR=8.4
Pod undocumented
19 2161 my ($self, $accounted) = @_;
20 2161 ▶ if ($accounted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accounted) { } 0 2161 2161
21 0 $self->{accounted} = $accounted;
22 0 return 1;
23 }
24 else {
25 2161 return $self->{accounted};
26 }
27 }
28  
29 2615 ▶sub resetAccounted {
Subroutine resetAccounted: called CC=1 SCAR=0.0
Pod undocumented
30 2615 my $self = shift;
31 2615 $self->{accounted} = 0;
32 2615 return 1;
33 }
34  
35 11809 ▶sub available {
Subroutine available: called CC=2 SCAR=6.9
Pod undocumented
36 11809 my $self = shift;
37 11809 my $available = $self->{quantity} - $self->{accounted};
38 11809 ▶ return ($available > 0 ? $available : 0);
Branch: 1 branch
BranchTrueFalseTotal
$available > 0 ? : 8138 3671 11809
39 }
40  
41 3001 ▶sub accountShares {
Subroutine accountShares: called CC=5 SCAR=18.5
Pod undocumented
42 3001 my ($self, $shares) = @_;
43 3001 ▶ unless ($shares and $shares > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($shares and $shares > 0) 0 3001 3001
Condition33%1/3
$shares and $shares > 0
!ll&&!rl&&r
003001
MC/DC0%0/2
$shares and $shares > 0
$shares $shares > 0
Truth table33%1/3
A and B
A= $sharesB= $shares > 0
ABresult
0X0
100
111
44 0 warn "AccountShares of $shares bad input.\n";
45 0 return 0;
46 }
47 3001 my $available = $self->available();
48 3001 ▶ if (0 == $available) {
Branch: 2 branches
BranchTrueFalseTotal
if (0 == $available) { } 0 3001 3001
elsif ($shares > $available) { } 644 2357 3001
49 0 warn "Requested accountShares but no shares available.\n";
50 0 return 0;
51 }
52 elsif ($shares > $available) {
53 644 $self->{accounted} = $self->{quantity};
54 644 return $available;
55 }
56 else {
57 2357 $self->{accounted} += $shares;
58 2357 return $shares;
59 }
60 }
61  
62 9475 ▶sub possiblePurchase {
Subroutine possiblePurchase: called CC=6 SCAR=18.6
Pod undocumented
63 9475 my ($self, $actionString) = @_;
64 9475 ▶ if ( (($actionString eq 'sell' and $self->buy()) or
Branch: 1 branch
BranchTrueFalseTotal
if ($actionString eq 'sell' && $self->buy || $actionString eq 'cover' && $self->short and $self->available) { } 2631 6844 9475
Condition66%8/12
$actionString eq "sell" && $self->buy || $actionString eq "cover" && $self->short and $self->available
!ll&&!rl&&r
356732772631
$actionString eq "sell" and $self->buy or $actionString eq "cover" and $self->short
l!l&&r!l&&!r
590803567
$actionString eq "sell" and $self->buy
!ll&&!rl&&r
035675908
$actionString eq "cover" and $self->short
!ll&&!rl&&r
356700
MC/DC40%2/5
$actionString eq "sell" && $self->buy || $actionString eq "cover" && $self->short and $self->available
$actionString eq "sell" $self->buy $actionString eq "cover" $self->short $self->available
Truth table30%3/10
A and B or C and D and E
A= $actionString eq "sell"B= $self->buyC= $actionString eq "cover"D= $self->shortE= $self->available
ABCDEresult
0X0XX0
0X10X0
100XX0
1010X0
11XX00
0X1100
101100
11XX11
0X1111
101111
65 ($actionString eq 'cover' and $self->short()))
66 and $self->available()) {
67 2631 return 1;
68 }
69 else {
70 6844 return 0;
71 }
72 }
73  
74 257 ▶sub hashKey {
Subroutine hashKey: called CC=1 SCAR=0.0
Pod undocumented
75 257 my $self = shift;
76 257 my $stock = $self->stock();
77 257 return $stock->hashKey();
78 }
79  
80 147 ▶sub lineFormatValues {
Subroutine lineFormatValues: called CC=2 SCAR=7.0
Pod undocumented
81 147 my ($self, $available) = @_;
82 147 my $lineFormatValues = $self->SUPER::lineFormatValues();
83 147 ▶ $lineFormatValues->[3] = $available ? $self->available : $self->{accounted};
Branch: 1 branch
BranchTrueFalseTotal
$available ? : 0 147 147
84 147 return $lineFormatValues;
85 }
86  
87 0 ▶sub lineFormatString {
Subroutine lineFormatString: not called CC=1 SCAR=6.9
Pod undocumented
88 0 my ($self, $available) = @_;
89 0 return sprintf(Finance::StockAccount::Transaction->lineFormatPattern(), @{$self->lineFormatValues($available)});
90 }
91  
92  
93 9 1;
94  
95 __END__
« StockAccount/Realization.pm ↑ Summary StockAccount/Acquisition.pm »