blib/lib/No/Giro.pm

filter: Statementstmt 22.5% 16 / 71 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod 100% 2 / 2 totaltotal 21.1% 22 / 104 CC 15 SCAR 38.0
CC
15
Cov
17%
eps
72.0
AUTOLOAD
56.0
new
6.0
CRAP 44.8
↑ Summary
1 package No::Giro;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use PostScript::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 our $AUTOLOAD; # it's a package global
10  
11 1 our $VERSION = '0.21';
12  
13  
14  
15 =head1 NAME
16  
17 No::Giro - Perl Module for generating Norwegian bank slips
18  
19 =head1 SYNOPSIS
20  
21 use No::Giro;
22 use PostScript::Simple;
23 my $p = new PostScript::Simple(papersize => "A4",
24 colour => 0,
25 eps => 0,
26 units => "mm");
27 $p->newpage;
28 my $giro = new No::Giro;
29 $giro->kid(242345);
30 $giro->belop(4534);
31 $giro->tilkonto(12345678901);
32 $giro->bettil(["Payme", 'Somewhere', '4932 Place']);
33 my $e = $giro->eps;
34 $p->importeps($e, 0,0);
35 $p->output("giro.ps");
36  
37  
38 =head1 DESCRIPTION
39  
40 It provides some methods to enter data into a standard F60-1 GIRO
41 slip. This is an A4 sheet with a standard layout and where data are
42 entered at the bottom and there is some space to enter any information
43 at the top. It returns an Encapsulated Postscript object that can be
44 used in a Postscript document, which again is suitable to be printed.
45  
46  
47 =head2 Data Methods
48  
49 These are the accessor methods, they serve only the purpose of setting and retrieving the values of the data fields of the object.
50  
51 These methods have Norwegian-looking names, except for that they are abbreviations and has not Norwegian characters, so I suppose you need to be Norwegian to understand them, or grab someone who is...
52  
53 =over
54  
55 =item C<belop()>
56  
57 The amount of money to be paid.
58  
59 =item C<frist()>
60  
61 Date payment is due. Currently, it should be a simple string.
62  
63 =item C<betav()>
64  
65 Name and address of the person or institution making the payment. It is an array where each element represents a line. It takes 3-4 lines and does not attempt to check that it is within bounds.
66  
67 =item C<bettil()>
68  
69 Name and address of the person or institution getting the payment. Like above, it is an array where each element representing a line.
70  
71 =item C<betinf()>
72  
73 Payment information. This field can contain comments without any particular semantics. It is an array of strings, where each element represents an array. Each element should not exceed 40 characters, but only a warning is issued if it does.
74  
75  
76  
77 =item C<kid()>
78  
79 The customer identification number, or KID. You need agreements with the banking system to actually use this meaningfully. There are constraints on length of numbers and how they are to be computed. Contact your bank for details if you plan to use this.
80  
81 =item C<tilkonto()>
82  
83 The account number to be credited.
84  
85  
86  
87 =item C<betkonto()>
88  
89 The account number of the payer.
90  
91  
92 =item C<belkonto()>
93  
94 Does nothing.
95  
96 =item C<kvittering()>
97  
98 Does nothing.
99  
100 =back
101  
102 =cut
103  
104
105 1 my %fields = (
106 belop => undef,
107 betkonto => undef,
108 betinf => [],
109 frist => undef,
110 betav => [],
111 bettil => [],
112 belkonto => undef,
113 kid => undef,
114 tilkonto => undef,
115 kvittering => 0,
116 );
117  
118  
119  
120 =head2 Other Methods
121  
122 =over
123  
124 =item C<new()>
125  
126 The constructor of this class.
127  
128 =cut
129  
130
131 # Snip verbatim from perltoot by Tom Christiansen.
132 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
133 0 my $that = shift;
134 0 ▶ my $class = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
135 0 my $self = {
136 _permitted => \%fields,
137 %fields,
138 };
139 0 bless $self, $class;
140 0 return $self;
141 }
142  
143  
144  
145 # Uhm, because of my autoload method, I don't know what to do with the destructor, so I just do this....:
146 0 ▶sub DESTROY { # Do nothing
Subroutine DESTROY: not called CC=1 SCAR=0.0
147 }
148  
149  
150 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=7 SCAR=40.3
151 0 my $self = shift;
152 0 ▶ my $type = ref($self)
Branch: 1 branch
BranchTrueFalseTotal
my $type = ref $self or croak("$self is not an object") 0 0 0
153 or croak "$self is not an object";
154 0 my $name = $AUTOLOAD;
155 0 $name =~ s/.*://; # strip fully-qualified portion
156 0 ▶ unless (exists $self->{_permitted}->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_permitted"}{$name}) 0 0 0
157 0 croak "Can't access `$name' field in class $type";
158 }
159 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
160 0 my $entry = shift;
161 0 ▶ if ($name eq 'betinf') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "betinf") 0 0 0
162 0 my $i=1;
163 0 foreach my $line (@{$entry}) {
164 0 ▶ if (length($line) > 40) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $line > 40) 0 0 0
165 0 carp("Length of line $i in betinf() is longer than 40 characters. This is discouraged");
166 0 $i++;
167 }
168 }
169 }
170 0 return $self->{$name} = $entry;
171 } else {
172 0 return $self->{$name};
173 }
174 }
175  
176 =item C<eps>
177  
178 This method uses whatever data that has been previously set by the data methods, and puts them in appropriate positions, and returns a L<PostScript::Simple::EPS> object. You may then use this object to import in a L<PostScript::Simple> document, save it to a file or whatever. Just remember that it has to be imported at the very bottom of the an A4 page.
179  
180 =cut
181  
182  
183 0 ▶sub eps {
Subroutine eps: not called CC=8 SCAR=42.8
Pod documented
184 0 my $self = shift;
185 0 my $eps = new PostScript::Simple(
186 xsize => 206,
187 ysize => 123,
188 eps => 1,
189 units => "pt");
190  
191 0 my $kroner = int($self->{belop});
192 0 my $ore = int(($self->{belop} - $kroner) * 100);
193  
194 0 $eps->setfont("Courier-iso", 4);
195
196 0 $eps->text(1.8, 21.5, 'H');
197 0 $eps->text(20, 21.5, $self->{kid});
198 0 $eps->text(86, 21.5, $kroner);
199 0 ▶ if ($ore > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ore > 0) 0 0 0
200 0 $eps->text(108, 21.5, $ore);
201 }
202 0 $eps->text(132, 21.5, $self->{tilkonto});
203 0 $eps->text(86, 106, $self->{belop});
204 0 $eps->text(132, 106, $self->{betkonto});
205  
206 0 ▶ if($self->{betinf}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"betinf"}) 0 0 0
207 0 my $feed = 93;
208 0 foreach my $line (@{$self->{betinf}}) {
209 0 $eps->text(15, $feed, $line);
210 0 $feed-=4;
211 }
212 }
213  
214 0 ▶ if($self->{bettil}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bettil"}) 0 0 0
215 0 my $feed = 60;
216 0 foreach my $line (@{$self->{bettil}}) {
217 0 $eps->text(115, $feed, $line);
218 0 $feed-=4;
219 }
220 }
221  
222 0 ▶ if($self->{betav}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"betav"}) 0 0 0
223 0 my $feed = 60;
224 0 foreach my $line (@{$self->{betav}}) {
225 0 $eps->text(15, $feed, $line);
226 0 $feed-=4;
227 }
228 }
229
230 0 $eps->text(170, 95, $self->{frist});
231
232 0 return $eps->geteps();
233  
234 }
235  
236  
237 1 1;
238 __END__
↑ Summary