line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::ID::SIM; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-10-15'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.08'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
98914
|
use 5.010001; |
|
1
|
|
|
|
|
13
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
8
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
865
|
use DateTime; |
|
1
|
|
|
|
|
506876
|
|
|
1
|
|
|
|
|
430
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(parse_sim); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# legend: S = lack of samples |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# less organized than the convoluted code in NIK |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my %provinces = ( |
21
|
|
|
|
|
|
|
'06' => "Nanggroe Aceh Darussalam", |
22
|
|
|
|
|
|
|
'07' => "Sumatera Utara", |
23
|
|
|
|
|
|
|
'08' => "Sumatera Barat", |
24
|
|
|
|
|
|
|
'09' => "Riau, Kepulauan Riau", |
25
|
|
|
|
|
|
|
'10' => undef, # S |
26
|
|
|
|
|
|
|
'11' => "Sumatera Selatan", |
27
|
|
|
|
|
|
|
'12' => "DKI Jakarta", # most frequently encountered |
28
|
|
|
|
|
|
|
'13' => "Jawa Barat", |
29
|
|
|
|
|
|
|
'14' => "Jawa Tengah, DI Yogyakarta", |
30
|
|
|
|
|
|
|
'15' => "Jawa Timur", |
31
|
|
|
|
|
|
|
'16' => "Bali", |
32
|
|
|
|
|
|
|
'17' => "Kalimantan Timur", |
33
|
|
|
|
|
|
|
'18' => "Kalimantan Selatan", |
34
|
|
|
|
|
|
|
'19' => "Sulawesi Selatan", |
35
|
|
|
|
|
|
|
'20' => "Sulawesi Utara, Gorontalo", |
36
|
|
|
|
|
|
|
'21' => undef, # S |
37
|
|
|
|
|
|
|
'22' => 'Papua', |
38
|
|
|
|
|
|
|
'23' => 'Kalimantan Tengah', |
39
|
|
|
|
|
|
|
'24' => 'Sulawesi Tengah', |
40
|
|
|
|
|
|
|
'25' => 'Lampung', |
41
|
|
|
|
|
|
|
#'30' => "Banten", # ?, SS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
our %SPEC; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$SPEC{parse_sim} = { |
48
|
|
|
|
|
|
|
v => 1.1, |
49
|
|
|
|
|
|
|
summary => 'Validate Indonesian driving license number (nomor SIM)', |
50
|
|
|
|
|
|
|
args => { |
51
|
|
|
|
|
|
|
sim => { |
52
|
|
|
|
|
|
|
summary => 'Input to be parsed', |
53
|
|
|
|
|
|
|
schema => 'str*', |
54
|
|
|
|
|
|
|
pos => 0, |
55
|
|
|
|
|
|
|
req => 1, |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
}, |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
sub parse_sim { |
60
|
3
|
|
|
3
|
1
|
13202
|
my %args = @_; |
61
|
|
|
|
|
|
|
|
62
|
3
|
50
|
|
|
|
11
|
my $sim = $args{sim} or return [400, "Please specify sim"]; |
63
|
3
|
|
|
|
|
6
|
my $res = {}; |
64
|
|
|
|
|
|
|
|
65
|
3
|
|
|
|
|
23
|
$sim =~ s/\D+//g; |
66
|
3
|
50
|
|
|
|
10
|
return [400, "Not 12 digit"] unless length($sim) == 12; |
67
|
|
|
|
|
|
|
|
68
|
3
|
|
|
|
|
10
|
$res->{prov_code} = substr($sim, 4, 2); |
69
|
3
|
100
|
|
|
|
18
|
return [400, "Unknown province code"] unless $provinces{$res->{prov_code}}; |
70
|
1
|
|
|
|
|
4
|
$res->{area_code} = substr($sim, 4, 4); |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
4
|
my ($y, $m) = $sim =~ /^(..)(..)/; |
73
|
1
|
|
|
|
|
8
|
my $today = DateTime->today; |
74
|
1
|
|
|
|
|
888
|
$y += int($today->year / 100) * 100; |
75
|
1
|
50
|
|
|
|
19
|
$y -= 100 if $y > $today->year; |
76
|
1
|
|
|
|
|
8
|
eval { $res->{dob} = DateTime->new(day=>1, month=>$m, year=>$y) }; |
|
1
|
|
|
|
|
5
|
|
77
|
1
|
50
|
|
|
|
388
|
return [400, "Invalid year and month of birth: $y, $m"] if $@; |
78
|
1
|
|
|
|
|
6
|
$res->{serial} = $sim =~ /(....)$/; |
79
|
1
|
50
|
|
|
|
11
|
return [400, "Serial starts from 1, not 0"] if $res->{serial} < 1; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
28
|
[200, "OK", $res]; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
# ABSTRACT: Validate Indonesian driving license number (nomor SIM) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=pod |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=encoding UTF-8 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 NAME |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Business::ID::SIM - Validate Indonesian driving license number (nomor SIM) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 VERSION |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This document describes version 0.08 of Business::ID::SIM (from Perl distribution Business-ID-SIM), released on 2019-10-15. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SYNOPSIS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
use Business::ID::SIM qw(parse_sim); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $res = parse_sim(sim => "0113 40 00 0001"); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 DESCRIPTION |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This module can be used to validate Indonesian driving license number, Nomor |
110
|
|
|
|
|
|
|
Surat Izin Mengemudi (SIM). |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
SIM is composed of 12 digits as follow: |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
yymm.pp.aa.ssss |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
yy and mm are year and month of birth, pp and aa are area code |
117
|
|
|
|
|
|
|
(province+district of some sort), ssss is 4-digit serial most probably starting |
118
|
|
|
|
|
|
|
from 1. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Note that there are several kinds of SIM (A, B1, B2, C) but this is not encoded |
121
|
|
|
|
|
|
|
in the SIM number and all SIM's have the same number. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 FUNCTIONS |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 parse_sim |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Usage: |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
parse_sim(%args) -> [status, msg, payload, meta] |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Validate Indonesian driving license number (nomor SIM). |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This function is not exported by default, but exportable. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Arguments ('*' denotes required arguments): |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over 4 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * B<sim>* => I<str> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Input to be parsed. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Returns an enveloped result (an array). |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
First element (status) is an integer containing HTTP status code |
149
|
|
|
|
|
|
|
(200 means OK, 4xx caller error, 5xx function error). Second element |
150
|
|
|
|
|
|
|
(msg) is a string containing error message, or 'OK' if status is |
151
|
|
|
|
|
|
|
200. Third element (payload) is optional, the actual result. Fourth |
152
|
|
|
|
|
|
|
element (meta) is called result metadata and is optional, a hash |
153
|
|
|
|
|
|
|
that contains extra information. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Return value: (any) |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 HOMEPAGE |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Business-ID-SIM>. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SOURCE |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Business-ID-SIM>. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 BUGS |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Business-ID-SIM> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
170
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
171
|
|
|
|
|
|
|
feature. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 AUTHOR |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This software is copyright (c) 2019, 2015, 2014, 2013 by perlancar@cpan.org. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
182
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |