Transaction/GRRCN/Base.pm

filter: Statementstmt 79.0% 34 / 43 Branchbran 42.8% 6 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod 50.0% 2 / 4 totaltotal 67.5% 50 / 74 SCAR 24.5
CC
9
Cov
68%
_get_column
19.6
new
2.0
line
2.0
CRAP 11.6
« Transaction/EPRAW.pm ↑ Summary Transaction.pm »
1 package Finance::AMEX::Transaction::GRRCN::Base;
2 7 $Finance::AMEX::Transaction::GRRCN::Base::VERSION = '0.003';
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use Text::CSV;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: Parse AMEX Global Reconciliation (GRRCN) Base methods
9  
10 sub new {
11 98 ▶ my ($class, %props) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
12 my $self = bless {
13 _line => $props{line},
14 _file_format => $props{file_format},
15 98 _fields => undef,
16 }, $class;
17  
18 98 my $map = $self->field_map;
19  
20 98 my @sorted = sort {$map->{$a}->[0] <=> $map->{$b}->[0]} keys %{$map};
21 98 my $numbered = {};
22 98 ▶ for (my $i = 0; $i < @sorted; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @sorted) 2681 98 2779
23 2681 $numbered->{$sorted[$i]} = $i;
24 }
25  
26 98 $self->{_fields} = $numbered;
27  
28 98 return $self;
29 }
30  
31 sub line {
32 0 ▶ my ($self) = @_;
Subroutine line: not called CC=1 SCAR=6.9
Pod documented
33 0 return $self->{_line};
34 }
35  
36 sub file_format {
37 5362 ▶ my ($self) = @_;
Subroutine file_format: called CC=1 SCAR=0.0
Pod undocumented
38 5362 return $self->{_file_format};
39 }
40  
41 sub fields {
42 2681 ▶ my ($self) = @_;
Subroutine fields: called CC=1 SCAR=0.0
Pod undocumented
43 2681 return $self->{_fields};
44 }
45  
46 sub _get_column {
47 2681 ▶ my ($self, $field) = @_;
Subroutine _get_column: called CC=8 SCAR=29.8
48  
49 2681 ▶ if ($self->file_format eq 'CSV' or $self->file_format eq 'TSV') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->file_format eq 'CSV' or $self->file_format eq 'TSV') { } 2681 0 2681
elsif ($self->file_format eq 'FIXED') { } 0 0 0
Condition33%1/3
$self->file_format eq "CSV" or $self->file_format eq "TSV"
l!l&&r!l&&!r
268100
MC/DC0%0/2
$self->file_format eq "CSV" or $self->file_format eq "TSV"
$self->file_format eq "CSV" $self->file_format eq "TSV"
Truth table33%1/3
A or B
A= $self->file_format eq "CSV"B= $self->file_format eq "TSV"
ABresult
1X1
011
000
50  
51 # Text::CSV does not like blank space at the end of the line
52 2681 $self->{_line} =~ s{\s+\z}{};
53 2681 my $index = $self->fields->{$field};
54  
55 2681 ▶ my $csv = Text::CSV->new ({
Branch: 1 branch
BranchTrueFalseTotal
my $csv = "Text::CSV"->new({"binary", 1, "quote_char", "\"", "escape_char", "\\"}) or die 'Cannot use CSV: ' . "Text::CSV"->error_diag 0 2681 2681
56 binary => 1,
57 quote_char => '"',
58 escape_char => "\\",
59 }) or die "Cannot use CSV: ".Text::CSV->error_diag ();
60  
61 2681 ▶ if ($self->file_format eq 'TSV') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->file_format eq "TSV") 0 2681 2681
62 0 $csv->sep_char("\t");
63 }
64  
65 2681 ▶ if (my $status = $csv->parse($self->{_line})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $status = $csv->parse($self->{"_line"})) 2681 0 2681
66 2681 return ($csv->fields)[$index];
67 }
68  
69 } elsif ($self->file_format eq 'FIXED') {
70  
71 0 my $map = $self->field_map;
72  
73 # if the line is not long enough to handle the start of the field,
74 # it is an optional field that we don't have
75 0 ▶ if (length($self->{_line}) < $map->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"_line"} < $map->[0]) 0 0 0
76 0 return '';
77 }
78  
79 0 my $ret = substr($self->{_line}, $map->[0] - 1, $map->[1]);
80 0 $ret =~ s{\s+\z}{};
81 0 return $ret;
82 }
83  
84 }
85  
86 7 1;
87  
88 __END__
« Transaction/EPRAW.pm ↑ Summary Transaction.pm »