File Coverage

blib/lib/String/Substitute.pm
Criterion Covered Total %
statement 29 29 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 38 38 100.0


line stmt bran cond sub pod time code
1             package String::Substitute;
2              
3             our $VERSION = '0.005';
4              
5             use Exporter::Easy (
6 2         13 OK => [qw/get_all_substitutes/],
7 2     2   2890 );
  2         2386  
8 2     2   1059 use Set::CrossProduct;
  2         3149  
  2         48  
9 2     2   883 use List::Gather;
  2         26034  
  2         16  
10 2     2   1552 use Params::Validate qw(:all);
  2         16284  
  2         356  
11 2     2   819 use strictures 2;
  2         2975  
  2         69  
12              
13             sub get_all_substitutes {
14 2     2 1 1165 my %params = validate(
15             @_, {
16             string => { type => SCALAR },
17             substitutions => { type => HASHREF },
18             }
19             );
20              
21 2         7 my %subs = %{$params{substitutions}};
  2         7  
22              
23 2         5 my @character_sets = gather {
24 2         8 my @chars = split //, $params{string};
25 2         4 for my $char (@chars) {
26 10 100       13 if (exists $subs{$char}) {
27 6         15 take [ split(//, $subs{$char}) ];
28             }
29             else {
30 4         6 take [ $char ];
31             }
32             }
33 2         4 };
34              
35 2         15 my $exploded_results = Set::CrossProduct->new([@character_sets])->combinations;
36 2         795 my @imploded_results = map { join '', @$_ } @$exploded_results;
  20         26  
37 2         19 return @imploded_results;
38             }
39              
40              
41             1;
42              
43             # ABSTRACT: generate strings using different combinations of subsitute characters
44              
45             __END__