line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Bank::FI::ReferenceNumber; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
1741
|
$Finance::Bank::FI::ReferenceNumber::AUTHORITY = 'cpan:OKKO'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
$Finance::Bank::FI::ReferenceNumber::VERSION = '0.004'; |
6
|
1
|
|
|
1
|
|
1021
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use namespace::autoclean; |
8
|
|
|
|
|
|
|
use utf8; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has '_reference_number' => (is => 'rw', isa => 'Int'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Finance::Bank::FI::ReferenceNumber - Calculate Finnish bank payment reference number (viitenumero) |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Calculate Finnish bank payment reference number. |
19
|
|
|
|
|
|
|
Laskee suomalaisen maksun viitenumeron. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#The number given in the argument must have a length of 3..19. |
24
|
|
|
|
|
|
|
my $ref = Finance::Bank::FI::ReferenceNumber->new('123'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
print "The reference number is " . $ref->get(); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
around BUILDARGS => sub { |
31
|
|
|
|
|
|
|
my $orig = shift; |
32
|
|
|
|
|
|
|
my $class = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if ( @_ == 1 && !ref $_[0] ) { |
35
|
|
|
|
|
|
|
return $class->$orig( number => $_[0] ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
|
|
|
|
|
|
return $class->$orig(@_); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub BUILD { |
43
|
|
|
|
|
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
my $args = shift; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Number is remittance info identifier, viitenumeron runko-osa in Finnish. |
47
|
|
|
|
|
|
|
my $ref = $args->{number}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $refsum = 0; |
50
|
|
|
|
|
|
|
my $reffactor = 7; |
51
|
|
|
|
|
|
|
for(my $i=length($ref)-1; $i >= 0; $i--) { |
52
|
|
|
|
|
|
|
$_ = substr($ref,$i,1); |
53
|
|
|
|
|
|
|
$refsum += $_ * $reffactor; |
54
|
|
|
|
|
|
|
$reffactor = ($reffactor==7)?3:($reffactor==3)?1:7; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
my $refcheck = ((10 - ($refsum % 10)) % 10); |
57
|
|
|
|
|
|
|
$ref .= $refcheck; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->_reference_number($ref); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 get |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Returns the reference number consisting of the number given for new() |
67
|
|
|
|
|
|
|
concatenated with the calculated checksum number. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get { |
72
|
|
|
|
|
|
|
my $self = shift; |
73
|
|
|
|
|
|
|
return $self->_reference_number(); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 BUGS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Accepts numbers shorter than 3 digits in new(). |
79
|
|
|
|
|
|
|
Accepts numbers longer than 19 digits in new(). |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Panu Ervamaa <pnu@cpan.org> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Oskari Ojala <okko@cpan.org> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Copyright 2011-2012 the above author(s). |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This sofware is free software, and is licensed under the same terms as perl itself. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |