Acme-Tie-Eleet
view release on metacpan or search on metacpan
lib/Acme/Tie/Eleet.pm view on Meta::CPAN
$target = $before.$target;
}
return $target;
}
# Add end of sentences randomly.
sub _apply_add_after {
my ($self, $target) = @_;
if ( rand(100) < $self->{add_after} ) {
my $after = $end[ rand( int(@end) ) ];
$target .= $after;
}
return $target;
}
# Mix case as wanted.
sub _apply_case_mixer {
my ($self, $target) = @_;
if ( $self->{case_mixer} =~ m!^(\d+)/(\d+)$! ) {
# Fixed pattern.
my $what = "";
my ($m, $n) = ( $1, $2 );
for my $c (split //, $target) {
$self->{_case_mix} =~ m/^([mn])(\d+)$/;
$what .= ($1 eq "m") ? uc($c) : $c;
my $new;
my $count = $2 + 1;
if ( $1 eq "m" ) {
$2+1 != $m and $new = "m$count";
$2+1 == $m && $n == 0 and $new = "m0";
$2+1 == $m && $n != 0 and $new = "n0";
} else {
$2+1 != $n and $new = "n$count";
$2+1 == $n && $m == 0 and $new = "n0";
$2+1 == $n && $m != 0 and $new = "m0";
}
$self->{_case_mix} = $new;
}
$target = $what;
} else {
# Put extra space at random.
$target =~ s/(.)/rand(100)<$self->{case_mixer}?uc($1):$1/eg;
}
return $target;
}
# Add whole sentences randomly.
sub _apply_extra_sent {
my $self = shift;
if ( rand(100) < $self->{extra_sent} ) {
return $sentences[rand( @sentences ) ];
}
return undef;
}
# Transform o to 0, l to 1, etc. That's 31337!
sub _apply_letters {
my ($self, $target) = @_;
return join "", map { rand(100) < $self->{letters} && exists $letter{$_} ?
( ref($letter{$_}) eq ref([]) ) ?
$letter{$_}[rand( @{$letter{$_}} ) ] :
$letter{$_}
: $_ } split //, $target;
}
# Put extra space between chars.
sub _apply_spacer {
my ($self, $target) = @_;
if ( $self->{spacer} =~ m!^(\d+)/(\d+)$! ) {
# Fixed pattern.
my $what = "";
my ($m, $n) = ( $1, $2 );
for my $c (split //, $target) {
$self->{_space} =~ m/^([mn])(\d+)$/;
$what .= ($1 eq "m") ? "$c " : $c;
my $new;
my $count = $2 + 1;
if ( $1 eq "m" ) {
$2+1 != $m and $new = "m$count";
$2+1 == $m && $n == 0 and $new = "m0";
$2+1 == $m && $n != 0 and $new = "n0";
} else {
$2+1 != $n and $new = "n$count";
$2+1 == $n && $m == 0 and $new = "n0";
$2+1 == $n && $m != 0 and $new = "m0";
}
$self->{_space} = $new;
}
$target = $what;
} else {
# Put extra space at random.
$target =~ s/(.)/rand(100)<$self->{spacer}?"$1 ":$1/eg;
}
return $target;
}
# Transform words according to %words.
sub _apply_words {
my ($self, $target) = @_;
my @what = ();
for my $word ( split / /, $target ) {
if ( exists( $words{$word} ) ) {
my $subst = $words{$word};
$word = ref($subst) eq ref([]) ?
$subst->[ rand( int(@$subst) ) ]
: $subst;
}
push @what, $word;
}
return join " ", @what;
}
# Main entry point for string transformation.
sub _transform {
my ($self, $line) = @_;
$line or return; # Case undef.
my $sentence;
( run in 2.279 seconds using v1.01-cache-2.11-cpan-364913b4093 )