| 1 | package Finance::AMEX::Transaction::GRRCN; | ||||||||||||||
| 2 | 8 | $Finance::AMEX::Transaction::GRRCN::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 | 8 | ▶ | use Finance::AMEX::Transaction::GRRCN::Header; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 8 | ▶ | use Finance::AMEX::Transaction::GRRCN::Summary; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 8 | ▶ | use Finance::AMEX::Transaction::GRRCN::TaxRecord; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 8 | ▶ | use Finance::AMEX::Transaction::GRRCN::Submission; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 8 | ▶ | use Finance::AMEX::Transaction::GRRCN::Transaction; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 8 | ▶ | use Finance::AMEX::Transaction::GRRCN::TxnPricing; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 8 | ▶ | use Finance::AMEX::Transaction::GRRCN::Chargeback; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 8 | ▶ | use Finance::AMEX::Transaction::GRRCN::Adjustment; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 8 | ▶ | use Finance::AMEX::Transaction::GRRCN::FeeRevenue; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 8 | ▶ | use Finance::AMEX::Transaction::GRRCN::Trailer; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 8 | ▶ | 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 | 2 | ▶ | my ($class, %props) = @_; | ||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 2 | 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 | 2 | ▶ | 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 | my $self = bless { | ||||||||||||||
| 41 | _type_map => $type_map, | ||||||||||||||
| 42 | _file_format => $file_format, | ||||||||||||||
| 43 | 2 | ▶ | _version => $props{version} || 1.01, | ||||||||||||
|
Condition50%1/2
$props{'version'} || 1.01
MC/DC0%0/1
$props{'version'} || 1.01
$props{'version'}
Truth table50%1/2
A
A= $props{'version'}
| |||||||||||||||
| 44 | }, $class; | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 2 | return $self; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | sub file_format { | ||||||||||||||
| 50 | 416 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
file_format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 51 | 416 | return $self->{_file_format}; | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | sub detect_file_format { | ||||||||||||||
| 55 | 2 | ▶ | my ($self, $line) = @_; | ||||||||||||
|
Subroutine
detect_file_format: called CC=4 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 56 | |||||||||||||||
| 57 | 2 | ▶ | if (substr($line, 0, 1) eq '"') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | 2 | ▶ | if ($line =~ m{","}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 59 | 2 | $self->{_file_format} = 'CSV'; | |||||||||||||
| 60 | } elsif ($line =~ m{\"\t\"}) { | ||||||||||||||
| 61 | 0 | $self->{_file_format} = 'TSV'; | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 2 | return $self->{_file_format}; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | 0 | $self->{_file_format} = 'FIXED'; | |||||||||||||
| 67 | 0 | return $self->{_file_format}; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | sub parse_line { | ||||||||||||||
| 71 | 106 | ▶ | my ($self, $line) = @_; | ||||||||||||
|
Subroutine
parse_line: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||
| 72 | |||||||||||||||
| 73 | 106 | ▶ | return if not defined $line; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 74 | |||||||||||||||
| 75 | 104 | ▶ | if ($self->file_format eq 'UNKNOWN') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | 2 | $self->detect_file_format($line); | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 104 | my $type = $self->detect_line_type($line); | |||||||||||||
| 80 | |||||||||||||||
| 81 | 104 | ▶ | if (exists $self->{_type_map}->{$type}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 82 | |||||||||||||||
| 83 | my $parsed = $self->{_type_map}->{$type}->new( | ||||||||||||||
| 84 | line => $line, | ||||||||||||||
| 85 | file_format => $self->file_format, | ||||||||||||||
| 86 | version => $self->{_version}, | ||||||||||||||
| 87 | 104 | ); | |||||||||||||
| 88 | |||||||||||||||
| 89 | 104 | ▶ | if ($type eq 'HEADER') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 90 | 2 | $self->{_version} = $parsed->FILE_VERSION_NUMBER; | |||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 104 | return $parsed; | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | |||||||||||||||
| 96 | 0 | return Finance::AMEX::Transaction::GRRCN::Unknown->new(line => $line); | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | |||||||||||||||
| 99 | sub detect_line_type { | ||||||||||||||
| 100 | 104 | ▶ | my ($self, $line) = @_; | ||||||||||||
|
Subroutine
detect_line_type: called CC=6 SCAR=21.2
Pod
undocumented
| |||||||||||||||
| 101 | |||||||||||||||
| 102 | 104 | ▶ | if ($self->file_format eq 'FIXED') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 103 | 0 | return substr($line, 0, 10); | |||||||||||||
| 104 | } | ||||||||||||||
| 105 | |||||||||||||||
| 106 | 104 | ▶ | my $csv = Text::CSV->new ({ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 107 | binary => 1, | ||||||||||||||
| 108 | quote_char => '"', | ||||||||||||||
| 109 | escape_char => "\\", | ||||||||||||||
| 110 | }) or die "Cannot use CSV: ".Text::CSV->error_diag (); | ||||||||||||||
| 111 | 104 | $line =~ s{\s+\z}{}; # csv parser does not like trailing whitespace | |||||||||||||
| 112 | |||||||||||||||
| 113 | 104 | ▶ | if ($self->file_format eq 'CSV') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 114 | 104 | $csv->sep_char(','); | |||||||||||||
| 115 | } elsif ($self->file_format eq 'TSV') { | ||||||||||||||
| 116 | 0 | $csv->sep_char("\t"); | |||||||||||||
| 117 | } | ||||||||||||||
| 118 | |||||||||||||||
| 119 | 104 | ▶ | if (my $status = $csv->parse($line)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 120 | 104 | return ($csv->fields)[0]; | |||||||||||||
| 121 | } | ||||||||||||||
| 122 | } | ||||||||||||||
| 123 | |||||||||||||||
| 124 | 8 | 1; | |||||||||||||
| 125 | |||||||||||||||
| 126 | __END__ | ||||||||||||||