JP.pm

filter: Statementstmt 88.1% 67 / 76 Branchbran 63.6% 14 / 22 Conditioncond 45.4% 5 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 78.0% 103 / 132 CC 19 SCAR 17.6
CC
19
Cov
79%
is_valid_number
12.3
set_number
5.7
_merge_table
5.0
CRAP 5.8
« regexp-table-maker.pl ↑ Summary JP/Table.pm »
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
BranchTrueFalseTotal
if (@_) { } 2 3 5
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
BranchTrueFalseTotal
$pkg->require or croak($@) 6 0 6
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
BranchTrueFalseTotal
if (() = each %{"${pkg}::ZIP_TABLE";}) 5685 6 5691
37 5685 ▶ $table{$k} ||= [];
Condition100%2/2
$table{$k} ||= []
l!l
18883797
MC/DC100%1/1
$table{$k} ||= []
$table{$k}
Truth table100%2/2
A
A= $table{$k}
Aresult
11
00
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
BranchTrueFalseTotal
if @_ 0 3 3
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
BranchTrueFalseTotal
if (ref $number eq 'ARRAY') { } 0 149143 149143
elsif (defined $_[0]) { } 0 149143 149143
elsif ($number =~ /^(\d{3})(?:\D)?(\d{4})$/) { } 149143 0 149143
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
BranchTrueFalseTotal
unless ($pref or $suff) 0 149143 149143
Condition33%1/3
$pref or $suff
l!l&&r!l&&!r
14914300
MC/DC0%0/2
$pref or $suff
$pref $suff
Truth table33%1/3
A or B
A= $prefB= $suff
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $pref =~ /^\d{3}$/ and $suff =~ /^\d{4}$/ 0 149143 149143
Condition33%1/3
$pref =~ /^\d{3}$/ and $suff =~ /^\d{4}$/
!ll&&!rl&&r
00149143
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}$/
ABresult
0X0
100
111
86 149143 my $re_ref = $ZIP_TABLE{$pref};
87 149143 ▶ return unless defined $re_ref && ref($re_ref) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $re_ref and ref $re_ref eq "ARRAY" 0 149143 149143
Condition33%1/3
defined $re_ref and ref $re_ref eq "ARRAY"
!ll&&!rl&&r
00149143
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"
ABresult
0X0
100
111
88 149143 my $matched;
89 149143 for my $re (@$re_ref) {
90 149143 ▶ if ($suff =~ /^$re$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suff =~ /^$re$/) 147250 1893 149143
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__
« regexp-table-maker.pl ↑ Summary JP/Table.pm »