| 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
Condition66%4/6
not $self->{"fh"} and $self->{"file"} and -f $self->{"file"}
not $self->{"fh"} and $self->{"file"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 76 | ▶ | if ($row->[8] =~ /(.+[^)]$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 10 | ▶ | $row->[5] .= $tmp->[5] unless $past_town_kana eq $tmp->[5]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | $row->[8] .= $tmp->[8]; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 10 | ▶ | last if $row->[8] =~ /\)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | $past_town_kana = $tmp->[5]; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 76 | my $town = $row->[8]; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 76 | ▶ | if ($town =~ /^(.+)(次のビルを除く)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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}/
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}/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||