| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $heat_seeker and ref $heat_seeker eq "CODE"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 61 | 170 | $tok->{is_match} = 1; | |||||||||||||||||||||||||||
| 62 | 170 | ▶ | if ($heat_seeker_is_coderef) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||