line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::AMEX::Transaction::GRRCN::Base; |
2
|
|
|
|
|
|
|
$Finance::AMEX::Transaction::GRRCN::Base::VERSION = '0.003'; |
3
|
7
|
|
|
7
|
|
57
|
use strict; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
189
|
|
4
|
7
|
|
|
7
|
|
39
|
use warnings; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
175
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
37
|
use Text::CSV; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
3518
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Parse AMEX Global Reconciliation (GRRCN) Base methods |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
98
|
|
|
98
|
1
|
336
|
my ($class, %props) = @_; |
12
|
|
|
|
|
|
|
my $self = bless { |
13
|
|
|
|
|
|
|
_line => $props{line}, |
14
|
|
|
|
|
|
|
_file_format => $props{file_format}, |
15
|
98
|
|
|
|
|
388
|
_fields => undef, |
16
|
|
|
|
|
|
|
}, $class; |
17
|
|
|
|
|
|
|
|
18
|
98
|
|
|
|
|
377
|
my $map = $self->field_map; |
19
|
|
|
|
|
|
|
|
20
|
98
|
|
|
|
|
210
|
my @sorted = sort {$map->{$a}->[0] <=> $map->{$b}->[0]} keys %{$map}; |
|
9917
|
|
|
|
|
12921
|
|
|
98
|
|
|
|
|
721
|
|
21
|
98
|
|
|
|
|
291
|
my $numbered = {}; |
22
|
98
|
|
|
|
|
280
|
for (my $i = 0; $i < @sorted; $i++) { |
23
|
2681
|
|
|
|
|
4839
|
$numbered->{$sorted[$i]} = $i; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
98
|
|
|
|
|
232
|
$self->{_fields} = $numbered; |
27
|
|
|
|
|
|
|
|
28
|
98
|
|
|
|
|
739
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub line { |
32
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
33
|
0
|
|
|
|
|
0
|
return $self->{_line}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub file_format { |
37
|
5362
|
|
|
5362
|
0
|
8088
|
my ($self) = @_; |
38
|
5362
|
|
|
|
|
14366
|
return $self->{_file_format}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub fields { |
42
|
2681
|
|
|
2681
|
0
|
3920
|
my ($self) = @_; |
43
|
2681
|
|
|
|
|
5157
|
return $self->{_fields}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _get_column { |
47
|
2681
|
|
|
2681
|
|
5243
|
my ($self, $field) = @_; |
48
|
|
|
|
|
|
|
|
49
|
2681
|
50
|
33
|
|
|
5074
|
if ($self->file_format eq 'CSV' or $self->file_format eq 'TSV') { |
|
|
0
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Text::CSV does not like blank space at the end of the line |
52
|
2681
|
|
|
|
|
11848
|
$self->{_line} =~ s{\s+\z}{}; |
53
|
2681
|
|
|
|
|
4968
|
my $index = $self->fields->{$field}; |
54
|
|
|
|
|
|
|
|
55
|
2681
|
50
|
|
|
|
12033
|
my $csv = Text::CSV->new ({ |
56
|
|
|
|
|
|
|
binary => 1, |
57
|
|
|
|
|
|
|
quote_char => '"', |
58
|
|
|
|
|
|
|
escape_char => "\\", |
59
|
|
|
|
|
|
|
}) or die "Cannot use CSV: ".Text::CSV->error_diag (); |
60
|
|
|
|
|
|
|
|
61
|
2681
|
50
|
|
|
|
304901
|
if ($self->file_format eq 'TSV') { |
62
|
0
|
|
|
|
|
0
|
$csv->sep_char("\t"); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
2681
|
50
|
|
|
|
6554
|
if (my $status = $csv->parse($self->{_line})) { |
66
|
2681
|
|
|
|
|
86579
|
return ($csv->fields)[$index]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} elsif ($self->file_format eq 'FIXED') { |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $map = $self->field_map; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# if the line is not long enough to handle the start of the field, |
74
|
|
|
|
|
|
|
# it is an optional field that we don't have |
75
|
0
|
0
|
|
|
|
|
if (length($self->{_line}) < $map->[0]) { |
76
|
0
|
|
|
|
|
|
return ''; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $ret = substr($self->{_line}, $map->[0] - 1, $map->[1]); |
80
|
0
|
|
|
|
|
|
$ret =~ s{\s+\z}{}; |
81
|
0
|
|
|
|
|
|
return $ret; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |