| 1 | package Business::NAB::Australian::DirectEntry::Payments::DescriptiveRecord; | ||||||||||
| 2 | 4 | $Business::NAB::Australian::DirectEntry::Payments::DescriptiveRecord::VERSION = '0.11'; | |||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Business::NAB::Australian::DirectEntry::Payments::DescriptiveRecord | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | use Business::NAB::Australian::DirectEntry::Payments::DescriptiveRecord; | ||||||||||
| 10 | |||||||||||
| 11 | # parse | ||||||||||
| 12 | my $Record = Business::NAB::Australian::DirectEntry | ||||||||||
| 13 | ::Payments::DescriptiveRecord->new_from_record( $line ); | ||||||||||
| 14 | |||||||||||
| 15 | # create | ||||||||||
| 16 | my $Record = Business::NAB::Australian::DirectEntry | ||||||||||
| 17 | ::Payments::DescriptiveRecord->new( | ||||||||||
| 18 | reel_sequence_number => '01', | ||||||||||
| 19 | institution_name => 'NAB', | ||||||||||
| 20 | user_name => 'NAB TEST', | ||||||||||
| 21 | user_number => 123456, | ||||||||||
| 22 | description => 'DrDebit', | ||||||||||
| 23 | process_date => DateTime->now, | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | my $line = $Record->to_record; | ||||||||||
| 27 | |||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||
| 29 | |||||||||||
| 30 | Class for descriptive record in the "Australian Direct Entry Payments and | ||||||||||
| 31 | Dishonour report" | ||||||||||
| 32 | |||||||||||
| 33 | =cut; | ||||||||||
| 34 | |||||||||||
| 35 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 4 | ▶ | use feature qw/ signatures /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | |||||||||||
| 39 | 4 | ▶ | use Carp qw/ croak /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 4 | ▶ | use Business::NAB::Types qw/ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | add_max_string_attribute | ||||||||||
| 43 | 4 | /; | |||||||||
| 44 | |||||||||||
| 45 | 4 | ▶ | no warnings qw/ experimental::signatures /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | |||||||||||
| 47 | =head1 ATTRIBUTES | ||||||||||
| 48 | |||||||||||
| 49 | =over | ||||||||||
| 50 | |||||||||||
| 51 | =item process_date (NAB::Type::Date, coerced from Str) | ||||||||||
| 52 | |||||||||||
| 53 | =item reel_sequence_number (Int, max 99) | ||||||||||
| 54 | |||||||||||
| 55 | =item institution_name (Str, max length 3) | ||||||||||
| 56 | |||||||||||
| 57 | =item user_name (Str, max length 26) | ||||||||||
| 58 | |||||||||||
| 59 | =item user_number (Str, max length 6) | ||||||||||
| 60 | |||||||||||
| 61 | =item description (Str, max length 12) | ||||||||||
| 62 | |||||||||||
| 63 | =back | ||||||||||
| 64 | |||||||||||
| 65 | =cut | ||||||||||
| 66 | |||||||||||
| 67 | 4 | has [ | |||||||||
| 68 | qw/ | ||||||||||
| 69 | process_date | ||||||||||
| 70 | / | ||||||||||
| 71 | ] => ( | ||||||||||
| 72 | is => 'ro', | ||||||||||
| 73 | isa => 'NAB::Type::Date', | ||||||||||
| 74 | required => 1, | ||||||||||
| 75 | coerce => 1, | ||||||||||
| 76 | ); | ||||||||||
| 77 | |||||||||||
| 78 | 4 | foreach my $str_attr ( | |||||||||
| 79 | 'reel_sequence_number[2:trim_leading_zeros]', | ||||||||||
| 80 | 'institution_name[3]', | ||||||||||
| 81 | 'user_name[26]', | ||||||||||
| 82 | 'user_number[6]', | ||||||||||
| 83 | 'description[12]', | ||||||||||
| 84 | ) { | ||||||||||
| 85 | 20 | __PACKAGE__->add_max_string_attribute( | |||||||||
| 86 | $str_attr, | ||||||||||
| 87 | is => 'ro', | ||||||||||
| 88 | required => 1, | ||||||||||
| 89 | ); | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 11 | ▶ | sub _pack_template { | ||||||||
|
Subroutine
_pack_template: called CC=1 SCAR=0.0
| |||||||||||
| 93 | 11 | return "A1 A17 A2 A3 A7 A26 A6 A12 A6 A40"; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 11 | ▶ | sub record_type { 0 } | ||||||||
|
Subroutine
record_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 97 | |||||||||||
| 98 | =head1 METHODS | ||||||||||
| 99 | |||||||||||
| 100 | =head2 new_from_record | ||||||||||
| 101 | |||||||||||
| 102 | Returns a new instance of the class with attributes populated from | ||||||||||
| 103 | the result of parsing the passed line: | ||||||||||
| 104 | |||||||||||
| 105 | my $Record = Business::NAB::Australian::DirectEntry | ||||||||||
| 106 | ::Payments::DescriptiveRecord->new_from_record( $line ); | ||||||||||
| 107 | |||||||||||
| 108 | =cut | ||||||||||
| 109 | |||||||||||
| 110 | 5 | ▶ | sub new_from_record ( $class, $line ) { | ||||||||
|
Subroutine
new_from_record: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 111 | |||||||||||
| 112 | # undef being "this space intentionally left blank" | ||||||||||
| 113 | my ( | ||||||||||
| 114 | 5 | $record_type, | |||||||||
| 115 | undef, | ||||||||||
| 116 | $reel_sequence_number, | ||||||||||
| 117 | $institution_name, | ||||||||||
| 118 | undef, | ||||||||||
| 119 | $user_name, | ||||||||||
| 120 | $user_number, | ||||||||||
| 121 | $description, | ||||||||||
| 122 | $date, | ||||||||||
| 123 | undef, | ||||||||||
| 124 | ) = unpack( $class->_pack_template(), $line ); | ||||||||||
| 125 | |||||||||||
| 126 | 5 | ▶ | if ( $record_type ne $class->record_type ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | 1 | croak( "unsupported record type ($record_type)" ); | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | 4 | return $class->new( | |||||||||
| 131 | reel_sequence_number => $reel_sequence_number, | ||||||||||
| 132 | institution_name => $institution_name, | ||||||||||
| 133 | user_name => $user_name, | ||||||||||
| 134 | user_number => $user_number, | ||||||||||
| 135 | description => $description, | ||||||||||
| 136 | process_date => $date, | ||||||||||
| 137 | ); | ||||||||||
| 138 | } | ||||||||||
| 139 | |||||||||||
| 140 | =head2 to_record | ||||||||||
| 141 | |||||||||||
| 142 | Returns a string constructed from the object's attributes, representing | ||||||||||
| 143 | the record for use in a batch file: | ||||||||||
| 144 | |||||||||||
| 145 | my $line = $Record->to_record; | ||||||||||
| 146 | |||||||||||
| 147 | =cut | ||||||||||
| 148 | |||||||||||
| 149 | 6 | ▶ | sub to_record ( $self ) { | ||||||||
|
Subroutine
to_record: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 150 | |||||||||||
| 151 | 6 | my $record = pack( | |||||||||
| 152 | $self->_pack_template(), | ||||||||||
| 153 | $self->record_type, | ||||||||||
| 154 | "", | ||||||||||
| 155 | sprintf( "%02s", $self->reel_sequence_number ), | ||||||||||
| 156 | $self->institution_name, | ||||||||||
| 157 | "", | ||||||||||
| 158 | $self->user_name, | ||||||||||
| 159 | sprintf( "%06s", $self->user_number ), | ||||||||||
| 160 | $self->description, | ||||||||||
| 161 | $self->process_date->strftime( '%d%m%y' ), | ||||||||||
| 162 | "", | ||||||||||
| 163 | ); | ||||||||||
| 164 | |||||||||||
| 165 | 6 | return $record; | |||||||||
| 166 | } | ||||||||||
| 167 | |||||||||||
| 168 | =head1 SEE ALSO | ||||||||||
| 169 | |||||||||||
| 170 | L<Business::NAB::Types> | ||||||||||
| 171 | |||||||||||
| 172 | =cut | ||||||||||
| 173 | |||||||||||
| 174 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||