Acme-LAUTER-DEUTSCHER
view release on metacpan or search on metacpan
lib/PerlIO/via/LAUTER_DEUTSCHER.pm view on Meta::CPAN
package PerlIO::via::LAUTER_DEUTSCHER;
use strict;
use warnings;
our $VERSION = '1.02';
use Lingua::Translate;
use Carp;
our $fish;
sub import {
$fish = Lingua::Translate->new( src => 'en', dest => 'de' )
or croak 'unable to translate from en to de';
}
sub unimport {
undef $fish;
}
sub PUSHED {
my $self = '';
bless \$self, shift;
}
sub FILL {
my ( $self, $fh ) = @_;
return defined $fh ? $self->_translate(<$fh>) : undef;
}
sub WRITE {
my ( $self, $text, $fh ) = @_;
return 0 unless defined $text;
if ( my $out = $self->_translate($text) ) {
print $fh $out;
return length $out;
}
else {
return -1;
}
}
sub _translate {
my ( $self, $line ) = @_;
return if not ref $fish;
return if not defined $line or $line !~ /\w/;
my $out = uc $fish->translate($line);
for ($out) {
s/ \b TIMMY \b /DIETER/gsx; # a solid German name
s/ (?<=\w) \. (?=\W|\Z) /!/gsx; # there's no whispering!
}
chomp $out;
return "$out\n";
}
1;
__END__
=head1 NAME
PerlIO::via::LAUTER_DEUTSCHER - a Perl IO layer to make output indistinguishable from someone yelling German
=head1 SYNOPSIS
use PerlIO::via::LAUTER_DEUTSCHER;
binmode STDOUT, ':via(LAUTER_DEUTSCHER)'
print "Timmy pet the cute puppy.\n";
Running the above produces the following output:
DIETER HAUSTIER DER NETTE WELPE!
=head1 DESCRIPTION
This module provides a Perl IO layer that translates output into German using
L<Lingua::Translate>. In addition to translation, the output is converted to upper
case and the name "Timmy" is changed to "Dieter."
=head1 AUTHOR
Ian Langworth, C<< <ian@cpan.org> >>
( run in 3.746 seconds using v1.01-cache-2.11-cpan-d80b1682f3f )