| 1 | package Finance::AMEX::Transaction::GRRCN; | ||||||||||||||
| 2 | 7 | $Finance::AMEX::Transaction::GRRCN::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 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::Header; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::Summary; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::TaxRecord; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::Submission; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::Transaction; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::TxnPricing; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::Chargeback; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::Adjustment; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::FeeRevenue; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::Trailer; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 7 | ▶ | use Finance::AMEX::Transaction::GRRCN::Unknown; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | |||||||||||||||
| 20 | # ABSTRACT: Parse AMEX Global Reconciliation (GRRCN) | ||||||||||||||
| 21 | |||||||||||||||
| 22 | sub new { | ||||||||||||||
| 23 | 1 | ▶ | my ($class, %props) = @_; | ||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 1 | my $type_map = { | |||||||||||||
| 26 | HEADER => 'Finance::AMEX::Transaction::GRRCN::Header', | ||||||||||||||
| 27 | SUMMARY => 'Finance::AMEX::Transaction::GRRCN::Summary', | ||||||||||||||
| 28 | TAXRECORD => 'Finance::AMEX::Transaction::GRRCN::TaxRecord', | ||||||||||||||
| 29 | SUBMISSION => 'Finance::AMEX::Transaction::GRRCN::Submission', | ||||||||||||||
| 30 | TRANSACTN => 'Finance::AMEX::Transaction::GRRCN::Transaction', | ||||||||||||||
| 31 | TXNPRICING => 'Finance::AMEX::Transaction::GRRCN::TxnPricing', | ||||||||||||||
| 32 | CHARGEBACK => 'Finance::AMEX::Transaction::GRRCN::Chargeback', | ||||||||||||||
| 33 | ADJUSTMENT => 'Finance::AMEX::Transaction::GRRCN::Adjustment', | ||||||||||||||
| 34 | FEEREVENUE => 'Finance::AMEX::Transaction::GRRCN::FeeRevenue', | ||||||||||||||
| 35 | TRAILER => 'Finance::AMEX::Transaction::GRRCN::Trailer', | ||||||||||||||
| 36 | }; | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 1 | ▶ | my $file_format = $props{format} || 'UNKNOWN'; | ||||||||||||
|
Condition50%1/2
$props{'format'} || 'UNKNOWN'
MC/DC0%0/1
$props{'format'} || 'UNKNOWN'
$props{'format'}
Truth table50%1/2
A
A= $props{'format'}
| |||||||||||||||
| 39 | |||||||||||||||
| 40 | 1 | my $self = bless { | |||||||||||||
| 41 | _type_map => $type_map, | ||||||||||||||
| 42 | _file_format => $file_format, | ||||||||||||||
| 43 | }, $class; | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 1 | return $self; | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | sub file_format { | ||||||||||||||
| 49 | 392 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
file_format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 50 | 392 | return $self->{_file_format}; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | sub detect_file_format { | ||||||||||||||
| 54 | 1 | ▶ | my ($self, $line) = @_; | ||||||||||||
|
Subroutine
detect_file_format: called CC=4 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 55 | |||||||||||||||
| 56 | 1 | ▶ | if (substr($line, 0, 1) eq '"') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 1 | ▶ | if ($line =~ m{","}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 58 | 1 | $self->{_file_format} = 'CSV'; | |||||||||||||
| 59 | } elsif ($line =~ m{\"\t\"}) { | ||||||||||||||
| 60 | 0 | $self->{_file_format} = 'TSV'; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | 1 | return $self->{_file_format}; | |||||||||||||
| 64 | } | ||||||||||||||
| 65 | 0 | $self->{_file_format} = 'FIXED'; | |||||||||||||
| 66 | 0 | return $self->{_file_format}; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | sub parse_line { | ||||||||||||||
| 70 | 99 | ▶ | my ($self, $line) = @_; | ||||||||||||
|
Subroutine
parse_line: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||
| 71 | |||||||||||||||
| 72 | 99 | ▶ | return if not defined $line; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 73 | |||||||||||||||
| 74 | 98 | ▶ | if ($self->file_format eq 'UNKNOWN') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | 1 | $self->detect_file_format($line); | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 98 | my $type = $self->detect_line_type($line); | |||||||||||||
| 79 | |||||||||||||||
| 80 | 98 | ▶ | if (exists $self->{_type_map}->{$type}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 81 | 98 | return $self->{_type_map}->{$type}->new(line => $line, file_format => $self->file_format); | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | |||||||||||||||
| 84 | 0 | return Finance::AMEX::Transaction::GRRCN::Unknown->new(line => $line); | |||||||||||||
| 85 | } | ||||||||||||||
| 86 | |||||||||||||||
| 87 | sub detect_line_type { | ||||||||||||||
| 88 | 98 | ▶ | my ($self, $line) = @_; | ||||||||||||
|
Subroutine
detect_line_type: called CC=6 SCAR=21.2
Pod
undocumented
| |||||||||||||||
| 89 | |||||||||||||||
| 90 | 98 | ▶ | if ($self->file_format eq 'FIXED') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | 0 | return substr($line, 0, 10); | |||||||||||||
| 92 | } | ||||||||||||||
| 93 | |||||||||||||||
| 94 | 98 | ▶ | my $csv = Text::CSV->new ({ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 95 | binary => 1, | ||||||||||||||
| 96 | quote_char => '"', | ||||||||||||||
| 97 | escape_char => "\\", | ||||||||||||||
| 98 | }) or die "Cannot use CSV: ".Text::CSV->error_diag (); | ||||||||||||||
| 99 | 98 | $line =~ s{\s+\z}{}; # csv parser does not like trailing whitespace | |||||||||||||
| 100 | |||||||||||||||
| 101 | 98 | ▶ | if ($self->file_format eq 'CSV') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 102 | 98 | $csv->sep_char(','); | |||||||||||||
| 103 | } elsif ($self->file_format eq 'TSV') { | ||||||||||||||
| 104 | 0 | $csv->sep_char("\t"); | |||||||||||||
| 105 | } | ||||||||||||||
| 106 | |||||||||||||||
| 107 | 98 | ▶ | if (my $status = $csv->parse($line)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 108 | 98 | return ($csv->fields)[0]; | |||||||||||||
| 109 | } | ||||||||||||||
| 110 | } | ||||||||||||||
| 111 | |||||||||||||||
| 112 | 7 | 1; | |||||||||||||
| 113 | |||||||||||||||
| 114 | __END__ | ||||||||||||||