NAB/BPAY/Payments/HeaderRecord.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 100% 47 / 47 CC 2 SCAR 1.7
CC
2
Cov
100%
new_from_record
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« NAB/Australian/DirectEntry/Report/PaymentRecord.pm ↑ Summary NAB/BPAY/Payments/Results/TrailerRecord.pm »
1 package Business::NAB::BPAY::Payments::HeaderRecord;
2 5 $Business::NAB::BPAY::Payments::HeaderRecord::VERSION = '0.11';
3 =head1 NAME
4  
5 Business::NAB::BPAY::Payments::HeaderRecord
6  
7 =head1 SYNOPSIS
8  
9 use Business::NAB::BPAY::Payments::HeaderRecord;
10  
11 # parse
12 my $Header = Business::NAB::BPAY::Payments::HeaderRecord
13 ->new_from_record( $line );
14  
15 # create
16 my $Header = Business::NAB::BPAY::Payments::HeaderRecord->new(
17 bpay_batch_user_id => '01',
18 customer_short_name => 'NAB',
19 processing_date => DateTime->now,
20 );
21  
22 my $line = $Header->to_record;
23  
24 =head1 DESCRIPTION
25  
26 Class for header record in the "BPAY Batch User Guide"
27  
28 =cut;
29  
30 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use feature qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 5 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 5 ▶use Business::NAB::Types qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
37 add_max_string_attribute
38 5 /;
39  
40 5 ▶no warnings qw/ experimental::signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 =head1 ATTRIBUTES
43  
44 =over
45  
46 =item bpay_batch_user_id (Str, max length 16)
47  
48 =item processing_date (NAB::Type::StatementDate, coerced from Str)
49  
50 =item customer_short_name (Str, max length 20)
51  
52 =back
53  
54 =cut
55  
56 5 has [
57 qw/
58 processing_date
59 /
60 ] => (
61 is => 'ro',
62 isa => 'NAB::Type::StatementDate',
63 required => 1,
64 coerce => 1,
65 );
66  
67 5 foreach my $str_attr (
68 'bpay_batch_user_id[16]',
69 'customer_short_name[20]',
70 ) {
71 10 __PACKAGE__->add_max_string_attribute(
72 $str_attr,
73 is => 'ro',
74 required => 1,
75 );
76 }
77  
78 15 ▶sub _pack_template {
Subroutine _pack_template: called CC=1 SCAR=0.0
79 15 return "A1 A16 A20 A8 A99";
80 }
81  
82 =head1 METHODS
83  
84 =head2 new_from_record
85  
86 Returns a new instance of the class with attributes populated from
87 the result of parsing the passed line:
88  
89 my $Record = Business::NAB::BPAY::Payments::HeaderRecord
90 ->new_from_record( $line );
91  
92 =cut
93  
94 6 ▶sub new_from_record ( $class, $line ) {
Subroutine new_from_record: called CC=2 SCAR=6.9
Pod documented
95  
96 # undef being "this space intentionally left blank"
97 my (
98 6 $record_type,
99 $bpay_batch_user_id,
100 $customer_short_name,
101 $processing_date,
102 undef,
103 ) = unpack( $class->_pack_template(), $line );
104  
105 6 ▶ if ( $record_type ne '1' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record_type ne 1) 2 4 6
106 2 croak( "unsupported record type ($record_type)" );
107 }
108  
109 4 return $class->new(
110 bpay_batch_user_id => $bpay_batch_user_id,
111 customer_short_name => $customer_short_name,
112 processing_date => $processing_date,
113 );
114 }
115  
116 =head2 to_record
117  
118 Returns a string constructed from the object's attributes, representing
119 the record for use in a batch file:
120  
121 my $line = $Header->to_record;
122  
123 =cut
124  
125 9 ▶sub to_record ( $self ) {
Subroutine to_record: called CC=1 SCAR=0.0
Pod documented
126  
127 9 my $record = pack(
128 $self->_pack_template(),
129 "1",
130 $self->bpay_batch_user_id,
131 $self->customer_short_name,
132 $self->processing_date->strftime( '%Y%m%d' ),
133 "",
134 );
135  
136 9 return $record;
137 }
138  
139 =head1 SEE ALSO
140  
141 L<Business::NAB::Types>
142  
143 =cut
144  
145 5 __PACKAGE__->meta->make_immutable;
« NAB/Australian/DirectEntry/Report/PaymentRecord.pm ↑ Summary NAB/BPAY/Payments/Results/TrailerRecord.pm »