| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->file_format eq "CSV" or $self->file_format eq "TSV"
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"
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 62 | 0 | $csv->sep_char("\t"); | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 2681 | ▶ | if (my $status = $csv->parse($self->{_line})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||