blib/lib/Grapheme/Ngram.pm

filter: Statementstmt 100% 23 / 23 Branchbran 100% 10 / 10 Conditioncond 100% 5 / 6 (1 uncoverable) MC/DCmcdc 100% 2 / 4 (2 uncoverable) Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 100% 49 / 52 (3 uncoverable) CC 9 SCAR 12.3
CC
9
Cov
100%
from_tokens
5.0
new
4.0
ngram
2.0
CRAP 3.4
↑ Summary
1 package Grapheme::Ngram;
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  
7 1 our $VERSION = '0.006';
8  
9 6 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
10 6 my $class = shift;
11 # uncoverable condition false
12 6 ▶ bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class;
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 3 3 6
@_ > 1 ? : 1 2 3
Condition100%2/3
ref $class || $class
l!l&&r!l&&!r
420
MC/DC100%0/2
ref $class || $class
ref $class $class
Truth table100%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
13 }
14  
15 14 ▶sub ngram {
Subroutine ngram: called CC=2 SCAR=6.9
Pod documented
16 14 my ($self, $word, $width) = @_;
17  
18 14 ▶ return [] unless (length($word));
Branch: 1 branch
BranchTrueFalseTotal
unless length $word 3 11 14
19  
20 11 return $self->from_tokens(
21 $self->_tokenize($word),
22 $width
23 );
24 }
25  
26 11 ▶sub from_tokens {
Subroutine from_tokens: called CC=5 SCAR=16.1
Pod documented
27 11 my ($self, $tokens, $width) = @_;
28  
29 11 ▶ $width = 1 unless ($width && $width =~ m/^[1-9][0-9]*$/x);
Branch: 1 branch
BranchTrueFalseTotal
unless $width and $width =~ /^[1-9][0-9]*$/x 2 9 11
Condition100%3/3
$width and $width =~ /^[1-9][0-9]*$/x
!ll&&!rl&&r
119
MC/DC100%2/2
$width and $width =~ /^[1-9][0-9]*$/x
$width $width =~ /^[1-9][0-9]*$/x
Truth table100%3/3
A and B
A= $widthB= $width =~ /^[1-9][0-9]*$/x
ABresult
0X0
100
111
30  
31 11 ▶ return [join('',@$tokens)] unless ($width <= scalar @$tokens);
Branch: 1 branch
BranchTrueFalseTotal
unless $width <= scalar @$tokens 1 10 11
32  
33 10 my @ngrams;
34  
35 10 for my $i (0..scalar(@$tokens)-$width) {
36 13 my $ngram = join('',@$tokens[$i..$i+$width-1]);
37 13 push @ngrams,$ngram;
38 }
39  
40 10 return \@ngrams;
41 }
42  
43 12 ▶sub _tokenize { [$_[1] =~ m/(\X)/g] }
Subroutine _tokenize: called CC=1 SCAR=0.0
44  
45 1 1;
46  
47  
48 __END__
↑ Summary