| 1 | # | ||||||||||||||||||||||||||||
| 2 | # WuManber.pm | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # Copyright (c) 2007-2011, Juergen Weigert, openSUSE.org | ||||||||||||||||||||||||||||
| 5 | # This module is free software. It may be used, redistributed | ||||||||||||||||||||||||||||
| 6 | # and/or modified under the same terms as Perl (version 5.8.8) itself. | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # This used to have a first() / next() iterator interface, which turned out to be | ||||||||||||||||||||||||||||
| 9 | # incompatible with the chaotic state machine of wu manber mgrep implementation. | ||||||||||||||||||||||||||||
| 10 | # Deprecated if favour of a simpler but more memory hungry find_all(). | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Search::WuManber; | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | require Exporter; | |||||||||||||||||||||||||||
| 18 | 2 | require DynaLoader; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use base qw(Exporter DynaLoader); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 2 | our @EXPORT_OK = qw(); # exportable | |||||||||||||||||||||||||||
| 22 | 2 | our $VERSION = '0.25'; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | bootstrap Search::WuManber $VERSION; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub new | ||||||||||||||||||||||||||||
| 27 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=23.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 1 | my ($self, $list, $opts) = @_; | |||||||||||||||||||||||||||
| 29 | 1 | ▶ | my $class = ref($self) || $self; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | die "new: patterns parameter not an ARRAY-ref\n" unless ref $list eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 1 | my $this = { patterns => $list }; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | my %opt = | |||||||||||||||||||||||||||
| 34 | ( | ||||||||||||||||||||||||||||
| 35 | return_string => 0, | ||||||||||||||||||||||||||||
| 36 | case_sensitive => 1, | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | for my $o (keys %opt) | |||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 2 | ▶ | $this->{$o} = ($opts && defined($opts->{$o})) ? $opts->{$o} : $opt{$o}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opts and defined $opts->{$o}
MC/DC50%1/2
$opts and defined $opts->{$o}
$opts
defined $opts->{$o}
Truth table66%2/3
A and B
A= $optsB= defined $opts->{$o}
| |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | delete $opts->{$o} if $opts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | die "new: unknown options: ". join(',', keys %$opts) . "\n try these: " . join(',', keys %opt) . "\n" if keys %$opts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | my $time = time(); | |||||||||||||||||||||||||||
| 48 | 1 | ▶ | init_tables($this) or die "internal error: init_tables failed.\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 1 | $this->{init_time_sec} = time() - $time; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | return bless $this, $class; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub first | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
first: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 0 | my ($self, $text) = @_; | |||||||||||||||||||||||||||
| 57 | 0 | delete $self->{result}; | |||||||||||||||||||||||||||
| 58 | 0 | return $self->next($text); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # This is a method, not a bare subroutine. | ||||||||||||||||||||||||||||
| 62 | sub next ## no critic (ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
next: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 0 | my ($self,$text) = @_; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | $self->{result} = $self->all($text) unless $self->{result}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # my $o = shift @{$self->{result}}; | ||||||||||||||||||||||||||||
| 68 | # my $i = shift @{$self->{result}}; | ||||||||||||||||||||||||||||
| 69 | # return [$o, $i]; | ||||||||||||||||||||||||||||
| 70 | 0 | return shift @{$self->{result}}; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | sub all | ||||||||||||||||||||||||||||
| 74 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
all: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 1 | my ($self, $text) = @_; | |||||||||||||||||||||||||||
| 76 | 1 | my $m = find_all($self, $text); | |||||||||||||||||||||||||||
| 77 | 1 | ▶ | if ($m && $self->{return_string}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$m and $self->{"return_string"}
MC/DC0%0/2
$m and $self->{"return_string"}
$m
$self->{"return_string"}
Truth table33%1/3
A and B
A= $mB= $self->{"return_string"}
| |||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||
| 79 | 1 | for my $p (@$m) | |||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||
| 81 | 16 | push @$p, $self->{patterns}[$p->[1]]; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 1 | return $m; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 2 | 1; | |||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||