Ngram.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 83.3% 5 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 82.3% 42 / 51 CC 5 SCAR 7.9
CC
5
Cov
89%
new
3.8
__ANON__
3.0
BEGIN
1.0
CRAP 2.2
↑ Summary Bigram.pm »
1 package Search::Fulltext::Tokenizer::Ngram;
2  
3 # ABSTRACT: Character n-gram tokenizer for Search::Fulltext
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Scalar::Util qw/looks_like_number/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = 0.01;
11  
12 32 ▶sub new {
Subroutine new: called CC=3 SCAR=13.3
Pod undocumented
13 32 my ($class, $token_length) = @_;
14  
15 32 ▶ unless (looks_like_number $token_length and $token_length > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($token_length) and $token_length > 0) 0 32 32
Condition33%1/3
&looks_like_number($token_length) and $token_length > 0
!ll&&!rl&&r
0032
MC/DC0%0/2
&looks_like_number($token_length) and $token_length > 0
&looks_like_number($token_length) $token_length > 0
Truth table33%1/3
A and B
A= &looks_like_number($token_length)B= $token_length > 0
ABresult
0X0
100
111
16 0 Carp::croak('Token length must be 1+.');
17 }
18  
19 32 bless +{ token_length => $token_length } => $class;
20 }
21  
22 32 ▶sub create_token_iterator {
Subroutine create_token_iterator: called CC=1 SCAR=0.0
Pod undocumented
23 32 my ($self, $text) = @_;
24  
25 32 my $token_index = -1;
26 32 my $n = $self->token_length;
27 218 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
28 GET_NEXT_TOKEN:
29 {
30 218 ++$token_index;
31 242 ▶ return if $token_index + $n > length($text);
Branch: 1 branch
BranchTrueFalseTotal
if $token_index + $n > length $text 21 221 242
32 221 my $token = substr $text, $token_index, $n;
33 221 ▶ redo GET_NEXT_TOKEN if $token =~ /\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $token =~ /\s/ 24 197 221
34 197 return ($token, $n, $token_index, $token_index + $n, $token_index);
35 }
36 32 };
37 }
38  
39 32 ▶sub token_length { $_[0]->{token_length} }
Subroutine token_length: called CC=1 SCAR=0.0
Pod undocumented
40  
41 1 1;
42  
43 __END__
↑ Summary Bigram.pm »