| 1 | package Text::Keywords::Container; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | $Text::Keywords::Container::AUTHORITY = 'cpan:GETTY'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | $Text::Keywords::Container::VERSION = '0.900'; | |||||||||||||||||||||||||||
| 7 | } | ||||||||||||||||||||||||||||
| 8 | # ABSTRACT: Class for a container of serveral Text::Keywords::List | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Text::Keywords::Found; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | has lists => ( | |||||||||||||||||||||||||||
| 15 | is => 'ro', | ||||||||||||||||||||||||||||
| 16 | required => 1, | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | has shuffle => ( | ||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||
| 21 | 2 | ▶ | default => sub { 1 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 2 | ); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | has use_secondary => ( | ||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||
| 26 | 2 | ▶ | default => sub { 1 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 2 | ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | has params => ( | ||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||
| 31 | 2 | ▶ | default => sub {{}}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 2 | ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 8 | ▶ | sub find_keywords { | ||||||||||||||||||||||||||
|
Subroutine
find_keywords: called CC=29 SCAR=34.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 8 | my ( $self, $primary, $secondary ) = @_; | |||||||||||||||||||||||||||
| 36 | 8 | ▶ | $primary = $secondary if !$primary; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 8 | ▶ | return () if !$primary; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 8 | my @founds; | |||||||||||||||||||||||||||
| 39 | my @keywordlists; | ||||||||||||||||||||||||||||
| 40 | 8 | my $klpos = 0; | |||||||||||||||||||||||||||
| 41 | 8 | for (@{$self->lists}) { | |||||||||||||||||||||||||||
| 42 | 16 | push @keywordlists, [ $_, $_->count ]; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 8 | ▶ | while (@keywordlists) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 31 | my $klcount = scalar @keywordlists; | |||||||||||||||||||||||||||
| 46 | 31 | my $idx = $klpos % $klcount; | |||||||||||||||||||||||||||
| 47 | 31 | my $kl = $keywordlists[$idx]; | |||||||||||||||||||||||||||
| 48 | 31 | $klpos++; | |||||||||||||||||||||||||||
| 49 | 31 | for my $keyword (@{$kl->[0]->keywords}[$kl->[0]->count - $kl->[1],$kl->[0]->count - 1]) { | |||||||||||||||||||||||||||
| 50 | 43 | $kl->[1]--; | |||||||||||||||||||||||||||
| 51 | 43 | my $found; | |||||||||||||||||||||||||||
| 52 | 43 | ▶ | splice(@keywordlists, $idx, 1) if (!$kl->[1]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 43 | my $rx = qr/(?:^|[^\w]|_)($keyword)(?:$|[^\w]|_)/i; | |||||||||||||||||||||||||||
| 54 | 43 | my @text_found; | |||||||||||||||||||||||||||
| 55 | 43 | my $primary_str = $primary; | |||||||||||||||||||||||||||
| 56 | 43 | ▶ | push (@text_found, [$primary_str =~ $rx]), $primary_str =~ s{$rx}{} while $primary_str =~ $rx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 43 | my @secondary_found; | |||||||||||||||||||||||||||
| 58 | 43 | ▶ | if ($secondary && $self->use_secondary) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$secondary and $self->use_secondary
MC/DC0%0/2
$secondary and $self->use_secondary
$secondary
$self->use_secondary
Truth table33%1/3
A and B
A= $secondaryB= $self->use_secondary
| |||||||||||||||||||||||||||||
| 59 | 43 | my $con_str = $secondary; | |||||||||||||||||||||||||||
| 60 | 43 | ▶ | push (@secondary_found, [$con_str =~ $rx]), $con_str =~ s{$rx}{} while $con_str =~ $rx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 43 | for (@text_found) { | |||||||||||||||||||||||||||
| 63 | 19 | $found = 1; | |||||||||||||||||||||||||||
| 64 | 19 | my @matches = @{$_}; | |||||||||||||||||||||||||||
| 65 | 19 | my $found_string = shift @matches; | |||||||||||||||||||||||||||
| 66 | 19 | my $already_found = 0; | |||||||||||||||||||||||||||
| 67 | 19 | for my $cur_found (@founds) { | |||||||||||||||||||||||||||
| 68 | 20 | ▶ | if ($cur_found->found eq $found_string and @{$cur_found->matches} ~~ @matches) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cur_found->found eq $found_string and \@{$cur_found->matches;} ~~ \@matches
MC/DC50%1/2
$cur_found->found eq $found_string and \@{$cur_found->matches;} ~~ \@matches
$cur_found->found eq $found_string
\@{$cur_found->matches;} ~~ \@matches
Truth table66%2/3
A and B
A= $cur_found->found eq $found_stringB= \@{$cur_found->matches;} ~~ \@matches
| |||||||||||||||||||||||||||||
| 69 | 4 | $already_found = 1; last; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 19 | ▶ | next if $already_found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 15 | my $found_in_secondary = 0; | |||||||||||||||||||||||||||
| 74 | 15 | my $cidx = 0; | |||||||||||||||||||||||||||
| 75 | 15 | for (@secondary_found) { | |||||||||||||||||||||||||||
| 76 | 3 | my @cmatches = @{$_}; | |||||||||||||||||||||||||||
| 77 | 3 | my $found_cstring = shift @cmatches; | |||||||||||||||||||||||||||
| 78 | 3 | ▶ | if ($found_string eq $found_cstring and @matches ~~ @cmatches) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$found_string eq $found_cstring and \@matches ~~ \@cmatches
MC/DC50%1/2
$found_string eq $found_cstring and \@matches ~~ \@cmatches
$found_string eq $found_cstring
\@matches ~~ \@cmatches
Truth table66%2/3
A and B
A= $found_string eq $found_cstringB= \@matches ~~ \@cmatches
| |||||||||||||||||||||||||||||
| 79 | 1 | delete $secondary_found[$cidx]; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 3 | $cidx++; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 15 | push @founds, $self->_new_found($found_string,1,$found_in_secondary,$kl->[0],$keyword,\@matches); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 43 | my @still_secondary_found; | |||||||||||||||||||||||||||
| 86 | 43 | ▶ | if (@text_found) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 15 | for (@secondary_found) { | |||||||||||||||||||||||||||
| 88 | 3 | ▶ | push @still_secondary_found, $_ if ($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||
| 91 | 28 | @still_secondary_found = @secondary_found; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 43 | for (@still_secondary_found) { | |||||||||||||||||||||||||||
| 94 | 7 | $found = 1; | |||||||||||||||||||||||||||
| 95 | 7 | my @matches = @{$_}; | |||||||||||||||||||||||||||
| 96 | 7 | my $found_string = shift @matches; | |||||||||||||||||||||||||||
| 97 | 7 | my $already_found = 0; | |||||||||||||||||||||||||||
| 98 | 7 | for my $cur_found (@founds) { | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ($cur_found->found eq $found_string and @{$cur_found->matches} ~~ @matches) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cur_found->found eq $found_string and \@{$cur_found->matches;} ~~ \@matches
MC/DC0%0/2
$cur_found->found eq $found_string and \@{$cur_found->matches;} ~~ \@matches
$cur_found->found eq $found_string
\@{$cur_found->matches;} ~~ \@matches
Truth table33%1/3
A and B
A= $cur_found->found eq $found_stringB= \@{$cur_found->matches;} ~~ \@matches
| |||||||||||||||||||||||||||||
| 100 | 0 | $already_found = 1; last; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 7 | ▶ | next if $already_found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 7 | push @founds, $self->_new_found($found_string,0,1,$kl->[0],$keyword,\@matches); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 43 | ▶ | last if $self->shuffle and $found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->shuffle and $found
MC/DC50%1/2
$self->shuffle and $found
$self->shuffle
$found
Truth table66%2/3
A and B
A= $self->shuffleB= $found
| |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 8 | return @founds; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 22 | ▶ | sub _new_found { | ||||||||||||||||||||||||||
|
Subroutine
_new_found: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 113 | 22 | my ( $self, $found, $in_primary, $in_secondary, $keywordlist, $keyword, $matches ) = @_; | |||||||||||||||||||||||||||
| 114 | 22 | ▶ | return Text::Keywords::Found->new({ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 115 | keyword => $keyword, | ||||||||||||||||||||||||||||
| 116 | found => $found, | ||||||||||||||||||||||||||||
| 117 | list => $keywordlist, | ||||||||||||||||||||||||||||
| 118 | matches => $matches, | ||||||||||||||||||||||||||||
| 119 | in_primary => $in_primary ? 1 : 0, | ||||||||||||||||||||||||||||
| 120 | in_secondary => $in_secondary ? 1 : 0, | ||||||||||||||||||||||||||||
| 121 | container => $self | ||||||||||||||||||||||||||||
| 122 | }); | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2 | 1; | |||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||