Keywords/Container.pm

filter: Statementstmt 96.5% 85 / 88 Branchbran 85.2% 29 / 34 Conditioncond 53.3% 8 / 15 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 1 totaltotal 85.4% 135 / 158 CC 31 SCAR 31.3
CC
31
Cov
89%
find_keywords
31.0
_new_found
3.0
BEGIN
1.0
CRAP 22.9
↑ Summary Keywords.pm »
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
BranchTrueFalseTotal
unless $primary 0 8 8
37 8 ▶ return () if !$primary;
Branch: 1 branch
BranchTrueFalseTotal
unless $primary 0 8 8
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
BranchTrueFalseTotal
if (@keywordlists) 31 8 39
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
BranchTrueFalseTotal
unless $kl->[1] 16 27 43
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
BranchTrueFalseTotal
$primary_str =~ /$rx/ and do { push(@text_found, [$primary_str =~ /$rx/]), $primary_str =~ s/$rx// } 19 43 62
57 43 my @secondary_found;
58 43 ▶ if ($secondary && $self->use_secondary) {
Branch: 1 branch
BranchTrueFalseTotal
if ($secondary and $self->use_secondary) 43 0 43
Condition33%1/3
$secondary and $self->use_secondary
!ll&&!rl&&r
0043
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$con_str =~ /$rx/ and do { push(@secondary_found, [$con_str =~ /$rx/]), $con_str =~ s/$rx// } 8 43 51
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
BranchTrueFalseTotal
if ($cur_found->found eq $found_string and \@{$cur_found->matches;} ~~ \@matches) 4 16 20
Condition66%2/3
$cur_found->found eq $found_string and \@{$cur_found->matches;} ~~ \@matches
!ll&&!rl&&r
1604
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
ABresult
0X0
100
111
69 4 $already_found = 1; last;
70 }
71 }
72 19 ▶ next if $already_found;
Branch: 1 branch
BranchTrueFalseTotal
if $already_found 4 15 19
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
BranchTrueFalseTotal
if ($found_string eq $found_cstring and \@matches ~~ \@cmatches) 1 2 3
Condition66%2/3
$found_string eq $found_cstring and \@matches ~~ \@cmatches
!ll&&!rl&&r
201
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (@text_found) { } 15 28 43
87 15 for (@secondary_found) {
88 3 ▶ push @still_secondary_found, $_ if ($_);
Branch: 1 branch
BranchTrueFalseTotal
if $_ 2 1 3
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
BranchTrueFalseTotal
if ($cur_found->found eq $found_string and \@{$cur_found->matches;} ~~ \@matches) 0 13 13
Condition33%1/3
$cur_found->found eq $found_string and \@{$cur_found->matches;} ~~ \@matches
!ll&&!rl&&r
1300
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
ABresult
0X0
100
111
100 0 $already_found = 1; last;
101 }
102 }
103 7 ▶ next if $already_found;
Branch: 1 branch
BranchTrueFalseTotal
if $already_found 0 7 7
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
BranchTrueFalseTotal
if $self->shuffle and $found 20 23 43
Condition66%2/3
$self->shuffle and $found
!ll&&!rl&&r
02320
MC/DC50%1/2
$self->shuffle and $found
$self->shuffle $found
Truth table66%2/3
A and B
A= $self->shuffleB= $found
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$in_primary ? : 15 7 22
$in_secondary ? : 7 15 22
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__
↑ Summary Keywords.pm »