| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 25 | 0 | for my $k (keys %$self){ | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | $k eq $name and next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $k =~ /^[A-Z]/o and delete $self->{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 88 | ▶ | unless ( $self->{$name} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
-f $file or -f "$file.dir"
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"
| |||||||||||||||||||||||||||||
| 35 | 88 | ▶ | tie %{$self->{$name}}, 'AnyDBM_File', $file, O_RDONLY, 0444 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | while(my $k = shift) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | $k =~ /^[A-Z]/o and delete $self->{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | }else{ | ||||||||||||||||||||||||||||
| 48 | 0 | for my $k (keys %$self){ | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | $k =~ /^[A-Z]/o and delete $self->{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 67 | 88 | ▶ | my $str = shift; length($str) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 88 | ▶ | if (wantarray){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||