| 1 | package Lingua::ZH::CCDICT::Storage::InMemory; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base 'Lingua::ZH::CCDICT'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Params::Validate qw( validate SCALAR ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Lingua::ZH::CCDICT::ResultItem; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Lingua::ZH::CCDICT::ResultSet::Array; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub new | ||||||||||||||||||||||||||||
| 15 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 17 | 1 | my %p = validate( @_, | |||||||||||||||||||||||||||
| 18 | { file => { type => SCALAR, optional => 1 }, | ||||||||||||||||||||||||||||
| 19 | }, | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | $self->parse_source_file( $p{file} ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | return $self; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub _real_add_entry | ||||||||||||||||||||||||||||
| 30 | 27484 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_real_add_entry: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 31 | 27484 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | 27484 | my $unicode = shift; | |||||||||||||||||||||||||||
| 33 | 27484 | my $entry = shift; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 27484 | foreach my $key ( keys %$entry ) | |||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | 252231 | ▶ | next if $key eq 'english' || $key eq 'unicode'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "english" or $key eq "unicode"
MC/DC100%2/2
$key eq "english" or $key eq "unicode"
$key eq "english"
$key eq "unicode"
Truth table100%3/3
A or B
A= $key eq "english"B= $key eq "unicode"
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 203223 | ▶ | foreach my $val ( eval { @{ $entry->{$key} } } ? @{ $entry->{$key} } : $entry->{$key} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | # intentionally stringify to take advantage of | ||||||||||||||||||||||||||||
| 42 | # stringification overloading for romanizations | ||||||||||||||||||||||||||||
| 43 | 262395 | push @{ $self->{$key}{"$val"} }, $unicode; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 27484 | $self->{unicode}{$unicode} = $entry; | |||||||||||||||||||||||||||
| 48 | 27484 | $self->{unicode}{$unicode}{unicode} = $unicode; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub all_characters | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
all_characters: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | return | ||||||||||||||||||||||||||||
| 56 | Lingua::ZH::CCDICT::ResultSet::Array->new | ||||||||||||||||||||||||||||
| 57 | ( results => | ||||||||||||||||||||||||||||
| 58 | 0 | [ map { Lingua::ZH::CCDICT::ResultItem->new( %{ $self->{unicode}{$_} } ) } | |||||||||||||||||||||||||||
| 59 | 0 | sort keys %{ $self->{unicode} } ] | |||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub match_unicode | ||||||||||||||||||||||||||||
| 64 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
match_unicode: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 9 | my %seen; | |||||||||||||||||||||||||||
| 68 | 9 | ▶ | my @chars = map { $seen{$_}++ ? () : $_ } sort @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 9 | my @results; | |||||||||||||||||||||||||||
| 71 | 9 | foreach my $char (@chars) | |||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 32 | ▶ | if ( exists $self->{unicode}{$char} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | push @results, | ||||||||||||||||||||||||||||
| 76 | 32 | Lingua::ZH::CCDICT::ResultItem->new( %{ $self->{unicode}{$char} } ); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 9 | return Lingua::ZH::CCDICT::ResultSet::Array->new( array => \@results ); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | sub _match | ||||||||||||||||||||||||||||
| 84 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_match: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | 3 | my $type = shift; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | return | ||||||||||||||||||||||||||||
| 89 | 4 | $self->match_unicode( map { @{ $self->{$type}{$_} } } | |||||||||||||||||||||||||||
| 90 | 3 | grep { exists $self->{$type}{$_} } | |||||||||||||||||||||||||||
| 91 | @_ | ||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub entry_count | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
entry_count: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | return scalar keys %{ $_[0]->{unicode} }; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | 1; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||