File Coverage

blib/lib/Business/ID/NOPPBB.pm
Criterion Covered Total %
statement 26 26 100.0
branch 8 10 80.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 40 42 95.2


line stmt bran cond sub pod time code
1             package Business::ID::NOPPBB;
2              
3             our $DATE = '2015-07-10'; # DATE
4             our $VERSION = '0.07'; # VERSION
5              
6 1     1   19891 use 5.010001;
  1         6  
  1         50  
7 1     1   7 use warnings;
  1         2  
  1         44  
8 1     1   7 use strict;
  1         2  
  1         54  
9              
10 1     1   805 use Locale::ID::Province qw(list_id_provinces);
  1         134017  
  1         590  
11              
12             require Exporter;
13             our @ISA = qw(Exporter);
14             our @EXPORT = 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 1990 my (%args) = @_;
64              
65 4 50       15 my $str = $args{str} or return [400, "Please specify str"];
66              
67             # cache provinces, key is code
68 4         5 state $provs;
69 4 100       11 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       2187 $res->[0] == 200 or die "Can't retrieve list of provinces: ".
74             "$res->[0] - $res->[1]";
75 1         3 $provs = {};
76 1         2 $provs->{$_->{bps_code}} = $_ for @{$res->[2]};
  1         51  
77             }
78              
79 4         22 $str =~ s/\D+//g;
80 4 100       18 length($str) == 18 or return [400, "Length must be 18 digits"];
81 3         18 my ($aa, $bb, $ccc, $ddd, $eee, $xxxx, $y) =
82             $str =~ /(.{2})(.{2})(.{3})(.{3})(.{4})(.{1})/;
83 3 100       15 $provs->{$aa} or return [400, "Unknown province code '$aa'"];
84              
85 2         27 [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             }];
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.07 of Business::ID::NOPPBB (from Perl distribution Business-ID-NOPPBB), released on 2015-07-10.
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(%args) -> [status, msg, result, meta]
149              
150             Validate (and parse) Indonesian property tax number (NOP PBB).
151              
152             Indonesian property tax object number, or Nomor Objek Pajak Pajak Bumi dan
153             Bangunan, is a number given to a tax object (a piece of land with its
154             house/building).
155              
156             NOP PBB is composed of 18 digits as follow:
157              
158             AA.BB.CCC.DDD.EEE-XXXX.Y
159              
160             AA is the province code from BPS. BB is locality (city/regency a.k.a
161             kota/kabupaten) code from BPS. CCC is district (kecamatan) code from BPS. DDD is
162             village (desa/kelurahan) code from BPS. EEE is block code. XXXX is the object
163             number. Y is a special code (it is most likely not a check digit, since it is
164             almost always has the value of 0).
165              
166             The function will return status 200 if syntax is valid and return the parsed
167             information hash. Otherwise it will return 400.
168              
169             Currently the length and AA code is checked against valid province code. There
170             is currently no way to check whether a specific NOP PBB actually exists, because
171             you would need to query Dirjen Pajak's database for that.
172              
173             Arguments ('*' denotes required arguments):
174              
175             =over 4
176              
177             =item * B<str> => I<str>
178              
179             The input string containing number to check.
180              
181             =back
182              
183             Returns an enveloped result (an array).
184              
185             First element (status) is an integer containing HTTP status code
186             (200 means OK, 4xx caller error, 5xx function error). Second element
187             (msg) is a string containing error message, or 'OK' if status is
188             200. Third element (result) is optional, the actual result. Fourth
189             element (meta) is called result metadata and is optional, a hash
190             that contains extra information.
191              
192             Return value: (hash)
193              
194             =head1 HOMEPAGE
195              
196             Please visit the project's homepage at L<https://metacpan.org/release/Business-ID-NOPPBB>.
197              
198             =head1 SOURCE
199              
200             Source repository is at L<https://github.com/perlancar/perl-Business-ID-NOPPBB>.
201              
202             =head1 BUGS
203              
204             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Business-ID-NOPPBB>
205              
206             When submitting a bug or request, please include a test-file or a
207             patch to an existing test-file that illustrates the bug or desired
208             feature.
209              
210             =head1 AUTHOR
211              
212             perlancar <perlancar@cpan.org>
213              
214             =head1 COPYRIGHT AND LICENSE
215              
216             This software is copyright (c) 2015 by perlancar@cpan.org.
217              
218             This is free software; you can redistribute it and/or modify it under
219             the same terms as the Perl 5 programming language system itself.
220              
221             =cut