line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
package Asmens::Kodas; |
3
|
1
|
|
|
1
|
|
26803
|
use Exporter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
413
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @ISA = qw/Exporter/; |
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw/tikras/; |
8
|
|
|
|
|
|
|
our $VERSION = 0.02; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Asmens::Kodas - Lithuanian personal (passport) number checking |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Asmens::Kodas qw/tikras/; |
17
|
|
|
|
|
|
|
print tikras("38208080214") ? "tinka" : "netinka"; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This module provides a subroutine that runs a few checks which ensure |
22
|
|
|
|
|
|
|
that Lithuanian personal number (I) has a correct checksum |
23
|
|
|
|
|
|
|
and has sane fields. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 tikras |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This subroutine does the actual checking. It returns 1 if the argument can possibly |
28
|
|
|
|
|
|
|
be a correct Lithuanian personal number. Otherwise it returns 0. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 AUTHOR |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Petras Kudaras Emoxliukas@delfi.ltE |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub tikras { |
37
|
11
|
100
|
|
11
|
1
|
59
|
return 0 unless $_[0] =~ /^\d{11}$/; |
38
|
8
|
|
|
|
|
50
|
my @what = split //, shift; |
39
|
8
|
100
|
66
|
|
|
56
|
return 0 unless $what[0] >= 1 and $what[0] <= 6; |
40
|
7
|
100
|
|
|
|
54
|
return 0 unless $what[10] == checksum(@what); |
41
|
5
|
100
|
|
|
|
19
|
return 0 unless $what[3] * 10 + $what[4] <= 12; |
42
|
4
|
100
|
|
|
|
14
|
return 0 unless $what[5] * 10 + $what[6] <= 31; |
43
|
3
|
|
|
|
|
43
|
1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub checksum { |
47
|
7
|
|
|
7
|
0
|
35
|
my $c = $_[0] + $_[1] * 2 + $_[2] * 3 + $_[3] * 4 + $_[4] * 5 + $_[5] * 6; |
48
|
7
|
|
|
|
|
20
|
$c += $_[6] * 7 + $_[7] * 8 + $_[8] * 9 + $_[9]; |
49
|
7
|
|
|
|
|
10
|
$c = $c % 11; |
50
|
7
|
50
|
|
|
|
41
|
return $c unless $c == 10; |
51
|
0
|
|
|
|
|
|
$c = $_[0] * 3 + $_[1] * 4 + $_[2] * 5 + $_[3] * 6 + $_[4] * 7 + $_[5] * 8; |
52
|
0
|
|
|
|
|
|
$c += $_[6] * 9 + $_[7] + $_[8] * 2 + $_[9] * 3; |
53
|
0
|
|
|
|
|
|
$c = $c % 11; |
54
|
0
|
0
|
|
|
|
|
return $c unless $c == 10; |
55
|
0
|
|
|
|
|
|
return 0; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
1; |