File Coverage

blib/lib/Business/ID/NOPPBB.pm
Criterion Covered Total %
statement 28 28 100.0
branch 8 10 80.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 43 45 95.5


line stmt bran cond sub pod time code
1             package Business::ID::NOPPBB;
2              
3             our $DATE = '2019-11-21'; # DATE
4             our $DIST = 'Business-ID-NOPPBB'; # DIST
5             our $VERSION = '0.090'; # VERSION
6              
7 1     1   78083 use 5.010001;
  1         10  
8 1     1   4 use warnings;
  1         2  
  1         20  
9 1     1   4 use strict;
  1         2  
  1         19  
10              
11 1     1   426 use Locale::ID::Province qw(list_id_provinces);
  1         96476  
  1         74  
12              
13 1     1   7 use Exporter 'import';
  1         2  
  1         405  
14             our @EXPORT_OK = qw(validate_nop_pbb);
15              
16             our %SPEC;
17              
18             $SPEC{validate_nop_pbb} = {
19             v => 1.1,
20             summary => 'Validate (and parse) Indonesian property tax number (NOP PBB)',
21             description => <<'_',
22              
23             Indonesian property tax object number, or Nomor Objek Pajak Pajak Bumi dan
24             Bangunan, is a number given to a tax object (a piece of land with its
25             house/building).
26              
27             NOP PBB is composed of 18 digits as follow:
28              
29             AA.BB.CCC.DDD.EEE-XXXX.Y
30              
31             AA is the province code from BPS. BB is locality (city/regency a.k.a
32             kota/kabupaten) code from BPS. CCC is district (kecamatan) code from BPS. DDD is
33             village (desa/kelurahan) code from BPS. EEE is block code. XXXX is the object
34             number. Y is a special code (it is most likely not a check digit, since it is
35             almost always has the value of 0).
36              
37             The function will return status 200 if syntax is valid and return the parsed
38             information hash. Otherwise it will return 400.
39              
40             Currently the length and AA code is checked against valid province code. There
41             is currently no way to check whether a specific NOP PBB actually exists, because
42             you would need to query Dirjen Pajak's database for that.
43              
44             _
45             args => {
46             str => {
47             summary => 'The input string containing number to check',
48             pos => 0,
49             schema => 'str*',
50             },
51             },
52             result => {
53             schema => ['hash*', {each_index=>['str*'=>{
54             in=>[qw/province locality district village
55             block object special
56              
57             eng_province_name
58             ind_province_name
59             /]}]}],
60             },
61             };
62             sub validate_nop_pbb {
63 4     4 1 1584 my (%args) = @_;
64              
65 4 50       12 my $str = $args{str} or return [400, "Please specify str"];
66              
67             # cache provinces, key is code
68 4         4 state $provs;
69 4 100       9 if (!$provs) {
70 1         6 my $res = list_id_provinces(
71             fields=>['bps_code', 'ind_name', 'eng_name'],
72             with_field_names => 1);
73 1 50       2342 $res->[0] == 200 or die "Can't retrieve list of provinces: ".
74             "$res->[0] - $res->[1]";
75 1         2 $provs = {};
76 1         3 $provs->{$_->{bps_code}} = $_ for @{$res->[2]};
  1         24  
77             }
78              
79 4         18 $str =~ s/\D+//g;
80 4 100       13 length($str) == 18 or return [400, "Length must be 18 digits"];
81 3         15 my ($aa, $bb, $ccc, $ddd, $eee, $xxxx, $y) =
82             $str =~ /(.{2})(.{2})(.{3})(.{3})(.{4})(.{1})/;
83 3 100       12 $provs->{$aa} or return [400, "Unknown province code '$aa'"];
84              
85             [200, "OK", {
86             province => $aa,
87             locality => $bb,
88             district => $ccc,
89             village => $ddd,
90             block => $eee,
91             object => $xxxx,
92             special => $y,
93              
94             eng_province_name => $provs->{$aa}{eng_name},
95             ind_province_name => $provs->{$aa}{ind_name},
96 2         27 }];
97             }
98              
99             1;
100             # ABSTRACT: Validate (and parse) Indonesian property tax number (NOP PBB)
101              
102             __END__
103              
104             =pod
105              
106             =encoding UTF-8
107              
108             =head1 NAME
109              
110             Business::ID::NOPPBB - Validate (and parse) Indonesian property tax number (NOP PBB)
111              
112             =head1 VERSION
113              
114             This document describes version 0.090 of Business::ID::NOPPBB (from Perl distribution Business-ID-NOPPBB), released on 2019-11-21.
115              
116             =head1 SYNOPSIS
117              
118             use Business::ID::NOPPBB qw(validate_nop_pbb);
119              
120             my $res = validate_nop_pbb(str => '327311000109900990');
121             $res->[0] == 200 or die "Invalid NOP PBB!";
122              
123             # get structure
124             use Data::Dumper;
125             print Dumper $res->[2];
126              
127             # will print something like
128             {
129             province => 32,
130             locality => 73,
131             district => 110,
132             village => '001',
133             block => '099',
134             object => '0099',
135             special => 0,
136             canonical => '32.73.110.001.099-0099.0',
137             }
138              
139             =head1 DESCRIPTION
140              
141             This module provides one function: B<validate_nop_pbb>.
142              
143             This module has L<Rinci> metadata.
144              
145             =head1 FUNCTIONS
146              
147              
148             =head2 validate_nop_pbb
149              
150             Usage:
151              
152             validate_nop_pbb(%args) -> [status, msg, payload, meta]
153              
154             Validate (and parse) Indonesian property tax number (NOP PBB).
155              
156             Indonesian property tax object number, or Nomor Objek Pajak Pajak Bumi dan
157             Bangunan, is a number given to a tax object (a piece of land with its
158             house/building).
159              
160             NOP PBB is composed of 18 digits as follow:
161              
162             AA.BB.CCC.DDD.EEE-XXXX.Y
163              
164             AA is the province code from BPS. BB is locality (city/regency a.k.a
165             kota/kabupaten) code from BPS. CCC is district (kecamatan) code from BPS. DDD is
166             village (desa/kelurahan) code from BPS. EEE is block code. XXXX is the object
167             number. Y is a special code (it is most likely not a check digit, since it is
168             almost always has the value of 0).
169              
170             The function will return status 200 if syntax is valid and return the parsed
171             information hash. Otherwise it will return 400.
172              
173             Currently the length and AA code is checked against valid province code. There
174             is currently no way to check whether a specific NOP PBB actually exists, because
175             you would need to query Dirjen Pajak's database for that.
176              
177             This function is not exported by default, but exportable.
178              
179             Arguments ('*' denotes required arguments):
180              
181             =over 4
182              
183             =item * B<str> => I<str>
184              
185             The input string containing number to check.
186              
187             =back
188              
189             Returns an enveloped result (an array).
190              
191             First element (status) is an integer containing HTTP status code
192             (200 means OK, 4xx caller error, 5xx function error). Second element
193             (msg) is a string containing error message, or 'OK' if status is
194             200. Third element (payload) is optional, the actual result. Fourth
195             element (meta) is called result metadata and is optional, a hash
196             that contains extra information.
197              
198             Return value: (hash)
199              
200             =head1 HOMEPAGE
201              
202             Please visit the project's homepage at L<https://metacpan.org/release/Business-ID-NOPPBB>.
203              
204             =head1 SOURCE
205              
206             Source repository is at L<https://github.com/perlancar/perl-Business-ID-NOPPBB>.
207              
208             =head1 BUGS
209              
210             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Business-ID-NOPPBB>
211              
212             When submitting a bug or request, please include a test-file or a
213             patch to an existing test-file that illustrates the bug or desired
214             feature.
215              
216             =head1 AUTHOR
217              
218             perlancar <perlancar@cpan.org>
219              
220             =head1 COPYRIGHT AND LICENSE
221              
222             This software is copyright (c) 2019, 2015, 2014, 2013, 2012 by perlancar@cpan.org.
223              
224             This is free software; you can redistribute it and/or modify it under
225             the same terms as the Perl 5 programming language system itself.
226              
227             =cut