NAB/Australian/DirectEntry/Payments/TotalRecord.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 66.6% 2 / 3 totaltotal 98.1% 52 / 53 CC 2 SCAR 1.4
CC
2
Cov
100%
new_from_record
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« NAB/BPAY/Remittance/File/DetailRecord.pm ↑ Summary NAB/Australian/DirectEntry/Report/ValueSummary.pm »
1 package Business::NAB::Australian::DirectEntry::Payments::TotalRecord;
2 4 $Business::NAB::Australian::DirectEntry::Payments::TotalRecord::VERSION = '0.11';
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 4 ▶use feature qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 4 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 4 ▶use Business::NAB::Types qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
41 add_max_string_attribute
42 4 /;
43  
44 4 ▶no warnings qw/ experimental::signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 4 has [ qw/ bsb_number / ] => (
65 is => 'ro',
66 isa => 'NAB::Type::BSBNumber',
67 required => 1,
68 coerce => 1,
69 );
70  
71 4 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 32 ▶ trigger => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
84 32 my ( $self, $value, $old_value ) = @_;
85 32 $self->{ $attr } = int( $value );
86 },
87 16 );
88 }
89  
90 11 ▶sub _pack_template {
Subroutine _pack_template: called CC=1 SCAR=0.0
91 11 return "A1 A7 A12 A10 A10 A10 A24 A6 A40";
92 }
93  
94 9 ▶sub record_type { 7 }
Subroutine record_type: called CC=1 SCAR=0.0
Pod undocumented
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 5 ▶sub new_from_record ( $class, $line ) {
Subroutine new_from_record: called CC=2 SCAR=6.9
Pod documented
109  
110 # undef being "this space intentionally left blank"
111 my (
112 5 $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 5 ▶ if ( $record_type ne $class->record_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record_type ne $class->record_type) 1 4 5
123 1 croak( "unsupported record type ($record_type)" );
124 }
125  
126 4 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 6 ▶sub to_record ( $self ) {
Subroutine to_record: called CC=1 SCAR=0.0
Pod documented
145  
146 6 my $record = pack(
147 $self->_pack_template(),
148 $self->record_type,
149 $self->bsb_number,
150 "",
151 sprintf( "%010.0f", $self->net_total_amount ),
152 sprintf( "%010.0f", $self->credit_total_amount ),
153 sprintf( "%010.0f", $self->debit_total_amount ),
154 "",
155 sprintf( "%06.0f", $self->record_count ),
156 "",
157 );
158  
159 6 return $record;
160 }
161  
162 =head1 SEE ALSO
163  
164 L<Business::NAB::Types>
165  
166 =cut
167  
168 4 __PACKAGE__->meta->make_immutable;
« NAB/BPAY/Remittance/File/DetailRecord.pm ↑ Summary NAB/Australian/DirectEntry/Report/ValueSummary.pm »