Transaction/GRRCN.pm

filter: Statementstmt 92.2% 71 / 77 Branchbran 50.0% 11 / 22 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 19 / 19 Podpod 40.0% 2 / 5 totaltotal 82.5% 104 / 126 SCAR 26.4
CC
13
Cov
82%
detect_line_type
8.3
detect_file_format
6.0
parse_line
4.0
CRAP 14.0
« Transaction/EPPRC.pm ↑ Summary Transaction/EPRAW.pm »
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'
l!l
01
MC/DC0%0/1
$props{'format'} || 'UNKNOWN'
$props{'format'}
Truth table50%1/2
A
A= $props{'format'}
Aresult
11
00
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
BranchTrueFalseTotal
if (substr($line, 0, 1) eq "\"") 1 0 1
57 1 ▶ if ($line =~ m{","}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /","/) { } 1 0 1
elsif ($line =~ /\"\t\"/) { } 0 0 0
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
BranchTrueFalseTotal
unless defined $line 1 98 99
73  
74 98 ▶ if ($self->file_format eq 'UNKNOWN') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->file_format eq "UNKNOWN") 1 97 98
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
BranchTrueFalseTotal
if (exists $self->{"_type_map"}{$type}) 98 0 98
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
BranchTrueFalseTotal
if ($self->file_format eq "FIXED") 0 98 98
91 0 return substr($line, 0, 10);
92 }
93  
94 98 ▶ 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 98 98
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
BranchTrueFalseTotal
if ($self->file_format eq 'CSV') { } 98 0 98
elsif ($self->file_format eq 'TSV') { } 0 0 0
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
BranchTrueFalseTotal
if (my $status = $csv->parse($line)) 98 0 98
108 98 return ($csv->fields)[0];
109 }
110 }
111  
112 7 1;
113  
114 __END__
« Transaction/EPPRC.pm ↑ Summary Transaction/EPRAW.pm »