line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::ZipCode::JP; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
314308
|
use strict; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
242
|
|
4
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
124
|
|
5
|
4
|
|
|
4
|
|
105
|
use 5.008_001; |
|
4
|
|
|
|
|
33
|
|
6
|
4
|
|
|
4
|
|
24
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
323
|
|
7
|
4
|
|
|
4
|
|
2114
|
use UNIVERSAL::require; |
|
4
|
|
|
|
|
7044
|
|
|
4
|
|
|
|
|
41
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.20230929'; |
10
|
|
|
|
|
|
|
our %ZIP_TABLE = (); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
13
|
5
|
|
|
5
|
|
864
|
my $self = shift; |
14
|
5
|
|
|
|
|
61
|
%ZIP_TABLE = (); |
15
|
5
|
100
|
|
|
|
22
|
if (@_) { |
16
|
2
|
|
|
|
|
5
|
my @packages = (); |
17
|
2
|
|
|
|
|
5
|
for my $subclass (@_) { |
18
|
2
|
|
|
|
|
25
|
push @packages, |
19
|
|
|
|
|
|
|
sprintf('%s::Table::%s', __PACKAGE__, ucfirst(lc($subclass))); |
20
|
|
|
|
|
|
|
} |
21
|
2
|
|
|
|
|
11
|
%ZIP_TABLE = _merge_table(@packages); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
3
|
|
|
|
|
910
|
require Number::ZipCode::JP::Table; |
25
|
3
|
|
|
|
|
20
|
import Number::ZipCode::JP::Table; |
26
|
|
|
|
|
|
|
} |
27
|
5
|
|
|
|
|
1722
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _merge_table { |
31
|
4
|
|
|
4
|
|
13
|
my %table = (); |
32
|
4
|
|
|
|
|
11
|
for my $pkg (@_) { |
33
|
6
|
50
|
|
|
|
39
|
$pkg->require or croak $@; |
34
|
|
|
|
|
|
|
{ |
35
|
4
|
|
|
4
|
|
716
|
no strict 'refs'; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
2145
|
|
|
6
|
|
|
|
|
156
|
|
36
|
6
|
|
|
|
|
13
|
while (my($k, $v) = each %{"$pkg\::ZIP_TABLE"}) { |
|
5691
|
|
|
|
|
18420
|
|
37
|
5685
|
|
100
|
|
|
16897
|
$table{$k} ||= []; |
38
|
5685
|
|
|
|
|
7014
|
push @{$table{$k}}, $v; |
|
5685
|
|
|
|
|
10854
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
4
|
|
|
|
|
1552
|
return %table; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
3
|
|
|
3
|
1
|
1301
|
my $class = shift; |
47
|
3
|
|
|
|
|
11
|
my $self = bless {}, $class; |
48
|
3
|
50
|
|
|
|
13
|
$self->set_number(@_) if @_; |
49
|
3
|
|
|
|
|
10
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub set_number { |
53
|
149001
|
|
|
149001
|
1
|
306282
|
my $self = shift; |
54
|
149001
|
|
|
|
|
225171
|
my $number = shift; |
55
|
149001
|
50
|
|
|
|
936633
|
if (ref($number) eq 'ARRAY') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
$self->_prefix = shift @$number; |
57
|
0
|
|
|
|
|
0
|
$self->_suffix = shift @$number; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif (defined $_[0]) { |
60
|
0
|
|
|
|
|
0
|
$self->_prefix = $number; |
61
|
0
|
|
|
|
|
0
|
$self->_suffix = $_[0]; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ($number =~ /^(\d{3})(?:\D)?(\d{4})$/) { |
64
|
149001
|
|
|
|
|
327906
|
my $pref = $1; |
65
|
149001
|
|
|
|
|
221838
|
my $suff = $2; |
66
|
149001
|
|
|
|
|
339805
|
$self->_prefix = $pref; |
67
|
149001
|
|
|
|
|
290369
|
$self->_suffix = $suff; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
0
|
|
|
|
|
0
|
carp "The number is invalid zip-code."; |
71
|
0
|
|
|
|
|
0
|
$self->_prefix = (); |
72
|
0
|
|
|
|
|
0
|
$self->_suffix = (); |
73
|
|
|
|
|
|
|
} |
74
|
149001
|
|
|
|
|
613021
|
return $self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub is_valid_number { |
78
|
149001
|
|
|
149001
|
1
|
196525
|
my $self = shift; |
79
|
149001
|
|
|
|
|
227841
|
my $pref = $self->_prefix; |
80
|
149001
|
|
|
|
|
245019
|
my $suff = $self->_suffix; |
81
|
149001
|
50
|
33
|
|
|
347884
|
unless ($pref || $suff) { |
82
|
0
|
|
|
|
|
0
|
carp "Any number was not set"; |
83
|
0
|
|
|
|
|
0
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
149001
|
50
|
33
|
|
|
667181
|
return unless $pref =~ /^\d{3}$/ && $suff =~ /^\d{4}$/; |
86
|
149001
|
|
|
|
|
296469
|
my $re_ref = $ZIP_TABLE{$pref}; |
87
|
149001
|
50
|
33
|
|
|
435410
|
return unless defined $re_ref && ref($re_ref) eq 'ARRAY'; |
88
|
149001
|
|
|
|
|
191843
|
my $matched; |
89
|
149001
|
|
|
|
|
265353
|
for my $re (@$re_ref) { |
90
|
149001
|
100
|
|
|
|
1107396
|
if ($suff =~ /^$re$/) { |
91
|
147108
|
|
|
|
|
242957
|
$matched = 1; |
92
|
147108
|
|
|
|
|
301210
|
last; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
149001
|
|
|
|
|
753158
|
return $matched; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
298002
|
|
|
298002
|
|
525143
|
sub _prefix : lvalue { shift->{_prefix} } |
99
|
298002
|
|
|
298002
|
|
445852
|
sub _suffix : lvalue { shift->{_suffix} } |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
__END__ |