blib/lib/Unicode/Unihan.pm

filter: Statementstmt 78.1% 50 / 64 Branchbran 30.0% 9 / 30 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 3 totaltotal 62.9% 73 / 116 CC 20 SCAR 26.7
CC
20
Cov
62%
unload
42.0
load
19.1
__ANON__
7.1
CRAP 14.5
↑ Summary
1 package Unicode::Unihan;
2  
3 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.046';
8 2 our $DEBUG = 0;
9  
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶BEGIN{ @AnyDBM_File::ISA = qw(DB_File GDBM_File SDBM_File) ; }
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use AnyDBM_File;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶sub new($;){
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
16 2 my $class = shift;
17 2 my $dir = __FILE__; $dir =~ s/\.pm//o;
18 2 ▶ -d $dir or die "DB Directory $dir nonexistent!";
Branch: 1 branch
BranchTrueFalseTotal
-d $dir or die "DB Directory $dir nonexistent!" 2 0 2
19 2 return bless { '_dir_' => $dir, @_ } => $class;
20 }
21  
22 88 ▶sub load($$){
Subroutine load: called CC=9 SCAR=29.5
Pod undocumented
23 88 my ($self, $name) = @_;
24 88 ▶ if ($self->{'-savemem'}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"-savemem"}) 0 88 88
25 0 for my $k (keys %$self){
26 0 ▶ $k eq $name and next;
Branch: 1 branch
BranchTrueFalseTotal
$k eq $name and next 0 0 0
27 0 ▶ $k =~ /^[A-Z]/o and delete $self->{$k};
Branch: 1 branch
BranchTrueFalseTotal
$k =~ /^[A-Z]/o and delete $self->{$k} 0 0 0
28 }
29 }
30 88 ▶ unless ( $self->{$name} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$name}) 88 0 88
31 88 my $file = $self->{_dir_} . "/$name.db";
32 # SDBM files attach a .dir and .pag (two files), so allow for
33 # that secret .dir at the end
34 88 ▶ (-f $file or -f "$file.dir") or croak "There is no DB for $name";
Branch: 1 branch
BranchTrueFalseTotal
-f $file or -f "$file.dir" or croak("There is no DB for $name") 88 0 88
Condition33%1/3
-f $file or -f "$file.dir"
l!l&&r!l&&!r
0880
MC/DC0%0/2
-f $file or -f "$file.dir"
-f $file -f "$file.dir"
Truth table33%1/3
A or B
A= -f $fileB= -f "$file.dir"
ABresult
1X1
011
000
35 88 ▶ tie %{$self->{$name}}, 'AnyDBM_File', $file, O_RDONLY, 0444
Branch: 1 branch
BranchTrueFalseTotal
tie %{$$self{$name};}, "AnyDBM_File", $file, 0, 292 or die "${file}: $!" 88 0 88
36 or die "$file: $!";
37 }
38 88 $self;
39 }
40  
41 0 ▶sub unload($;){
Subroutine unload: not called CC=6 SCAR=37.4
Pod undocumented
42 0 my $self = shift;
43 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
44 0 ▶ while(my $k = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $k = shift()) 0 0 0
45 0 ▶ $k =~ /^[A-Z]/o and delete $self->{$k};
Branch: 1 branch
BranchTrueFalseTotal
$k =~ /^[A-Z]/o and delete $self->{$k} 0 0 0
46 }
47 }else{
48 0 for my $k (keys %$self){
49 0 ▶ $k =~ /^[A-Z]/o and delete $self->{$k};
Branch: 1 branch
BranchTrueFalseTotal
$k =~ /^[A-Z]/o and delete $self->{$k} 0 0 0
50 }
51 }
52 0 $self;
53 }
54  
55 2 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.6
56 2 ▶ $DEBUG and warn "$_[0] destroyed!";
Branch: 1 branch
BranchTrueFalseTotal
$Unicode::Unihan::DEBUG and warn "$_[0] destroyed!" 0 2 2
57 }
58  
59 88 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=1 SCAR=0.2
60 88 my $self = shift;
61 88 my $name = our $AUTOLOAD;
62 88 $name =~ s/.*:://o;
63 88 $self->load($name);
64 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
65 88 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: called CC=5 SCAR=19.6
66 88 ▶ my $self = shift; @_ or return;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return 88 0 88
67 88 ▶ my $str = shift; length($str) or return;
Branch: 1 branch
BranchTrueFalseTotal
length $str or return 88 0 88
68 88 ▶ if (wantarray){
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 88 88
69 0 my @result = ();
70 0 for my $ord (unpack("U*", $str)){
71 0 push @result, $self->{$name}{$ord};
72 }
73 0 return @result;
74 }else{
75 88 return $self->{$name}{ord($str)};
76 }
77 88 };
78 88 return $self->$name(@_);
79 }
80  
81 2 1;
82 __END__
↑ Summary