| 1 | package Finance::Bank::Bankwest::Parser::TransactionExport; | ||||||||||||||
| 2 | # ABSTRACT: transaction CSV export parser | ||||||||||||||
| 3 | 9 | $Finance::Bank::Bankwest::Parser::TransactionExport::VERSION = '1.2.8'; | |||||||||||||
| 4 | |||||||||||||||
| 5 | ## no critic (RequireUseStrict, RequireUseWarnings, RequireEndWithOne) | ||||||||||||||
| 6 | 10 | ▶ | use MooseX::Declare; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 10 | ▶ | use HTTP::Response::Switch::Handler 1.000000; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | class Finance::Bank::Bankwest::Parser::TransactionExport | ||||||||||||||
| 9 | with HTTP::Response::Switch::Handler | ||||||||||||||
| 10 | 10 | ▶ | { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 10 | ▶ | use Finance::Bank::Bankwest::Transaction (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 10 | ▶ | use IO::String (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 10 | ▶ | use Text::CSV_XS 0.66 (); # for "empty_is_undef" attribute | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 10 | ▶ | method handle { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=6 SCAR=17.9
Subroutine
handle: called CC=6 SCAR=17.9
| |||||||||||||||
| 16 | 2 | ▶ | $self->decline | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 17 | if $self->response->headers->content_type ne 'text/csv'; | ||||||||||||||
| 18 | |||||||||||||||
| 19 | 1 | my $io = IO::String->new( $self->response->content_ref ); | |||||||||||||
| 20 | 1 | my $csv = Text::CSV_XS->new({ | |||||||||||||
| 21 | auto_diag => 2, | ||||||||||||||
| 22 | empty_is_undef => 1, | ||||||||||||||
| 23 | }); | ||||||||||||||
| 24 | 1 | $csv->column_names( $csv->getline($io) ); | |||||||||||||
| 25 | |||||||||||||||
| 26 | 1 | my @txns; | |||||||||||||
| 27 | 1 | ▶ | while (my $row = $csv->getline_hr($io)) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 28 | 8 | my $amount; | |||||||||||||
| 29 | 8 | for (qw{ Credit Debit }) { | |||||||||||||
| 30 | 16 | ▶ | next if not defined $row->{$_}; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 31 | 8 | $amount = $row->{$_}; | |||||||||||||
| 32 | 8 | ▶ | undef $amount if $amount == 0; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 33 | } | ||||||||||||||
| 34 | push @txns, Finance::Bank::Bankwest::Transaction->new( | ||||||||||||||
| 35 | date => $row->{'Transaction Date'}, | ||||||||||||||
| 36 | narrative => $row->{'Narration'}, | ||||||||||||||
| 37 | cheque_num => $row->{'Cheque Number'}, | ||||||||||||||
| 38 | amount => $amount, | ||||||||||||||
| 39 | 8 | type => $row->{'Transaction Type'}, | |||||||||||||
| 40 | ); | ||||||||||||||
| 41 | } | ||||||||||||||
| 42 | 1 | return @txns; | |||||||||||||
| 43 | 10 | } | |||||||||||||
| 44 | 10 | ▶ | } | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 45 | |||||||||||||||
| 46 | __END__ | ||||||||||||||