blib/lib/Lingua/Han/CanonicalPinYin.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 75.0% 9 / 12 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 79.6% 51 / 64 CC 10 SCAR 20.6
CC
10
Cov
85%
canonicalize_pinyin
11.3
BEGIN
1.0
BEGIN
1.0
CRAP 7.9
↑ Summary
1 package Lingua::Han::CanonicalPinYin;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 our $VERSION = 0.04;
6  
7 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our @EXPORT_OK = 'canonicalize_pinyin';
10 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 my @tones = ( "\x{304}", "\x{301}", "\x{30c}", "\x{300}" );
13 80 ▶sub canonicalize_pinyin {
Subroutine canonicalize_pinyin: called CC=10 SCAR=24.3
Pod undocumented
14 80 my $pinyin = lc shift;
15 80 ▶ $pinyin = decode_utf8( $pinyin ) unless utf8::is_utf8( $pinyin );
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($pinyin) 76 4 80
16 80 my $tone;
17 80 ▶ ($pinyin, $tone) = ( $1, $2 ) if $pinyin =~ /^(.*)(\d)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $pinyin =~ /^(.*)(\d)$/ 80 0 80
18 80 ▶ return $pinyin if ! defined $tone || $tone == 5;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $tone or $tone == 5 0 80 80
Condition33%1/3
not defined $tone or $tone == 5
l!l&&r!l&&!r
0080
MC/DC0%0/2
not defined $tone or $tone == 5
not defined $tone $tone == 5
Truth table33%1/3
not(A) or B
A= not defined $toneB= $tone == 5
ABresult
1X1
011
000
19  
20 80 ▶ if ( $tone < 1 || $tone > 5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tone < 1 or $tone > 5) 0 80 80
Condition33%1/3
$tone < 1 or $tone > 5
l!l&&r!l&&!r
0080
MC/DC0%0/2
$tone < 1 or $tone > 5
$tone < 1 $tone > 5
Truth table33%1/3
A or B
A= $tone < 1B= $tone > 5
ABresult
1X1
011
000
21 0 die "invalid pinyin $pinyin: tone $tone doesn't exist";
22 }
23  
24 80 $tone = $tones[$tone-1];
25 80 for my $vowel (qw/a o e iu i u v ü/) {
26 280 ▶ if ( $pinyin =~ /$vowel/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pinyin =~ /$vowel/) 80 200 280
27 80 ▶ if ( $vowel eq 'v' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vowel eq 'v') { } 4 76 80
28 4 $pinyin =~ s/v/u\x{308}$tone/;
29 }
30 else {
31 76 $pinyin =~ s/$vowel/$vowel$tone/;
32 }
33 80 last;
34 }
35 }
36 80 $pinyin =~ s/v/ü/g;
37  
38 80 return $pinyin;
39 };
40  
41 2 1;
42  
43 __END__
↑ Summary