blib/lib/Search/Tools/Tokenizer.pm

filter: Statementstmt 96.0% 49 / 51 Branchbran 88.8% 16 / 18 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 95.2% 81 / 85 CC 12 SCAR 18.9
CC
12
Cov
94%
tokenize_pp
11.0
BUILD
2.1
BEGIN
1.0
CRAP 6.6
« blib/lib/Search/Tools/UTF8.pm ↑ Summary blib/lib/Search/Tools/Transliterate.pm »
1 package Search::Tools::Tokenizer;
2 32 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 32 extends 'Search::Tools::Object';
4 32 ▶use Search::Tools; # XS package required
Subroutine BEGIN: called CC=1 SCAR=0.0
5 32 ▶use Search::Tools::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 32 ▶use Search::Tools::TokenList;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 32 ▶use Search::Tools::UTF8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 32 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 32 our $VERSION = '1.007';
11  
12 6 ▶has 're' => ( is => 'rw', default => sub {qr/\w+(?:[\'\-\.]\w+)*/} );
Subroutine __ANON__: called CC=1 SCAR=0.0
13  
14 65 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=7.6
Pod documented
15 65 my $self = shift;
16 65 ▶ if ( $self->debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 65 65
17 0 $self->set_debug( $self->debug - 1 ); # XS debug a level higher
18 }
19 65 return $self;
20 }
21  
22 7 ▶sub tokenize_pp {
Subroutine tokenize_pp: called CC=11 SCAR=24.0
Pod documented
23 7 require Search::Tools::TokenPP;
24 7 require Search::Tools::TokenListPP;
25  
26 7 my $self = shift;
27 7 ▶ if ( !defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 0 7 7
28 0 croak "str required";
29 }
30  
31 # XS modifies the original arg, so we do too.
32 # this is same slight optimization XS does. ~5%
33 7 ▶ if ( !is_ascii( $_[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_ascii($_[0])) 2 5 7
34 2 $_[0] = to_utf8( $_[0] );
35 }
36 7 my $heat_seeker = $_[1];
37  
38 # match_num ($_[2]) not supported in PP
39  
40 7 my @heat = ();
41 7 my @tokens = ();
42 7 my $i = 0;
43 7 my $re = $self->{re};
44 7 ▶ my $heat_seeker_is_coderef
Branch: 1 branch
BranchTrueFalseTotal
defined $heat_seeker && ref $heat_seeker eq 'CODE' ? : 2 5 7
Condition100%3/3
defined $heat_seeker and ref $heat_seeker eq "CODE"
!ll&&!rl&&r
412
MC/DC100%2/2
defined $heat_seeker and ref $heat_seeker eq "CODE"
defined $heat_seeker ref $heat_seeker eq "CODE"
Truth table100%3/3
A and B
A= defined $heat_seekerB= ref $heat_seeker eq "CODE"
ABresult
0X0
100
111
45 = ( defined $heat_seeker and ref($heat_seeker) eq 'CODE' ) ? 1 : 0;
46  
47 # TODO is_sentence_* logic
48 7 for ( split( m/($re)/, $_[0] ) ) {
49 343 ▶ next unless length($_);
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 17 326 343
50 326 my $tok = bless(
51 { 'pos' => $i++,
52 str => $_,
53 is_hot => 0,
54 is_match => 0,
55 len => byte_length($_),
56 u8len => length($_),
57 },
58 'Search::Tools::TokenPP'
59 );
60 326 ▶ if ( $_ =~ m/^$re$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^$re$/) 170 156 326
61 170 $tok->{is_match} = 1;
62 170 ▶ if ($heat_seeker_is_coderef) {
Branch: 2 branches
BranchTrueFalseTotal
if ($heat_seeker_is_coderef) { } 13 157 170
elsif (defined $heat_seeker) { } 69 88 157
63 13 $heat_seeker->($tok);
64 }
65 elsif ( defined $heat_seeker ) {
66 69 $tok->{is_hot} = $_ =~ m/$heat_seeker/;
67 }
68 }
69 326 ▶ push( @heat, $tok->{pos} ) if $tok->{is_hot};
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"is_hot"} 1 325 326
70 326 push @tokens, $tok;
71 }
72 7 return bless(
73 { tokens => \@tokens,
74 num => $i,
75 'pos' => 0,
76 heat => \@heat,
77 },
78 'Search::Tools::TokenListPP'
79 );
80 }
81  
82 32 1;
83  
84 __END__
« blib/lib/Search/Tools/UTF8.pm ↑ Summary blib/lib/Search/Tools/Transliterate.pm »