JapanesePostalCode.pm

filter: Statementstmt 100% 61 / 61 Branchbran 95.4% 21 / 22 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 93.5% 101 / 108 CC 15 SCAR 17.6
CC
15
Cov
96%
get_line
10.0
new
4.1
fetch_obj
2.0
CRAP 5.8
« JapanesePostalCode/Row.pm ↑ Summary
1 package Parse::JapanesePostalCode;
2 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 our $VERSION = '0.03';
6  
7 16 ▶use Parse::JapanesePostalCode::Row;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 17 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod documented
10 17 my($class, %opts) = @_;
11  
12 17 my $self = bless {
13 format => 'ken',
14 katakana_h2z => 1,
15 alnum_z2h => 1,
16 %opts,
17 current_build_town => '',
18 current_build_town_kana => '',
19 }, $class;
20  
21 17 ▶ if ( ! $self->{fh} && $self->{file} && -f $self->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"fh"} and $self->{"file"} and -f $self->{"file"}) 4 13 17
Condition66%4/6
not $self->{"fh"} and $self->{"file"} and -f $self->{"file"}
!ll&&!rl&&r
1304
not $self->{"fh"} and $self->{"file"}
!ll&&!rl&&r
1304
MC/DC33%1/3
not $self->{"fh"} and $self->{"file"} and -f $self->{"file"}
not $self->{"fh"} $self->{"file"} -f $self->{"file"}
Truth table50%2/4
not(A) and B and C
A= not $self->{"fh"}B= $self->{"file"}C= -f $self->{"file"}
ABCresult
0XX0
10X0
1100
1111
22 4 open $self->{fh}, '<:encoding(cp932)', $self->{file};
23 }
24  
25 17 $self;
26 }
27  
28 76 ▶sub fetch_obj {
Subroutine fetch_obj: called CC=2 SCAR=6.9
Pod documented
29 76 my($self, ) = @_;
30  
31 76 my $row = $self->get_line;
32 76 ▶ return unless $row;
Branch: 1 branch
BranchTrueFalseTotal
unless $row 1 75 76
33 75 my @names = Parse::JapanesePostalCode::Row->columns;
34 75 my %columns;
35 75 @columns{@names} = @{ $row };
36  
37 Parse::JapanesePostalCode::Row->new(
38 build_town => $self->{current_build_town},
39 build_town_kana => $self->{current_build_town_kana},
40 katakana_h2z => $self->{katakana_h2z},
41 alnum_z2h => $self->{alnum_z2h},
42 75 %columns,
43 );
44 }
45  
46 88 ▶sub _get_line {
Subroutine _get_line: called CC=2 SCAR=6.9
47 88 my($self, ) = @_;
48  
49 88 my $fh = $self->{fh};
50 88 my $line = <$fh>;
51 88 ▶ return unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 2 86 88
52 86 $line =~ s/\r\n$//;
53  
54 # easy csv parser for KEN_ALL.csv
55 my @row = map {
56 86 my $data = $_;
57 1289 $data =~ s/^"//;
58 1289 $data =~ s/"$//;
59 1289 $data;
60 } split ',', $line;
61  
62 86 \@row;
63 }
64  
65 78 ▶sub get_line {
Subroutine get_line: called CC=10 SCAR=23.0
Pod documented
66 78 my($self, ) = @_;
67  
68 78 my $row = $self->_get_line;
69 78 ▶ return unless $row;
Branch: 1 branch
BranchTrueFalseTotal
unless $row 2 76 78
70 76 ▶ if ($row->[8] =~ /(.+[^)]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->[8] =~ /\x{ff08}.+[^\x{ff09}]$/) 7 69 76
71 7 my $past_town_kana = $row->[5];
72 7 while (1) {
73 10 my $tmp = $self->_get_line;
74 10 ▶ return unless $tmp;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmp 0 10 10
75 10 ▶ $row->[5] .= $tmp->[5] unless $past_town_kana eq $tmp->[5];
Branch: 1 branch
BranchTrueFalseTotal
unless $past_town_kana eq $tmp->[5] 8 2 10
76 10 $row->[8] .= $tmp->[8];
77 10 ▶ last if $row->[8] =~ /\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $row->[8] =~ /\\x{ff09}$/ 7 3 10
78 3 $past_town_kana = $tmp->[5];
79 }
80 }
81  
82 76 my $town = $row->[8];
83  
84 76 ▶ if ($town =~ /^(.+)(次のビルを除く)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($town =~ /^(.+)\x{ff08}\x{6b21}\x{306e}\x{30d3}\x{30eb}\x{3092}\x{9664}\x{304f}\x{ff09}$/) { } 1 75 76
elsif ($row->[2] eq '4530002' and $town =~ /^\x{540d}\x{99c5}\\x{ff08}/) { } 1 74 75
85 1 $self->{current_build_town} = $1;
86 1 ($self->{current_build_town_kana}) = $row->[5] =~ /^(.+)\(/;
87 ▶ } elsif ($row->[2] eq '4530002' && $town =~ /^名駅\(/) {
Condition66%2/3
$row->[2] eq 4530002 and $town =~ /^\x{540d}\x{99c5}\\x{ff08}/
!ll&&!rl&&r
7401
MC/DC50%1/2
$row->[2] eq 4530002 and $town =~ /^\x{540d}\x{99c5}\\x{ff08}/
$row->[2] eq 4530002 $town =~ /^\x{540d}\x{99c5}\\x{ff08}/
Truth table66%2/3
A and B
A= $row->[2] eq 4530002B= $town =~ /^\x{540d}\x{99c5}\\x{ff08}/
ABresult
0X0
100
111
88 1 $self->{current_build_town} = '名駅';
89 1 $self->{current_build_town_kana} = 'メイエキ';
90 } else {
91 74 my $current_build_town = $self->{current_build_town};
92 74 ▶ unless ($town =~ /^$current_build_town.+(.+階.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($town =~ /^$current_build_town.+\x{ff08}.+\x{968e}.*\x{ff09}$/) 66 8 74
93 66 $self->{current_build_town} = '';
94 66 $self->{current_build_town_kana} = '';
95 }
96 }
97  
98 76 $row;
99 }
100  
101 16 1;
102 __END__
« JapanesePostalCode/Row.pm ↑ Summary