line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::Substitute; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.007'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Exporter::Easy ( |
6
|
2
|
|
|
|
|
11
|
OK => [qw/get_all_substitutes/], |
7
|
2
|
|
|
2
|
|
2509
|
); |
|
2
|
|
|
|
|
2266
|
|
8
|
2
|
|
|
2
|
|
943
|
use Set::CrossProduct; |
|
2
|
|
|
|
|
3018
|
|
|
2
|
|
|
|
|
51
|
|
9
|
2
|
|
|
2
|
|
1042
|
use Params::Validate qw(:all); |
|
2
|
|
|
|
|
15393
|
|
|
2
|
|
|
|
|
421
|
|
10
|
2
|
|
|
2
|
|
807
|
use strictures 2; |
|
2
|
|
|
|
|
2285
|
|
|
2
|
|
|
|
|
70
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub get_all_substitutes { |
13
|
2
|
|
|
2
|
1
|
1897
|
my %params = validate( |
14
|
|
|
|
|
|
|
@_, { |
15
|
|
|
|
|
|
|
string => { type => SCALAR }, |
16
|
|
|
|
|
|
|
substitutions => { type => HASHREF }, |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
10
|
my %subs = %{$params{substitutions}}; |
|
2
|
|
|
|
|
10
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
3
|
my @character_sets = do { |
23
|
2
|
|
|
|
|
4
|
my @csets; |
24
|
2
|
|
|
|
|
8
|
my @chars = split //, $params{string}; |
25
|
2
|
|
|
|
|
4
|
for my $char (@chars) { |
26
|
10
|
100
|
|
|
|
15
|
if (exists $subs{$char}) { |
27
|
6
|
|
|
|
|
14
|
push @csets, [ split(//, $subs{$char}) ]; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
4
|
|
|
|
|
6
|
push @csets, [ $char ]; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
@csets |
34
|
2
|
|
|
|
|
5
|
}; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
13
|
my $exploded_results = Set::CrossProduct->new([@character_sets])->combinations; |
37
|
2
|
|
|
|
|
710
|
my @imploded_results = map { join '', @$_ } @$exploded_results; |
|
20
|
|
|
|
|
24
|
|
38
|
2
|
|
|
|
|
19
|
return @imploded_results; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# ABSTRACT: generate strings using different combinations of subsitute characters |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |