NAB/BPAY/Payments/TrailerRecord.pm

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