lib/Finance/Bank/SentinelBenefits/Csv401kConverter.pm

filter: Statementstmt 100% 64 / 64 Branchbran 100% 10 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 1 / 1 totaltotal 97.8% 91 / 93 CC 8 SCAR 13.4
CC
8
Cov
99%
write_output
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
« lib/Finance/Bank/SentinelBenefits/Csv401kConverter/LineParser.pm ↑ Summary lib/Finance/Bank/SentinelBenefits/Csv401kConverter/SymbolMap.pm »
1 package Finance::Bank::SentinelBenefits::Csv401kConverter;
2 4 $Finance::Bank::SentinelBenefits::Csv401kConverter::VERSION = '1.3';
3 4 ▶use Modern::Perl '2015';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use DateTime::Format::Flexible;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11  
12  
13 Finance::Bank::SentinelBenefits::Csv401kConverter - Takes a series of lines in Sentinel Benefits format and writes them out as QIF files, subject to the symbol mappings specified.
14  
15  
16  
17 =head1 VERSION
18  
19 version 1.3
20  
21 =head1 SYNOPSIS
22  
23  
24  
25  
26 =head1 DESCRIPTION
27  
28  
29  
30 This module takes a CSV file in the format "provided" i.e. copy-pasted from the Sentinel Benefits website. It also takes a description->symbol mapping, and one or two filenames to write out. The first file is a list of the transactions in QIF format. The second file, if provided, is a list of the company matches with the signs reversed, which can be useful if you want to keep unvested company contributions from showing up in your net worth calculations.
31  
32  
33  
34 =cut
35  
36 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 4 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 4 ▶use Finance::Bank::SentinelBenefits::Csv401kConverter::SymbolMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 4 ▶use Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 4 ▶use Finance::Bank::SentinelBenefits::Csv401kConverter::QifWriter;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 4 ▶use Finance::Bank::SentinelBenefits::Csv401kConverter::SideReverser;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44  
45 =head1 Accessors
46  
47  
48  
49 =head2 $p->trade_input()
50  
51  
52  
53 A file handle that supplies the trade data
54  
55  
56  
57 =cut
58  
59 4 has 'trade_input' => (
60 is => 'ro',
61 isa => 'FileHandle',
62 required => 1,
63 );
64  
65 4 has 'primary_output_file' => (
66 is => 'ro',
67 isa => 'Str',
68 required => 1,
69 );
70  
71 4 has 'symbol_map' => (
72 is => 'ro',
73 isa => 'Finance::Bank::SentinelBenefits::Csv401kConverter::SymbolMap',
74 required => 1,
75 );
76  
77 =head2 $p->trade_date()
78  
79  
80  
81 Used if you wish to override the trade date specified in the input file, or if no trade date is available in the files.
82  
83  
84  
85 If no dates are specified here or in the files, an exception will be thrown.
86  
87  
88  
89 =cut
90  
91 4 has 'trade_date' => (
92 is => 'ro',
93 isa => 'DateTime',
94 required => 0,
95 );
96  
97 4 has 'account' => (
98 is => 'ro',
99 isa => 'Str',
100 required => 1,
101 );
102  
103 4 has 'companymatch_account' => (
104 is => 'ro',
105 isa => 'Str',
106 required => 0,
107 );
108  
109 has '_side_reverser' => (
110 is => 'ro',
111 isa => 'Finance::Bank::SentinelBenefits::Csv401kConverter::SideReverser',
112 required => 0,
113 10 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
114 10 Finance::Bank::SentinelBenefits::Csv401kConverter::SideReverser->new();
115 }
116 4 );
117  
118  
119 =head2 p->write_output()
120  
121 Writes the output to the output file
122  
123 =cut
124  
125 8 ▶sub write_output($self){
Subroutine write_output: called CC=8 SCAR=20.8
Pod documented
126 8 my $parser = Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser->new
127 (
128 symbol_map => $self->symbol_map()
129 );
130  
131 8 my $writer = Finance::Bank::SentinelBenefits::Csv401kConverter::QifWriter->new
132 (
133 output_file => ">" . $self->primary_output_file(),
134 account => $self->account(),
135 );
136  
137 8 my $fh = $self->trade_input();
138  
139 8 my @lines;
140  
141 8 my $date = $self->trade_date();
142  
143 8 ▶ while(<$fh>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 46 8 54
144  
145  
146 #this line is a date and there is no override, parse it as such
147 46 ▶ if(9 == length && (not defined $self->trade_date()) ){
Branch: 1 branch
BranchTrueFalseTotal
if (9 == length $_ and not defined $self->trade_date) { } 4 42 46
Condition66%2/3
9 == length $_ and not defined $self->trade_date
!ll&&!rl&&r
4204
MC/DC50%1/2
9 == length $_ and not defined $self->trade_date
9 == length $_ not defined $self->trade_date
Truth table66%2/3
A and not(B)
A= 9 == length $_B= not defined $self->trade_date
ABresult
0X0
100
111
148 4 $date = DateTime::Format::Flexible->parse_datetime($_);
149 # warn "date is $date";
150 }else{
151  
152 42 my $line = $parser->parse_line($_, $date);
153  
154 42 ▶ if (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 14 28 42
155 14 $writer->output_line($line);
156  
157 14 push @lines, $line;
158 }
159 }
160 }
161  
162 8 $writer->close();
163  
164 8 ▶ if($self->companymatch_account())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->companymatch_account) 4 4 8
165 {
166 4 my $cm_writer = Finance::Bank::SentinelBenefits::Csv401kConverter::QifWriter->new
167 (
168 output_file => ">>" . $self->primary_output_file(),
169 account => $self->companymatch_account(),
170 );
171  
172 4 foreach my $line (@lines) {
173  
174 6 ▶ if($line->source() eq 'Match'){
Branch: 1 branch
BranchTrueFalseTotal
if ($line->source eq "Match") 4 2 6
175 4 my $cm_line = Finance::Bank::SentinelBenefits::Csv401kConverter::Line->new
176 (
177 date => $line->date(),
178 symbol => $line->symbol(),
179 memo => $line->memo(),
180 quantity => $line->quantity(),
181 price => $line->price(),
182 total => $line->total(),
183 source => $line->source(),
184 side => $self->_side_reverser->flip($line->side()),
185 );
186 4 $cm_writer->output_line($cm_line);
187 }
188  
189 }
190  
191 4 $cm_writer->close();
192
193 }
194 }
195  
196 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
197  
198 4 __PACKAGE__->meta->make_immutable;
199  
200 4 1;
201  
202  
203 =head1 LICENSE AND COPYRIGHT
204 Copyright 2009-2023 David Solimano
205 This file is part of Finance::Bank::SentinelBenefits::Csv401kConverter
206  
207 Finance::Bank::SentinelBenefits::Csv401kConverter is free software: you can redistribute it and/or modify
208 it under the terms of the GNU General Public License as published by
209 the Free Software Foundation, either version 3 of the License, or
210 (at your option) any later version.
211  
212 Finance::Bank::SentinelBenefits::Csv401kConverter is distributed in the hope that it will be useful,
213 but WITHOUT ANY WARRANTY; without even the implied warranty of
214 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
215 GNU General Public License for more details.
216  
217 You should have received a copy of the GNU General Public License
218 along with Finance::Bank::SentinelBenefits::Csv401kConverter. If not, see <http://www.gnu.org/licenses/>
219 =cut
« lib/Finance/Bank/SentinelBenefits/Csv401kConverter/LineParser.pm ↑ Summary lib/Finance/Bank/SentinelBenefits/Csv401kConverter/SymbolMap.pm »