AhoCorasick.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 100% 54 / 54 CC 6 SCAR 8.5
CC
6
Cov
100%
find_first
4.0
find_all
2.0
__ANON__
2.0
CRAP 2.3
« AhoCorasick/SearchMachine.pm ↑ Summary
1 package Algorithm::AhoCorasick;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Algorithm::AhoCorasick::SearchMachine;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 require Exporter;
9  
10 4 our @ISA = qw(Exporter);
11  
12 4 our %EXPORT_TAGS = ( 'all' => [ qw(
13 find_first
14 find_all
15 ) ] );
16  
17 4 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
18  
19 4 our $VERSION = '0.04';
20  
21 61 ▶sub find_first {
Subroutine find_first: called CC=4 SCAR=13.9
Pod documented
22 61 my $text = shift;
23  
24 61 my $m = Algorithm::AhoCorasick::SearchMachine->new(@_);
25 58 ▶ my $rv = $m->feed($text, sub { [ @_ ]; });
Subroutine __ANON__: called CC=1 SCAR=0.0
26 58 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 55 3 58
27 55 ▶ return $rv ? @$rv : ();
Branch: 1 branch
BranchTrueFalseTotal
$rv ? : 54 1 55
28 } else {
29 3 ▶ return $rv ? $rv : undef;
Branch: 1 branch
BranchTrueFalseTotal
$rv ? : 1 2 3
30 }
31 }
32  
33 61 ▶sub find_all {
Subroutine find_all: called CC=2 SCAR=6.9
Pod documented
34 61 my $text = shift;
35  
36 61 my $m = Algorithm::AhoCorasick::SearchMachine->new(@_);
37  
38 58 my %total;
39 181 ▶ my $handle_all = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
40 181 my ($pos, $keyword) = @_;
41  
42 181 ▶ if (!exists($total{$pos})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $total{$pos}) 176 5 181
43 176 $total{$pos} = [ ];
44 }
45  
46 181 push @{$total{$pos}}, $keyword;
47  
48 181 undef;
49 58 };
50  
51 58 $m->feed($text, $handle_all);
52  
53 58 ▶ return keys(%total) ? \%total : undef;
Branch: 1 branch
BranchTrueFalseTotal
keys %total ? : 56 2 58
54 }
55  
56 4 1;
57  
58 __END__
« AhoCorasick/SearchMachine.pm ↑ Summary