line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::AMEX::Transaction::GRRCN::Base 0.005; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
80
|
use strict; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
241
|
|
4
|
10
|
|
|
10
|
|
47
|
use warnings; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
189
|
|
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
653
|
use Text::CSV; |
|
10
|
|
|
|
|
19791
|
|
|
10
|
|
|
|
|
328
|
|
7
|
10
|
|
|
10
|
|
64
|
use Carp 'croak'; |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
5001
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Parse AMEX Global Reconciliation (GRRCN) Base methods |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
114
|
|
|
114
|
1
|
2190
|
my ($class, %props) = @_; |
13
|
|
|
|
|
|
|
my $self = bless { |
14
|
|
|
|
|
|
|
_line => $props{line}, |
15
|
|
|
|
|
|
|
_file_format => $props{file_format}, |
16
|
|
|
|
|
|
|
_fields => undef, |
17
|
114
|
|
50
|
|
|
649
|
_file_version => $props{file_version} || 1.01, |
18
|
|
|
|
|
|
|
}, $class; |
19
|
|
|
|
|
|
|
|
20
|
114
|
|
|
|
|
467
|
my $map = $self->field_map; |
21
|
|
|
|
|
|
|
|
22
|
114
|
|
|
|
|
194
|
my $column_number = 0; |
23
|
114
|
|
|
|
|
173
|
my $numbered = {}; |
24
|
|
|
|
|
|
|
|
25
|
114
|
|
|
|
|
164
|
foreach my $column (@{$map}) { |
|
114
|
|
|
|
|
239
|
|
26
|
3152
|
|
|
|
|
3635
|
my ($field) = keys %{$column}; |
|
3152
|
|
|
|
|
5043
|
|
27
|
3152
|
|
|
|
|
5216
|
$numbered->{$field} = $column_number++; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
114
|
|
|
|
|
248
|
$self->{_fields} = $numbered; |
31
|
|
|
|
|
|
|
|
32
|
114
|
|
|
|
|
980
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub line { |
36
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
37
|
0
|
|
|
|
|
0
|
return $self->{_line}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub file_format { |
41
|
5628
|
|
|
5628
|
1
|
8687
|
my ($self) = @_; |
42
|
5628
|
|
|
|
|
14839
|
return $self->{_file_format}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub fields { |
46
|
5650
|
|
|
5650
|
1
|
7880
|
my ($self) = @_; |
47
|
5650
|
|
|
|
|
12504
|
return $self->{_fields}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub file_version { |
51
|
88
|
|
|
88
|
1
|
145
|
my ($self) = @_; |
52
|
88
|
|
|
|
|
433
|
return $self->{_file_version}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _get_column { |
56
|
2820
|
|
|
2820
|
|
5533
|
my ($self, $field) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# this will happen if we're trying to get a field that does not |
59
|
|
|
|
|
|
|
# exist in the version of the file we are parsing |
60
|
2820
|
100
|
|
|
|
5477
|
return if not exists $self->fields->{$field}; |
61
|
|
|
|
|
|
|
|
62
|
2814
|
50
|
33
|
|
|
5037
|
if ($self->file_format eq 'CSV' or $self->file_format eq 'TSV') { |
|
|
0
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Text::CSV does not like blank space at the end of the line |
65
|
2814
|
|
|
|
|
14159
|
$self->{_line} =~ s{\s+\z}{}xsm; |
66
|
2814
|
|
|
|
|
4437
|
my $index = $self->fields->{$field}; |
67
|
|
|
|
|
|
|
|
68
|
2814
|
50
|
|
|
|
12114
|
my $csv = Text::CSV->new({ |
69
|
|
|
|
|
|
|
binary => 1, |
70
|
|
|
|
|
|
|
quote_char => '"', |
71
|
|
|
|
|
|
|
escape_char => "\\", |
72
|
|
|
|
|
|
|
}) |
73
|
|
|
|
|
|
|
or croak 'Cannot use CSV: ' . Text::CSV->error_diag(); |
74
|
|
|
|
|
|
|
|
75
|
2814
|
50
|
|
|
|
330322
|
if ($self->file_format eq 'TSV') { |
76
|
0
|
|
|
|
|
0
|
$csv->sep_char("\t"); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
2814
|
50
|
|
|
|
6595
|
if (my $status = $csv->parse($self->{_line})) { |
80
|
2814
|
|
|
|
|
94488
|
return ($csv->fields)[$index]; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} elsif ($self->file_format eq 'FIXED') { |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $column_number = $self->fields->{$field}; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $map = $self->field_map->{$column_number}->{$field}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# if the line is not long enough to handle the start of the field, |
90
|
|
|
|
|
|
|
# it is an optional field that we don't have |
91
|
0
|
0
|
|
|
|
|
if (length($self->{_line}) < $map->[0]) { |
92
|
0
|
|
|
|
|
|
return ''; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $ret = substr($self->{_line}, $map->[0] - 1, $map->[1]); |
96
|
0
|
|
|
|
|
|
$ret =~ s{\s+\z}{}xsm; |
97
|
0
|
|
|
|
|
|
return $ret; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |