Acme-Tie-Eleet
view release on metacpan or search on metacpan
lib/Acme/Tie/Eleet.pm view on Meta::CPAN
}
# 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;
my @what = split "([.?!\n])", lc $line;
while ( my ($what, $punc) = splice @what, 0, 2 ) {
# Build the sentence.
$self->{add_before} and $what = $self->_apply_add_before($what);
$self->{add_after} and $what = $self->_apply_add_after($what);
defined($punc) and $what .= $punc;
my $extra = $self->_apply_extra_sent();
$extra and $what .= " $extra";
# Transform chars.
foreach my $plugin ( qw( words spacer letters case_mixer ) ) {
my $meth = "_apply_$plugin";
$self->{$plugin} and $what = $self->$meth($what);
}
$sentence .= $what;
}
return $sentence;
}
# By default, tie standard filedescriptors.
# tie *STDOUT, __PACKAGE__, *STDOUT;
# tie *STDERR, __PACKAGE__, *STDERR;
1;
__END__
=head1 NAME
Acme::Tie::Eleet - Perl extension to 5pE4k 1Ik3 4n 3l337!
=head1 SYNOPSIS
B<!!!See the BUGS section below!!!>
use Acme::Tie::Eleet;
print "This is eleet!\n";
tie *OUT, 'Acme::Tie::Eleet', *OUT, case_mixer => "1/1";
print OUT "This is eleet\n";
Or, even, to translate instant sentences:
perl -MAcme::Tie::Eleet -p -e ''
tie $bar, 'Acme::Tie::Eleet', spacer => 0;
$bar = "eleet";
print $bar;
=head1 DESCRIPTION
Have you ever wanted to speak like an eleet? Do you feel like it's too
difficult to do your case mixin' manually? Tired of being laugh at by
your mates because your quotes don't make you look like an h4x0r?
Well, there's a solution, and you're reading the documentation of the
module specially made for u, Ye4h M4n!
This module basically allows you to perform a tie on filehandles,
converting text written to it; or a tie on scalars, converting text
they holds.
And since it's quite difficult to do urself a tie, the module will
also tie the 2 (no, not the letter 'S', the figure, u b4st4rd)
standard output file descriptors perl comes with (aka, STDOUT and
STDERR). A simple use of the module and you're ready to go! Fe4R u5!
=head2 Parameters supported by tie (both TIEHANDLE and TIESCALAR)
=over 4
=item o letters => <percentage>
The parameter allow you to transform letters to corresponding number
(ie, transform l to 1, e to 3, etc.) with a given percentage. Default
is 25 (1 char out of 4 being translitterate - if possible). That's 31337!
=item o spacer => <percentage>|<pattern>
Add extra spaces between chars. You can tell it to add random spaces
with a given percentage. Eg, 'spacer => 50' will add about 1 space
every two chars, whereas 'spacer => 0' will add no extra spaces. Or
you can provide a pattern of the form "m/n" which will be understood
as 'add an extra space after each of the m next chars, then do not add
extra space after the n next chars'. For example, 'spacer => "1/1"'
will add an extra space after one char out of two, whereas 'spacer =>
"1/0" will add extra spaces after each char. Default is 0 (no extra
space). T h a t r o c k s !
=item o case_mixer => <percentage>|<pattern>
Put some chars into uppercase. You can tell it to convert random chars
( run in 3.149 seconds using v1.01-cache-2.11-cpan-364913b4093 )