line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::ZipCode::JP; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
329505
|
use strict; |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
227
|
|
4
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
125
|
|
5
|
4
|
|
|
4
|
|
124
|
use 5.008_001; |
|
4
|
|
|
|
|
17
|
|
6
|
4
|
|
|
4
|
|
26
|
use Carp; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
330
|
|
7
|
4
|
|
|
4
|
|
2330
|
use UNIVERSAL::require; |
|
4
|
|
|
|
|
4991
|
|
|
4
|
|
|
|
|
42
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.20230731'; |
10
|
|
|
|
|
|
|
our %ZIP_TABLE = (); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
13
|
5
|
|
|
5
|
|
871
|
my $self = shift; |
14
|
5
|
|
|
|
|
63
|
%ZIP_TABLE = (); |
15
|
5
|
100
|
|
|
|
23
|
if (@_) { |
16
|
2
|
|
|
|
|
4
|
my @packages = (); |
17
|
2
|
|
|
|
|
7
|
for my $subclass (@_) { |
18
|
2
|
|
|
|
|
25
|
push @packages, |
19
|
|
|
|
|
|
|
sprintf('%s::Table::%s', __PACKAGE__, ucfirst(lc($subclass))); |
20
|
|
|
|
|
|
|
} |
21
|
2
|
|
|
|
|
10
|
%ZIP_TABLE = _merge_table(@packages); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
3
|
|
|
|
|
948
|
require Number::ZipCode::JP::Table; |
25
|
3
|
|
|
|
|
18
|
import Number::ZipCode::JP::Table; |
26
|
|
|
|
|
|
|
} |
27
|
5
|
|
|
|
|
1593
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _merge_table { |
31
|
4
|
|
|
4
|
|
14
|
my %table = (); |
32
|
4
|
|
|
|
|
11
|
for my $pkg (@_) { |
33
|
6
|
50
|
|
|
|
40
|
$pkg->require or croak $@; |
34
|
|
|
|
|
|
|
{ |
35
|
4
|
|
|
4
|
|
807
|
no strict 'refs'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
2369
|
|
|
6
|
|
|
|
|
122
|
|
36
|
6
|
|
|
|
|
13
|
while (my($k, $v) = each %{"$pkg\::ZIP_TABLE"}) { |
|
5691
|
|
|
|
|
18042
|
|
37
|
5685
|
|
100
|
|
|
17471
|
$table{$k} ||= []; |
38
|
5685
|
|
|
|
|
7209
|
push @{$table{$k}}, $v; |
|
5685
|
|
|
|
|
11680
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
4
|
|
|
|
|
1641
|
return %table; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
3
|
|
|
3
|
1
|
1295
|
my $class = shift; |
47
|
3
|
|
|
|
|
24
|
my $self = bless {}, $class; |
48
|
3
|
50
|
|
|
|
16
|
$self->set_number(@_) if @_; |
49
|
3
|
|
|
|
|
10
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub set_number { |
53
|
148956
|
|
|
148956
|
1
|
342150
|
my $self = shift; |
54
|
148956
|
|
|
|
|
297899
|
my $number = shift; |
55
|
148956
|
50
|
|
|
|
1115492
|
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
|
148956
|
|
|
|
|
382385
|
my $pref = $1; |
65
|
148956
|
|
|
|
|
268243
|
my $suff = $2; |
66
|
148956
|
|
|
|
|
379478
|
$self->_prefix = $pref; |
67
|
148956
|
|
|
|
|
336833
|
$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
|
148956
|
|
|
|
|
1005217
|
return $self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub is_valid_number { |
78
|
148956
|
|
|
148956
|
1
|
235287
|
my $self = shift; |
79
|
148956
|
|
|
|
|
277594
|
my $pref = $self->_prefix; |
80
|
148956
|
|
|
|
|
286621
|
my $suff = $self->_suffix; |
81
|
148956
|
50
|
33
|
|
|
400985
|
unless ($pref || $suff) { |
82
|
0
|
|
|
|
|
0
|
carp "Any number was not set"; |
83
|
0
|
|
|
|
|
0
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
148956
|
50
|
33
|
|
|
816015
|
return unless $pref =~ /^\d{3}$/ && $suff =~ /^\d{4}$/; |
86
|
148956
|
|
|
|
|
382206
|
my $re_ref = $ZIP_TABLE{$pref}; |
87
|
148956
|
50
|
33
|
|
|
548447
|
return unless defined $re_ref && ref($re_ref) eq 'ARRAY'; |
88
|
148956
|
|
|
|
|
221570
|
my $matched; |
89
|
148956
|
|
|
|
|
319545
|
for my $re (@$re_ref) { |
90
|
148956
|
100
|
|
|
|
1337733
|
if ($suff =~ /^$re$/) { |
91
|
147063
|
|
|
|
|
273970
|
$matched = 1; |
92
|
147063
|
|
|
|
|
378854
|
last; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
148956
|
|
|
|
|
1162783
|
return $matched; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
297912
|
|
|
297912
|
|
620436
|
sub _prefix : lvalue { shift->{_prefix} } |
99
|
297912
|
|
|
297912
|
|
521002
|
sub _suffix : lvalue { shift->{_suffix} } |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
__END__ |