line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::CountString; |
2
|
3
|
|
|
3
|
|
131606
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
169
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
82
|
|
4
|
3
|
|
|
3
|
|
972
|
use utf8; |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
21
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $COUNTER; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
3
|
|
|
3
|
|
25
|
my ($class, $implement) = @_; |
12
|
|
|
|
|
|
|
|
13
|
3
|
100
|
66
|
|
|
26
|
$COUNTER = ($implement && $implement eq 'split') |
14
|
|
|
|
|
|
|
? \&_split_implement |
15
|
|
|
|
|
|
|
: \&_regexp_implement; |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
|
|
6
|
my $caller = caller; |
18
|
3
|
|
|
3
|
|
347
|
no strict 'refs'; ## no critic |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1144
|
|
19
|
3
|
|
|
|
|
7
|
*{"${caller}::count_string"} = \&count_string; |
|
3
|
|
|
|
|
1015
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _regexp_implement { |
23
|
29
|
100
|
100
|
29
|
|
122
|
return 0 if !defined($_[0]) || $_[0] eq ''; |
24
|
27
|
100
|
100
|
|
|
99
|
return 0 if !defined($_[1]) || $_[1] eq ''; |
25
|
25
|
|
|
|
|
193
|
return () = ($_[0] =~ /\Q$_[1]\E/g); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _split_implement { |
29
|
29
|
100
|
100
|
29
|
|
152
|
return 0 if !defined($_[0]) || $_[0] eq ''; |
30
|
27
|
100
|
100
|
|
|
115
|
return 0 if !defined($_[1]) || $_[1] eq ''; |
31
|
25
|
|
|
|
|
251
|
my @list = split /\Q$_[1]\E/, $_[0], -1; |
32
|
25
|
|
|
|
|
146
|
return scalar(@list) - 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub count_string { |
36
|
52
|
|
|
52
|
1
|
5387
|
my $target_text = shift; |
37
|
|
|
|
|
|
|
|
38
|
52
|
|
|
|
|
57
|
my $result; |
39
|
|
|
|
|
|
|
|
40
|
52
|
100
|
|
|
|
115
|
if (@_ == 1) { |
41
|
50
|
|
|
|
|
95
|
$result = $COUNTER->($target_text, $_[0]); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
2
|
|
|
|
|
8
|
for my $string (@_) { |
45
|
8
|
|
|
|
|
17
|
$result->{$string} = $COUNTER->($target_text, $string); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
52
|
|
|
|
|
221
|
return $result; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |