line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::AMEX::Transaction::GRRCN::Base; |
2
|
|
|
|
|
|
|
$Finance::AMEX::Transaction::GRRCN::Base::VERSION = '0.004'; |
3
|
8
|
|
|
8
|
|
71
|
use strict; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
230
|
|
4
|
8
|
|
|
8
|
|
45
|
use warnings; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
186
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
42
|
use Text::CSV; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
5706
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Parse AMEX Global Reconciliation (GRRCN) Base methods |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
104
|
|
|
104
|
1
|
623
|
my ($class, %props) = @_; |
12
|
|
|
|
|
|
|
my $self = bless { |
13
|
|
|
|
|
|
|
_line => $props{line}, |
14
|
|
|
|
|
|
|
_file_format => $props{file_format}, |
15
|
|
|
|
|
|
|
_fields => undef, |
16
|
104
|
|
50
|
|
|
912
|
_version => $props{version} || 1.01, |
17
|
|
|
|
|
|
|
}, $class; |
18
|
|
|
|
|
|
|
|
19
|
104
|
|
|
|
|
626
|
my $map = $self->field_map; |
20
|
|
|
|
|
|
|
|
21
|
104
|
|
|
|
|
310
|
my @sorted = sort {$map->{$a}->[0] <=> $map->{$b}->[0]} keys %{$map}; |
|
10511
|
|
|
|
|
17217
|
|
|
104
|
|
|
|
|
1016
|
|
22
|
104
|
|
|
|
|
460
|
my $numbered = {}; |
23
|
104
|
|
|
|
|
515
|
for (my $i = 0; $i < @sorted; $i++) { |
24
|
2799
|
|
|
|
|
6361
|
$numbered->{$sorted[$i]} = $i; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
104
|
|
|
|
|
322
|
$self->{_fields} = $numbered; |
28
|
|
|
|
|
|
|
|
29
|
104
|
|
|
|
|
901
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub line { |
33
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
34
|
0
|
|
|
|
|
0
|
return $self->{_line}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub file_format { |
38
|
5602
|
|
|
5602
|
0
|
10590
|
my ($self) = @_; |
39
|
5602
|
|
|
|
|
20048
|
return $self->{_file_format}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub fields { |
43
|
2801
|
|
|
2801
|
0
|
4937
|
my ($self) = @_; |
44
|
2801
|
|
|
|
|
6962
|
return $self->{_fields}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub version { |
48
|
170
|
|
|
170
|
0
|
401
|
my ($self) = @_; |
49
|
170
|
|
|
|
|
3760
|
return $self->{_version}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _get_column { |
53
|
2801
|
|
|
2801
|
|
7430
|
my ($self, $field) = @_; |
54
|
|
|
|
|
|
|
|
55
|
2801
|
50
|
33
|
|
|
6728
|
if ($self->file_format eq 'CSV' or $self->file_format eq 'TSV') { |
|
|
0
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Text::CSV does not like blank space at the end of the line |
58
|
2801
|
|
|
|
|
16117
|
$self->{_line} =~ s{\s+\z}{}; |
59
|
2801
|
|
|
|
|
7101
|
my $index = $self->fields->{$field}; |
60
|
|
|
|
|
|
|
|
61
|
2801
|
50
|
|
|
|
15102
|
my $csv = Text::CSV->new ({ |
62
|
|
|
|
|
|
|
binary => 1, |
63
|
|
|
|
|
|
|
quote_char => '"', |
64
|
|
|
|
|
|
|
escape_char => "\\", |
65
|
|
|
|
|
|
|
}) or die "Cannot use CSV: ".Text::CSV->error_diag (); |
66
|
|
|
|
|
|
|
|
67
|
2801
|
50
|
|
|
|
420969
|
if ($self->file_format eq 'TSV') { |
68
|
0
|
|
|
|
|
0
|
$csv->sep_char("\t"); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
2801
|
50
|
|
|
|
8970
|
if (my $status = $csv->parse($self->{_line})) { |
72
|
2801
|
|
|
|
|
118317
|
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
|
0
|
|
|
|
|
if (length($self->{_line}) < $map->[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
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |