NAB/BPAY/Payments/DetailRecord.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 2 / 2 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 96.8% 61 / 63 CC 5 SCAR 7.0
CC
5
Cov
98%
to_record
4.0
new_from_record
2.0
BEGIN
1.0
CRAP 2.0
« NAB/BPAY/Payments.pm ↑ Summary NAB/BPAY/Payments/Results/DetailRecord.pm »
1 package Business::NAB::BPAY::Payments::DetailRecord;
2 5 $Business::NAB::BPAY::Payments::DetailRecord::VERSION = '0.11';
3 =head1 NAME
4  
5 Business::NAB::BPAY::Payments::DetailRecord
6  
7 =head1 SYNOPSIS
8  
9 use Business::NAB::BPAY::Payments::DetailRecord;
10  
11 # parse
12 my $Detail = Business::NAB::BPAY::Payments::DetailRecord;
13 ->new_from_record( $line );
14  
15 # create
16 my $Detail = Business::NAB::BPAY::Payments::DetailRecord->new(
17 biller_code => $biller_code,
18 payment_account_bsb => $payment_account_bsb,
19 payment_account_number => $payment_account_number,
20 customer_reference_number => $customer_reference_number,
21 amount => $amount,
22 lodgement_reference_1 => $lodgement_reference_1,
23 lodgement_reference_2 => $lodgement_reference_2,
24 lodgement_reference_3 => $lodgement_reference_3,
25 );
26  
27 my $line = $Detail->to_record;
28  
29 =head1 DESCRIPTION
30  
31 Class for detail record in the "BPAY Batch User Guide"
32  
33 =cut;
34  
35 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 ▶use feature qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 5 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 5 ▶use Business::NAB::Types qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
42 add_max_string_attribute
43 5 /;
44  
45 5 ▶no warnings qw/ experimental::signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 =head1 ATTRIBUTES
48  
49 =over
50  
51 =item biller_code (Str, max length 10)
52  
53 =item payment_account_bsb (NAB::Type::BSBNumberNoDash)
54  
55 =item payment_account_number (NAB::Type::AccountNumber)
56  
57 =item customer_reference_number (Str, max length 20)
58  
59 =item amount (NAB::Type::PositiveInt)
60  
61 =item lodgement_reference_1 (Str, max length 10, optional)
62  
63 =item lodgement_reference_2 (Str, max length 20, optional)
64  
65 =item lodgement_reference_3 (Str, max length 50, optional)
66  
67 =back
68  
69 =cut
70  
71 5 has [ qw/ payment_account_bsb / ] => (
72 is => 'ro',
73 isa => 'NAB::Type::BSBNumberNoDash',
74 required => 1,
75 coerce => 1,
76 );
77  
78 5 has [ qw/ payment_account_number / ] => (
79 is => 'ro',
80 isa => 'NAB::Type::AccountNumber',
81 required => 1,
82 );
83  
84 5 has [ qw/ amount / ] => (
85 is => 'ro',
86 isa => 'NAB::Type::PositiveInt',
87 required => 1,
88 );
89  
90 5 foreach my $str_attr (
91 'biller_code[10]',
92 'customer_reference_number[20]',
93 ) {
94 10 __PACKAGE__->add_max_string_attribute(
95 $str_attr,
96 is => 'ro',
97 required => 1,
98 );
99 }
100  
101 5 foreach my $str_attr (
102 'lodgement_reference_1[10]',
103 'lodgement_reference_2[20]',
104 'lodgement_reference_3[50]',
105 ) {
106 15 __PACKAGE__->add_max_string_attribute(
107 $str_attr,
108 is => 'ro',
109 required => 0,
110 );
111 }
112  
113 24 ▶sub _pack_template {
Subroutine _pack_template: called CC=1 SCAR=0.0
114 24 return "A1 A10 A6 A9 A20 A13 A10 A20 A50 A5";
115 }
116  
117 =head1 METHODS
118  
119 =head2 new_from_record
120  
121 Returns a new instance of the class with attributes populated from
122 the result of parsing the passed line:
123  
124 my $Record = Business::NAB::BPAY::Payments::DetailRecord
125 ->new_from_record( $line );
126  
127 =cut
128  
129 7 ▶sub new_from_record ( $class, $line ) {
Subroutine new_from_record: called CC=2 SCAR=6.9
Pod documented
130  
131 # undef being "this space intentionally left blank"
132 my (
133 7 $record_type,
134 $biller_code,
135 $payment_account_bsb,
136 $payment_account_number,
137 $customer_reference_number,
138 $amount,
139 $lodgement_reference_1,
140 $lodgement_reference_2,
141 $lodgement_reference_3,
142 undef,
143 ) = unpack( $class->_pack_template(), $line );
144  
145 7 ▶ if ( $record_type ne '2' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record_type ne 2) 1 6 7
146 1 croak( "unsupported record type ($record_type)" );
147 }
148  
149 6 $biller_code =~ s/^0+//;
150 6 $amount =~ s/^0+//;
151  
152 6 return $class->new(
153 biller_code => $biller_code,
154 payment_account_bsb => $payment_account_bsb,
155 payment_account_number => $payment_account_number,
156 customer_reference_number => $customer_reference_number,
157 amount => $amount,
158 lodgement_reference_1 => $lodgement_reference_1,
159 lodgement_reference_2 => $lodgement_reference_2,
160 lodgement_reference_3 => $lodgement_reference_3,
161 );
162 }
163  
164 =head2 to_record
165  
166 Returns a string constructed from the object's attributes, representing
167 the record for use in a batch file:
168  
169 my $line = $Detail->to_record;
170  
171 =cut
172  
173 17 ▶sub to_record ( $self ) {
Subroutine to_record: called CC=4 SCAR=13.9
Pod documented
174  
175 # remove the - char (well, any non-digits). the various specs are
176 # a bit all over the place, some keep this char and some don't
177 17 my $bsb = $self->payment_account_bsb =~ s/\D//gr;
178  
179 17 ▶ my $record = pack(
Condition83%5/6
$self->lodgement_reference_1 // ""
l!l
170
$self->lodgement_reference_2 // ""
l!l
512
$self->lodgement_reference_3 // ""
l!l
512
MC/DC0%0/1
$self->lodgement_reference_1 // ""
$self->lodgement_reference_1
MC/DC100%1/1
$self->lodgement_reference_2 // ""
$self->lodgement_reference_2
MC/DC100%1/1
$self->lodgement_reference_3 // ""
$self->lodgement_reference_3
Truth table50%1/2
A
A= $self->lodgement_reference_1
Aresult
11
00
Truth table100%2/2
A
A= $self->lodgement_reference_2
Aresult
11
00
Truth table100%2/2
A
A= $self->lodgement_reference_3
Aresult
11
00
180 $self->_pack_template(),
181 "2",
182 sprintf( "%010s", $self->biller_code ),
183 $bsb,
184 $self->payment_account_number,
185 $self->customer_reference_number,
186 sprintf( "%013.0f", $self->amount ),
187 $self->lodgement_reference_1 // '',
188 $self->lodgement_reference_2 // '',
189 $self->lodgement_reference_3 // '',
190 );
191  
192 17 return $record;
193 }
194  
195 =head1 SEE ALSO
196  
197 L<Business::NAB::Types>
198  
199 =cut
200  
201 5 __PACKAGE__->meta->make_immutable;
« NAB/BPAY/Payments.pm ↑ Summary NAB/BPAY/Payments/Results/DetailRecord.pm »