Transaction/GRRCN/Base.pm

filter: Statementstmt 80.0% 36 / 45 Branchbran 42.8% 6 / 14 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 88.8% 8 / 9 Podpod 40.0% 2 / 5 totaltotal 66.6% 54 / 81 SCAR 25.7
CC
10
Cov
69%
_get_column
19.6
new
3.0
line
2.0
CRAP 13.1
« Transaction/EPRAW.pm ↑ Summary Transaction.pm »
1 package Finance::AMEX::Transaction::GRRCN::Base;
2 8 $Finance::AMEX::Transaction::GRRCN::Base::VERSION = '0.004';
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶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 104 ▶ my ($class, %props) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
12 my $self = bless {
13 _line => $props{line},
14 _file_format => $props{file_format},
15 _fields => undef,
16 104 ▶ _version => $props{version} || 1.01,
Condition50%1/2
$props{'version'} || 1.01
l!l
1040
MC/DC0%0/1
$props{'version'} || 1.01
$props{'version'}
Truth table50%1/2
A
A= $props{'version'}
Aresult
11
00
17 }, $class;
18  
19 104 my $map = $self->field_map;
20  
21 104 my @sorted = sort {$map->{$a}->[0] <=> $map->{$b}->[0]} keys %{$map};
22 104 my $numbered = {};
23 104 ▶ for (my $i = 0; $i < @sorted; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @sorted) 2799 104 2903
24 2799 $numbered->{$sorted[$i]} = $i;
25 }
26  
27 104 $self->{_fields} = $numbered;
28  
29 104 return $self;
30 }
31  
32 sub line {
33 0 ▶ my ($self) = @_;
Subroutine line: not called CC=1 SCAR=6.9
Pod documented
34 0 return $self->{_line};
35 }
36  
37 sub file_format {
38 5602 ▶ my ($self) = @_;
Subroutine file_format: called CC=1 SCAR=0.0
Pod undocumented
39 5602 return $self->{_file_format};
40 }
41  
42 sub fields {
43 2801 ▶ my ($self) = @_;
Subroutine fields: called CC=1 SCAR=0.0
Pod undocumented
44 2801 return $self->{_fields};
45 }
46  
47 sub version {
48 170 ▶ my ($self) = @_;
Subroutine version: called CC=1 SCAR=0.0
Pod undocumented
49 170 return $self->{_version};
50 }
51  
52 sub _get_column {
53 2801 ▶ my ($self, $field) = @_;
Subroutine _get_column: called CC=8 SCAR=29.8
54  
55 2801 ▶ 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') { } 2801 0 2801
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
280100
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
56  
57 # Text::CSV does not like blank space at the end of the line
58 2801 $self->{_line} =~ s{\s+\z}{};
59 2801 my $index = $self->fields->{$field};
60  
61 2801 ▶ 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 2801 2801
62 binary => 1,
63 quote_char => '"',
64 escape_char => "\\",
65 }) or die "Cannot use CSV: ".Text::CSV->error_diag ();
66  
67 2801 ▶ if ($self->file_format eq 'TSV') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->file_format eq "TSV") 0 2801 2801
68 0 $csv->sep_char("\t");
69 }
70  
71 2801 ▶ if (my $status = $csv->parse($self->{_line})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $status = $csv->parse($self->{"_line"})) 2801 0 2801
72 2801 return ($csv->fields)[$index];
73 }
74  
75 } elsif ($self->file_format eq 'FIXED') {
76  
77 0 my $map = $self->field_map;
78  
79 # if the line is not long enough to handle the start of the field,
80 # it is an optional field that we don't have
81 0 ▶ if (length($self->{_line}) < $map->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"_line"} < $map->[0]) 0 0 0
82 0 return '';
83 }
84  
85 0 my $ret = substr($self->{_line}, $map->[0] - 1, $map->[1]);
86 0 $ret =~ s{\s+\z}{};
87 0 return $ret;
88 }
89  
90 }
91  
92 8 1;
93  
94 __END__
« Transaction/EPRAW.pm ↑ Summary Transaction.pm »