File Coverage

blib/lib/Business/NAB/BPAY/Remittance/File/HeaderRecord.pm
Criterion Covered Total %
statement 34 35 97.1
branch 1 2 50.0
condition n/a
subroutine 10 10 100.0
pod 2 2 100.0
total 47 49 95.9


line stmt bran cond sub pod time code
1             package Business::NAB::BPAY::Remittance::File::HeaderRecord;
2             $Business::NAB::BPAY::Remittance::File::HeaderRecord::VERSION = '0.03';
3             =head1 NAME
4              
5             Business::NAB::BPAY::Remittance::File::HeaderRecord
6              
7             =head1 SYNOPSIS
8              
9             use Business::NAB::BPAY::Remittance::File::HeaderRecord;
10              
11             # parse
12             my $Header = Business::NAB::BPAY::Remittance::File::HeaderRecord
13             ->new_from_record( $line );
14              
15             # create
16             my $Header = Business::NAB::BPAY::Remittance::File::HeaderRecord->new(
17             biller_code => ...
18             biller_short_name => ...
19             biller_credit_bsb => ...
20             biller_credit_account => ...
21             file_creation_date => ...
22             file_creation_time => ...
23             );
24              
25             my $line = $Header->to_record;
26              
27             =head1 DESCRIPTION
28              
29             Class for header record in the "BPAY Remittance File"
30              
31             =cut;
32              
33 1     1   1070 use strict;
  1         3  
  1         51  
34 1     1   6 use warnings;
  1         3  
  1         73  
35 1     1   7 use feature qw/ signatures /;
  1         2  
  1         198  
36              
37 1     1   9 use Carp qw/ croak /;
  1         4  
  1         66  
38 1     1   7 use Moose;
  1         30  
  1         10  
39 1         72 use Business::NAB::Types qw/
40             add_max_string_attribute
41 1     1   9635 /;
  1         2  
42              
43 1     1   7 no warnings qw/ experimental::signatures /;
  1         2  
  1         667  
44              
45             =head1 ATTRIBUTES
46              
47             =over
48              
49             =item biller_code (Str, max length 10)
50              
51             =item biller_short_name (Str, max length 20)
52              
53             =item biller_credit_bsb (NAB::Type::BSBNumberNoDash)
54              
55             =item biller_credit_account (NAB::Type::AccountNumber)
56              
57             =item file_creation_date (NAB::Type::StatementDate)
58              
59             =item file_creation_time (Str, max length 6)
60              
61             =back
62              
63             =cut
64              
65             foreach my $str_attr (
66             'biller_code[10]',
67             'biller_short_name[20]',
68             'file_creation_time[6]',
69             ) {
70             __PACKAGE__->add_max_string_attribute(
71             $str_attr,
72             is => 'ro',
73             required => 1,
74             );
75             }
76              
77             has [ qw/ biller_credit_bsb / ] => (
78             is => 'ro',
79             isa => 'NAB::Type::BSBNumberNoDash',
80             required => 1,
81             coerce => 1,
82             );
83              
84             has [ qw/ biller_credit_account / ] => (
85             is => 'ro',
86             isa => 'NAB::Type::AccountNumber',
87             required => 1,
88             );
89              
90             has [
91             qw/
92             file_creation_date
93             /
94             ] => (
95             is => 'ro',
96             isa => 'NAB::Type::StatementDate',
97             required => 1,
98             coerce => 1,
99             );
100              
101             sub _pack_template {
102 4     4   34 return "A2 A10 A20 A6 A9 A8 A6";
103             }
104              
105             =head1 METHODS
106              
107             =head2 new_from_record
108              
109             Returns a new instance of the class with attributes populated from
110             the result of parsing the passed line:
111              
112             my $Record = Business::NAB::BPAY::Remittance::File::HeaderRecord
113             ->new_from_record( $line );
114              
115             =cut
116              
117 1     1 1 4 sub new_from_record ( $class, $line ) {
  1         2  
  1         3  
  1         3  
118              
119             # undef being "this space intentionally left blank"
120             my (
121 1         4 $record_type,
122             $biller_code,
123             $biller_short_name,
124             $biller_credit_bsb,
125             $biller_credit_account,
126             $file_creation_date,
127             $file_creation_time,
128             ) = unpack( $class->_pack_template(), $line );
129              
130 1 50       5 if ( $record_type ne '00' ) {
131 0         0 croak( "unsupported record type ($record_type)" );
132             }
133              
134 1         100 return $class->new(
135             biller_code => $biller_code,
136             biller_short_name => $biller_short_name,
137             biller_credit_bsb => $biller_credit_bsb,
138             biller_credit_account => $biller_credit_account,
139             file_creation_date => $file_creation_date,
140             file_creation_time => $file_creation_time,
141             );
142             }
143              
144             =head2 to_record
145              
146             Returns a string constructed from the object's attributes, representing
147             the record for use in a batch file:
148              
149             my $line = $Header->to_record;
150              
151             =cut
152              
153 3     3 1 58 sub to_record ( $self ) {
  3         8  
  3         7  
154              
155 3         14 my $record = pack(
156             $self->_pack_template(),
157             "00",
158             $self->biller_code,
159             $self->biller_short_name,
160             $self->biller_credit_bsb,
161             $self->biller_credit_account,
162             $self->file_creation_date->ymd( '' ),
163             $self->file_creation_time,
164             );
165              
166 3         194 return $record;
167             }
168              
169             =head1 SEE ALSO
170              
171             L<Business::NAB::Types>
172              
173             =cut
174              
175             __PACKAGE__->meta->make_immutable;