| 1 | package Number::ZipCode::JP; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use 5.008_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use UNIVERSAL::require; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | our $VERSION = '0.20260731'; | |||||||||||||||||||||||||||
| 10 | 4 | our %ZIP_TABLE = (); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 13 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 14 | 5 | %ZIP_TABLE = (); | |||||||||||||||||||||||||||
| 15 | 5 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 2 | my @packages = (); | |||||||||||||||||||||||||||
| 17 | 2 | for my $subclass (@_) { | |||||||||||||||||||||||||||
| 18 | 2 | push @packages, | |||||||||||||||||||||||||||
| 19 | sprintf('%s::Table::%s', __PACKAGE__, ucfirst(lc($subclass))); | ||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 2 | %ZIP_TABLE = _merge_table(@packages); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||
| 24 | 3 | require Number::ZipCode::JP::Table; | |||||||||||||||||||||||||||
| 25 | 3 | import Number::ZipCode::JP::Table; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 5 | return $self; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 4 | ▶ | sub _merge_table { | ||||||||||||||||||||||||||
|
Subroutine
_merge_table: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 31 | 4 | my %table = (); | |||||||||||||||||||||||||||
| 32 | 4 | for my $pkg (@_) { | |||||||||||||||||||||||||||
| 33 | 6 | ▶ | $pkg->require or croak $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 6 | ▶ | while (my($k, $v) = each %{"$pkg\::ZIP_TABLE"}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 5685 | ▶ | $table{$k} ||= []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$table{$k} ||= []
MC/DC100%1/1
$table{$k} ||= []
$table{$k}
Truth table100%2/2
A
A= $table{$k}
| |||||||||||||||||||||||||||||
| 38 | 5685 | push @{$table{$k}}, $v; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 4 | return %table; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 47 | 3 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 48 | 3 | ▶ | $self->set_number(@_) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 3 | return $self; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 149143 | ▶ | sub set_number { | ||||||||||||||||||||||||||
|
Subroutine
set_number: called CC=4 SCAR=17.5
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 149143 | my $self = shift; | |||||||||||||||||||||||||||
| 54 | 149143 | my $number = shift; | |||||||||||||||||||||||||||
| 55 | 149143 | ▶ | if (ref($number) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 56 | 0 | $self->_prefix = shift @$number; | |||||||||||||||||||||||||||
| 57 | 0 | $self->_suffix = shift @$number; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | elsif (defined $_[0]) { | ||||||||||||||||||||||||||||
| 60 | 0 | $self->_prefix = $number; | |||||||||||||||||||||||||||
| 61 | 0 | $self->_suffix = $_[0]; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | elsif ($number =~ /^(\d{3})(?:\D)?(\d{4})$/) { | ||||||||||||||||||||||||||||
| 64 | 149143 | my $pref = $1; | |||||||||||||||||||||||||||
| 65 | 149143 | my $suff = $2; | |||||||||||||||||||||||||||
| 66 | 149143 | $self->_prefix = $pref; | |||||||||||||||||||||||||||
| 67 | 149143 | $self->_suffix = $suff; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | else { | ||||||||||||||||||||||||||||
| 70 | 0 | carp "The number is invalid zip-code."; | |||||||||||||||||||||||||||
| 71 | 0 | $self->_prefix = (); | |||||||||||||||||||||||||||
| 72 | 0 | $self->_suffix = (); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 149143 | return $self; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 149143 | ▶ | sub is_valid_number { | ||||||||||||||||||||||||||
|
Subroutine
is_valid_number: called CC=9 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 149143 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 149143 | my $pref = $self->_prefix; | |||||||||||||||||||||||||||
| 80 | 149143 | my $suff = $self->_suffix; | |||||||||||||||||||||||||||
| 81 | 149143 | ▶ | unless ($pref || $suff) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pref or $suff
MC/DC0%0/2
$pref or $suff
$pref
$suff
Truth table33%1/3
A or B
A= $prefB= $suff
| |||||||||||||||||||||||||||||
| 82 | 0 | carp "Any number was not set"; | |||||||||||||||||||||||||||
| 83 | 0 | return; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 149143 | ▶ | return unless $pref =~ /^\d{3}$/ && $suff =~ /^\d{4}$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pref =~ /^\d{3}$/ and $suff =~ /^\d{4}$/
MC/DC0%0/2
$pref =~ /^\d{3}$/ and $suff =~ /^\d{4}$/
$pref =~ /^\d{3}$/
$suff =~ /^\d{4}$/
Truth table33%1/3
A and B
A= $pref =~ /^\d{3}$/B= $suff =~ /^\d{4}$/
| |||||||||||||||||||||||||||||
| 86 | 149143 | my $re_ref = $ZIP_TABLE{$pref}; | |||||||||||||||||||||||||||
| 87 | 149143 | ▶ | return unless defined $re_ref && ref($re_ref) eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $re_ref and ref $re_ref eq "ARRAY"
MC/DC0%0/2
defined $re_ref and ref $re_ref eq "ARRAY"
defined $re_ref
ref $re_ref eq "ARRAY"
Truth table33%1/3
A and B
A= defined $re_refB= ref $re_ref eq "ARRAY"
| |||||||||||||||||||||||||||||
| 88 | 149143 | my $matched; | |||||||||||||||||||||||||||
| 89 | 149143 | for my $re (@$re_ref) { | |||||||||||||||||||||||||||
| 90 | 149143 | ▶ | if ($suff =~ /^$re$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 147250 | $matched = 1; | |||||||||||||||||||||||||||
| 92 | 147250 | last; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 149143 | return $matched; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 298286 | ▶ | sub _prefix : lvalue { shift->{_prefix} } | ||||||||||||||||||||||||||
|
Subroutine
_prefix: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 99 | 298286 | ▶ | sub _suffix : lvalue { shift->{_suffix} } | ||||||||||||||||||||||||||
|
Subroutine
_suffix: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 4 | 1; | |||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||