Acme-Tie-Eleet
view release on metacpan or search on metacpan
lib/Acme/Tie/Eleet.pm view on Meta::CPAN
return bless( $self, $pkg );
}
sub TIESCALAR {
# Process args.
my $pkg = shift;
ref $pkg and croak "Not an instance method";
my $self = &_new; # magic call.
$self->{value} = undef;
# Return it.
return bless( $self, $pkg );
}
#--
# Handlers.
# Catch scalar fetching.
lib/Acme/Tie/Eleet.pm view on Meta::CPAN
}
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{$_}
lib/Acme/Tie/Eleet.pm view on Meta::CPAN
}
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();
( run in 1.430 second using v1.01-cache-2.11-cpan-d80b1682f3f )