blib/lib/Lingua/Han/Cantonese.pm

filter: Statementstmt 100% 41 / 41 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 90.3% 56 / 62 CC 8 SCAR 12.0
CC
8
Cov
92%
han2Cantonese
5.0
new
4.0
BEGIN
1.0
CRAP 3.3
↑ Summary
1 package Lingua::Han::Cantonese;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 $VERSION = '0.12';
7  
8 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Lingua::Han::Utils qw/Unihan_value/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
12 2 my $class = shift;
13 2 my $dir = __FILE__; $dir =~ s/\.pm//o;
14 2 ▶ -d $dir or die "Directory $dir nonexistent!";
Branch: 1 branch
BranchTrueFalseTotal
-d $dir or die "Directory $dir nonexistent!" 2 0 2
15 2 my $self = { @_ };
16 2 my %ct;
17 2 my $file = File::Spec->catfile($dir, 'Cantonese.dat');
18 2 ▶ open(FH, $file) or die "$file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open FH, $file or die "${file}: $!" 2 0 2
19 2 ▶ while(<FH>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FH)) 46116 2 46118
20 46116 my ($uni, $ct) = split(/\s+/);
21 46116 $ct{$uni} = $ct;
22 }
23 2 close(FH);
24 2 $self->{'ct'} = \%ct;
25 2 return bless $self => $class;
26 }
27  
28 6 ▶sub han2Cantonese {
Subroutine han2Cantonese: called CC=5 SCAR=16.2
Pod undocumented
29 6 my ($self, $hanzi) = @_;
30  
31 6 my @code = Unihan_value($hanzi);
32  
33 6 my @result;
34 6 foreach my $code (@code) {
35 30 my $value = $self->{'ct'}->{$code};
36 30 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 12 18 30
37 12 ▶ $value =~ s/\d//isg unless ($self->{'tone'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"tone"} 12 0 12
38 } else {
39 # if it's not a Chinese, return original word
40 18 $value = pack("U*", hex $code);
41 }
42 30 push @result, lc $value;
43 }
44  
45 6 ▶ return wantarray ? @result : join('', @result);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 6 6
46  
47 }
48  
49 3 1;
50 __END__
↑ Summary