CCDICT/Storage/InMemory.pm

filter: Statementstmt 88.3% 53 / 60 Branchbran 75.0% 6 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 83.3% 10 / 12 Podpod 100% 4 / 4 totaltotal 87.6% 78 / 89 CC 9 SCAR 11.7
CC
9
Cov
87%
_real_add_entry
6.0
match_unicode
4.0
all_characters
2.0
CRAP 3.2
« CCDICT/ResultSet/BerkeleyDB.pm ↑ Summary CCDICT/ResultSet/Array.pm »
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
BranchTrueFalseTotal
if $key eq "english" or $key eq "unicode" 49008 203223 252231
Condition100%3/3
$key eq "english" or $key eq "unicode"
l!l&&r!l&&!r
2152427484203223
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"
ABresult
1X1
011
000
38  
39 203223 ▶ foreach my $val ( eval { @{ $entry->{$key} } } ? @{ $entry->{$key} } : $entry->{$key} )
Branch: 1 branch
BranchTrueFalseTotal
eval { do { @{$entry->{$key};} } } ? : 68968 134255 203223
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
BranchTrueFalseTotal
$seen{$_}++ ? : 0 32 32
69  
70 9 my @results;
71 9 foreach my $char (@chars)
72 {
73 32 ▶ if ( exists $self->{unicode}{$char} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"unicode"}{$char}) 32 0 32
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__
« CCDICT/ResultSet/BerkeleyDB.pm ↑ Summary CCDICT/ResultSet/Array.pm »