File Coverage

blib/lib/Business/NAB/BPAY/Payments/Results/TrailerRecord.pm
Criterion Covered Total %
statement 32 32 100.0
branch 2 2 100.0
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 45 45 100.0


line stmt bran cond sub pod time code
1             package Business::NAB::BPAY::Payments::Results::TrailerRecord;
2             $Business::NAB::BPAY::Payments::Results::TrailerRecord::VERSION = '0.03';
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::Results::TrailerRecord
13             ->new_from_record( $line );
14              
15             # create
16             my $Trailer = Business::NAB::BPAY::Payments::Results::TrailerRecord->new(
17             total_value_of_payments => 189915,
18             total_number_of_payments => 5,
19             total_number_of_successful_payments => 2,
20             total_value_of_successful_payments => 9914,
21             total_number_of_declined_payments => 3,
22             total_value_of_declined_payments => 180001,
23             );
24              
25             my $line = $Trailer->to_record;
26              
27             =head1 DESCRIPTION
28              
29             Class for trailer record in the "BPAY Batch User Guide" responses
30              
31             All methods and attributes are inherited from
32             L<Business::NAB::BPAY::Payments::TrailerRecord>
33              
34             =cut
35              
36 2     2   1879966 use strict;
  2         5  
  2         74  
37 2     2   10 use warnings;
  2         3  
  2         114  
38 2     2   12 use feature qw/ signatures /;
  2         3  
  2         267  
39              
40 2     2   1132 use Moose;
  2         1028382  
  2         20  
41             extends 'Business::NAB::BPAY::Payments::TrailerRecord';
42              
43 2     2   20492 use Carp qw/ croak /;
  2         5  
  2         157  
44              
45 2     2   16 no warnings qw/ experimental::signatures /;
  2         6  
  2         1291  
46              
47             =head1 ATTRIBUTES
48              
49             Additional attributes are inherited from
50             L<Business::NAB::BPAY::Payments::HeaderRecord>
51              
52             =over
53              
54             =item total_number_of_successful_payments (NAB::Type::PositiveIntOrZero)
55              
56             =item total_value_of_successful_payments (NAB::Type::PositiveIntOrZero)
57              
58             =item total_number_of_declined_payments (NAB::Type::PositiveIntOrZero)
59              
60             =item total_value_of_declined_payments (NAB::Type::PositiveIntOrZero)
61              
62             =back
63              
64             =cut
65              
66             foreach my $attr (
67             qw/
68             total_value_of_successful_payments
69             total_value_of_declined_payments
70             total_number_of_successful_payments
71             total_number_of_declined_payments
72             /
73             ) {
74             has $attr => (
75             is => 'ro',
76             isa => 'NAB::Type::PositiveIntOrZero',
77             required => 1,
78             trigger => sub {
79             my ( $self, $value, $old_value ) = @_;
80             $self->{ $attr } = int( $value );
81             },
82             );
83             }
84              
85             sub _pack_template {
86 7     7   296 return "A1 A10 A13 A10 A13 A10 A13";
87             }
88              
89 3     3 1 3069 sub new_from_record ( $class, $line ) {
  3         9  
  3         9  
  3         7  
90              
91             # undef being "this space intentionally left blank"
92             my (
93 3         14 $record_type,
94             $total_successful_number,
95             $total_successful_value,
96             $total_declined_number,
97             $total_declined_value,
98             $total_transactions,
99             $total_value,
100             ) = unpack( $class->_pack_template(), $line );
101              
102 3 100       18 if ( $record_type ne '9' ) {
103 1         22 croak( "unsupported record type ($record_type)" );
104             }
105              
106 2         114 return $class->new(
107             total_number_of_successful_payments => $total_successful_number,
108             total_value_of_successful_payments => $total_successful_value,
109             total_number_of_declined_payments => $total_declined_number,
110             total_value_of_declined_payments => $total_declined_value,
111             total_number_of_payments => $total_transactions,
112             total_value_of_payments => $total_value,
113             );
114             }
115              
116 4     4 1 8 sub to_record ( $self ) {
  4         7  
  4         7  
117              
118 4         17 my $record = pack(
119             $self->_pack_template(),
120             "9",
121             sprintf( "%010s", $self->total_number_of_successful_payments ),
122             sprintf( "%013s", $self->total_value_of_successful_payments ),
123             sprintf( "%010s", $self->total_number_of_declined_payments ),
124             sprintf( "%013s", $self->total_value_of_declined_payments ),
125             sprintf( "%010s", $self->total_number_of_payments ),
126             sprintf( "%013s", $self->total_value_of_payments ),
127             );
128              
129 4         20 return $record;
130             }
131              
132             =head1 SEE ALSO
133              
134             L<Business::NAB::Types>
135              
136             L<Business::NAB::BPAY::Payments::TrailerRecord>
137              
138             =cut
139              
140             __PACKAGE__->meta->make_immutable;