File Coverage

blib/lib/Business/NAB/Australian/DirectEntry/Payments/TotalRecord.pm
Criterion Covered Total %
statement 36 36 100.0
branch 2 2 100.0
condition n/a
subroutine 11 11 100.0
pod 2 3 66.6
total 51 52 98.0


line stmt bran cond sub pod time code
1             package Business::NAB::Australian::DirectEntry::Payments::TotalRecord;
2             $Business::NAB::Australian::DirectEntry::Payments::TotalRecord::VERSION = '0.03';
3             =head1 NAME
4              
5             Business::NAB::Australian::DirectEntry::Payments::TotalRecord
6              
7             =head1 SYNOPSIS
8              
9             use Business::NAB::Australian::DirectEntry::Payments::TotalRecord;
10              
11             # parse
12             my $Record = Business::NAB::Australian::DirectEntry
13             ::Payments::TotalRecord->new_from_record( $line );
14              
15             # create
16             my $Record = Business::NAB::Australian::DirectEntry
17             ::Payments::TotalRecord->new(
18             bsb_number => '123-456',
19             net_total_amount => 33333,
20             credit_total_amount => 11111,
21             debit_total_amount => 22222,
22             record_count => 10,
23             );
24              
25             my $line = $Record->to_record;
26              
27             =head1 DESCRIPTION
28              
29             Class for total record in the "Australian Direct Entry Payments and
30             Dishonour report"
31              
32             =cut;
33              
34 4     4   1033396 use strict;
  4         12  
  4         198  
35 4     4   24 use warnings;
  4         10  
  4         285  
36 4     4   27 use feature qw/ signatures /;
  4         9  
  4         614  
37              
38 4     4   30 use Carp qw/ croak /;
  4         11  
  4         335  
39 4     4   710 use Moose;
  4         610543  
  4         35  
40 4         372 use Business::NAB::Types qw/
41             add_max_string_attribute
42 4     4   35079 /;
  4         14  
43              
44 4     4   28 no warnings qw/ experimental::signatures /;
  4         11  
  4         2414  
45              
46             =head1 ATTRIBUTES
47              
48             =over
49              
50             =item bsb_number (NAB::Type::BSBNumber)
51              
52             =item net_total_amount (NAB::Type::PositiveIntOrZero)
53              
54             =item credit_total_amount (NAB::Type::PositiveIntOrZero)
55              
56             =item debit_total_amount (NAB::Type::PositiveIntOrZero)
57              
58             =item record_count (NAB::Type::PositiveIntOrZero)
59              
60             =back
61              
62             =cut
63              
64             has [ qw/ bsb_number / ] => (
65             is => 'ro',
66             isa => 'NAB::Type::BSBNumber',
67             required => 1,
68             coerce => 1,
69             );
70              
71             foreach my $attr (
72             qw/
73             net_total_amount
74             credit_total_amount
75             debit_total_amount
76             record_count
77             /
78             ) {
79             has $attr => (
80             is => 'ro',
81             isa => 'NAB::Type::PositiveIntOrZero',
82             required => 1,
83             trigger => sub {
84             my ( $self, $value, $old_value ) = @_;
85             $self->{ $attr } = int( $value );
86             },
87             );
88             }
89              
90             sub _pack_template {
91 9     9   70 return "A1 A7 A12 A10 A10 A10 A24 A6 A40";
92             }
93              
94 7     7 0 216 sub record_type { 7 }
95              
96             =head1 METHODS
97              
98             =head2 new_from_record
99              
100             Returns a new instance of the class with attributes populated from
101             the result of parsing the passed line:
102              
103             my $Record = Business::NAB::Australian::DirectEntry
104             ::Payments::TotalRecord->new_from_record( $line );
105              
106             =cut
107              
108 4     4 1 25372 sub new_from_record ( $class, $line ) {
  4         14  
  4         11  
  4         10  
109              
110             # undef being "this space intentionally left blank"
111             my (
112 4         34 $record_type,
113             $bsb_number,
114             undef,
115             $net_total_amount,
116             $credit_total_amount,
117             $debit_total_amount,
118             undef,
119             $record_count,
120             ) = unpack( $class->_pack_template(), $line );
121              
122 4 100       26 if ( $record_type ne $class->record_type ) {
123 1         22 croak( "unsupported record type ($record_type)" );
124             }
125              
126 3         246 return $class->new(
127             bsb_number => $bsb_number,
128             net_total_amount => $net_total_amount,
129             credit_total_amount => $credit_total_amount,
130             debit_total_amount => $debit_total_amount,
131             record_count => $record_count,
132             );
133             }
134              
135             =head2 to_record
136              
137             Returns a string constructed from the object's attributes, representing
138             the record for use in a batch file:
139              
140             my $line = $Record->to_record;
141              
142             =cut
143              
144 5     5 1 13 sub to_record ( $self ) {
  5         11  
  5         10  
145              
146 5         30 my $record = pack(
147             $self->_pack_template(),
148             $self->record_type,
149             $self->bsb_number,
150             "",
151             sprintf( "%010s", $self->net_total_amount ),
152             sprintf( "%010s", $self->credit_total_amount ),
153             sprintf( "%010s", $self->debit_total_amount ),
154             "",
155             sprintf( "%06s", $self->record_count ),
156             "",
157             );
158              
159 5         66 return $record;
160             }
161              
162             =head1 SEE ALSO
163              
164             L<Business::NAB::Types>
165              
166             =cut
167              
168             __PACKAGE__->meta->make_immutable;