| 1 | package Business::Westpac::Role::CSV; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Business::Westpac::Role::CSV | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use Moose; | ||
| 10 | with 'Business::Westpac::Role::CSV'; | ||
| 11 | |||
| 12 | =head1 DESCRIPTION | ||
| 13 | |||
| 14 | Role for CSV related attributes and functions used in the | ||
| 15 | Business::Westpac namespace | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | 12 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 12 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 12 | ▶ | use feature qw/ signatures /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | |||
| 23 | 12 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | 12 | ▶ | no warnings qw/ experimental::signatures /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 12 | ▶ | use Text::CSV; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | |||
| 27 | =head1 ATTRIBUTES | ||
| 28 | |||
| 29 | None yet | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | has _csv_encoder => ( | ||
| 34 | is => 'ro', | ||
| 35 | isa => 'Text::CSV', | ||
| 36 | lazy => 1, | ||
| 37 | 28 | ▶ | default => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 38 | 28 | Text::CSV->new({ | |
| 39 | binary => 1, | ||
| 40 | quote => '"', | ||
| 41 | always_quote => 1, | ||
| 42 | }); | ||
| 43 | } | ||
| 44 | 12 | ); | |
| 45 | |||
| 46 | =head1 METHODS | ||
| 47 | |||
| 48 | =head2 attributes_to_csv | ||
| 49 | |||
| 50 | Convert the list of attributes to a CSV line: | ||
| 51 | |||
| 52 | my @csv = $self->attributes_to_csv( qw/ | ||
| 53 | record_type | ||
| 54 | payment_amount | ||
| 55 | ... | ||
| 56 | / ); | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | 28 | ▶ | sub attributes_to_csv ( |
|
Subroutine
attributes_to_csv: called CC=1 SCAR=0.0
Pod
documented
| |||
| 61 | $self, | ||
| 62 | @attributes, | ||
| 63 | ) { | ||
| 64 | return $self->values_to_csv( | ||
| 65 | 28 | map { $self->$_ } @attributes | |
| 66 | ); | ||
| 67 | } | ||
| 68 | |||
| 69 | =head1 METHODS | ||
| 70 | |||
| 71 | =head2 values_to_csv | ||
| 72 | |||
| 73 | Convert the list of values to a CSV line: | ||
| 74 | |||
| 75 | my @csv = $self->values_to_csv( | ||
| 76 | $self->record_type, | ||
| 77 | $self->payment_amount, | ||
| 78 | ... | ||
| 79 | ); | ||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | 31 | ▶ | sub values_to_csv ( |
|
Subroutine
values_to_csv: called CC=1 SCAR=0.0
Pod
documented
| |||
| 84 | $self, | ||
| 85 | @values, | ||
| 86 | ) { | ||
| 87 | 31 | my $csv = $self->_csv_encoder; | |
| 88 | 31 | $csv->combine( @values ); | |
| 89 | 31 | return $csv->string; | |
| 90 | } | ||
| 91 | |||
| 92 | 12 | 1; | |