blib/lib/ACH/Generator.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 70 CC 5 SCAR 27.7
CC
5
Cov
0%
ACH::generate
30.0
_croak
2.0
BEGIN
2.0
CRAP 16.0
1 package ACH::Generator;
2
3 $VERSION = '0.01';
4
5 use strict;
6 use warnings;
7
8 use ACH;
9
10 sub _croak { require Carp; Carp::croak(@_) }
11
12 =head1 NAME
13
14 ACH::Generator - Generates an ACH formatted file from an ACH perl object
15
16 =head1 VERSION
17
18 Version: 0.01
19 May 2006
20
21 =head1 DESCRIPTION
22
23 ACH::Generator is a simple, generic subclass of ACH used to generate ACH files.
24 It's intentional use is for testing purposes ONLY. ACH-Generator will allow a
25 developer to create an ACH formatted file.
26
27 =head1 USING ACH-Generator
28
29 use ACH::Generator;
30
31 my $newACH = new ACH;
32 my $newACHfile = 'newACHFile.ACH'; # The name of the ACH file to be generated
33
34 ...
35
36 $newACH->generate($newACHfile);
37
38 =head1 METHODS
39
40 =head2 generate
41
42 Generates an ACH file from the data in the ACH object
43
44 =cut
45
46 # Generate the ACH file
47 sub ACH::generate {
48 # Get the file name
49 my $self = shift;
50 my $file = shift or _croak "Need an ACH file";
51
52 # File data
53 my $data = "";
54
55 # Iterate through the ACH Data
56 foreach my $item (@{$self->{_achData}}) { # Array of ACH file Sections
57 my @achSections = map { defined $_ ? $_ : '' } @{$item};
58 my $sectionValue = 0;
59
60 for (my $y=0; $y < @achSections; $y++) { # Array of ACH file Section data
61 my %hash = map { defined $_ ? $_ : '' } %{$achSections[$y]};
62
63 # Use the appropriate file Format size for the appropriate ACH file section
64 foreach my $hashItem (keys (%hash)) { # Hash containing the ACH field name and value
65 chomp $hash{$hashItem};
66 my $dataValue = "";
67
68 # Get the section header in the first field, else get the data
69 if ($y == 0) { $dataValue = $sectionValue = $hash{$hashItem}; }
70 else {
71 # Get the field length and data
72 my $field = ${$self->{_achFormats}{$sectionValue}}[$y];
73 my ($field_length); while ( my ($key, $value) = each(%$field) ) { $field_length = $value; }
74 $dataValue = substr($hash{$hashItem}, 0, $field_length);
75 }
76
77 # Store the data in the file data variable
78 $data .= $dataValue;
79 }
80 }
81 }
82
83 # Open the file
84 if ( open(OUTPUT, ">$file") ) {}
85 else { print "Error: Couldn't open file $file\n"; die; }
86
87 # Print data out to ACH file
88 print OUTPUT "$data";
89
90 # Close the ACH file
91 close (OUTPUT);
92 }
93
94
95 =head2 CAVEATS
96
97 This package is created for testing purposes only. It shouldn't be used
98 for production programs or scripts. There are other commercial products
99 out there that may be a more efficient solution for accomplishing your
100 goals.
101
102 All records in an ACH file must be formatted in the following sequence
103 of records. IF the file is not formatted in this exact sequence, it
104 may be rejected.
105
106 ACH File Layout:
107 1 - File Header Record
108 5 - First Company/Batch Header Record
109 6 - First Entry Detail Record
110 7 - First Entry Detail Addenda Record (optional)
111 |
112 Multiples of Entry Detail Records
113 |
114 6 - Last Entry Detail Record
115 7 - Last Entry Detail Addenda Record (optional)
116 8 - First Company/Batch Control Record
117 |
118 Multiples of Company/Batches
119 |
120 5 - Last Company/Batch Header Record
121 6 - First Entry Detail Record
122 7 - First Entry Detail Addenda Record (optional)
123 |
124 Multiples of Entry Detail Records
125 |
126 6 - Last Entry Detail Record
127 7 - Last Entry Detail Addenda Record (optional)
128 8 - Last Company/Batch Control Record
129 9 - File Control Record
130 9999...9999 (optional)
131
132 =head1 AUTHOR
133
134 Author: Christopher Kois
135 Date: May, 2006
136 Contact: cpkois@cpan.org
137
138 =head1 COPYRIGHTS
139
140 The ACH-Generator module is Copyright (c) May, 2006 by Christopher Kois.
141 http://www.christopherkois.com All rights reserved. You may distribute this
142 module under the terms of GNU General Public License (GPL).
143
144 =head1 SUPPORT/WARRANTY
145
146 ACH-Generator is free Open Source software. IT COMES WITHOUT WARRANTY OR SUPPORT OF ANY KIND.
147
148 =head1 KNOWN BUGS
149
150 This is version 0.01 of ACH::Generator. There are currently no known bugs.
151
152 =head1 SEE ALSO
153
154 L<ACH>. L<ACH::Parser>
155
156 =cut
157
158 1;