package Encode::ROT13;
use strict;
use warnings;
use parent qw( Encode::Encoding );
__PACKAGE__->Define( 'rot13' );
sub encode($$;$){
my( $obj, $str, $chk ) = @_;
$str =~ tr/A-Za-z/N-ZA-Mn-za-m/;
$_[1] = '' if $chk; # $_[1] is aliased through the call. Inplace edit.
return $str;
}
no warnings 'once';
*Encode::ROT13::decode = \&encode; # Because rot13( rot13() ) is a round-trip.
1;
package main;
use strict;
use warnings;
####
use Data::Dump ;
dd\%Encode::Encoding;
for my $enc ( qw/
:rot13
:ROT13
:encoding(rot13)
:encoding(ROT13)
:UTF-7
:encoding(UTF-7)
:via(ROT13)
:via(Encode::ROT13)
/ )
{
fudge( $enc );
}
dd\%Encode::Encoding;
our $tell;
sub fudge {
my( $layer ) = @_;
$tell ||= tell DATA;
seek DATA, $tell, 0;
print "## binmode DATA, $layer \n";
binmode DATA, $layer;
dd [];
}
__DATA__
Apple
cat
dog
strawberry
watermelon
####
$ perl fudge
{
"ascii" => bless(do{\(my $o = 1783919988)}, "Encode::XS"),
"ascii-ctrl" => bless(do{\(my $o = 1783919960)}, "Encode::XS"),
"iso-8859-1" => bless(do{\(my $o = 1783919932)}, "Encode::XS"),
"null" => bless(do{\(my $o = 1783919904)}, "Encode::XS"),
"rot13" => bless({ Name => "rot13" }, "Encode::ROT13"),
"Unicode" => bless({ Name => "Internal" }, "Encode::Internal"),
"utf-8-strict" => bless({ Name => "utf-8-strict", strict_utf8 => 1 }, "Encode::utf8"),
"utf8" => bless({ Name => "utf8" }, "Encode::utf8"),
}
## binmode DATA, :rot13
Unknown PerlIO layer "rot13" at fudge line 51.
["Apple\n", "cat\n", "dog\n", "strawberry\n", "watermelon\n"]
## binmode DATA, :ROT13
Unknown PerlIO layer "ROT13" at fudge line 51, line 5.
["Apple\n", "cat\n", "dog\n", "strawberry\n", "watermelon\n"]
## binmode DATA, :encoding(rot13)
["Nccyr\n", "png\n", "qbt\n", "fgenjoreel\n", "jngrezryba\n"]
## binmode DATA, :encoding(ROT13)
["Apple\n", "cat\n", "dog\n", "strawberry\n", "watermelon\n"]
## binmode DATA, :UTF-7
Unknown PerlIO layer "UTF" at fudge line 51, line 20.
["Apple\n", "cat\n", "dog\n", "strawberry\n", "watermelon\n"]
## binmode DATA, :encoding(UTF-7)
["Apple\n", "cat\n", "dog\n", "strawberry\n", "watermelon\n"]
## binmode DATA, :via(ROT13)
Cannot find package 'ROT13' at fudge line 51, line 30.
["Apple\n", "cat\n", "dog\n", "strawberry\n", "watermelon\n"]
## binmode DATA, :via(Encode::ROT13)
["Apple\n", "cat\n", "dog\n", "strawberry\n", "watermelon\n"]
{
"ascii" => bless(do{\(my $o = 1783919988)}, "Encode::XS"),
"ascii-ctrl" => bless(do{\(my $o = 1783919960)}, "Encode::XS"),
"iso-8859-1" => bless(do{\(my $o = 1783919932)}, "Encode::XS"),
"null" => bless(do{\(my $o = 1783919904)}, "Encode::XS"),
"rot13" => bless({ Name => "rot13" }, "Encode::ROT13"),
"UCS-2BE" => bless({ endian => "n", Name => "UCS-2BE", size => 2, ucs2 => 1 }, "Encode::Unicode"),
"UCS-2LE" => bless({ endian => "v", Name => "UCS-2LE", size => 2, ucs2 => 1 }, "Encode::Unicode"),
"Unicode" => bless({ Name => "Internal" }, "Encode::Internal"),
"UTF-16" => bless({ endian => "", Name => "UTF-16", size => 2, ucs2 => "" }, "Encode::Unicode"),
"UTF-16BE" => bless({ endian => "n", Name => "UTF-16BE", size => 2, ucs2 => "" }, "Encode::Unicode"),
"UTF-16LE" => bless({ endian => "v", Name => "UTF-16LE", size => 2, ucs2 => "" }, "Encode::Unicode"),
"UTF-32" => bless({ endian => "", Name => "UTF-32", size => 4, ucs2 => "" }, "Encode::Unicode"),
"UTF-32BE" => bless({ endian => "N", Name => "UTF-32BE", size => 4, ucs2 => "" }, "Encode::Unicode"),
"UTF-32LE" => bless({ endian => "V", Name => "UTF-32LE", size => 4, ucs2 => "" }, "Encode::Unicode"),
"UTF-7" => bless({ Name => "UTF-7" }, "Encode::Unicode::UTF7"),
"utf-8-strict" => bless({ Name => "utf-8-strict", strict_utf8 => 1 }, "Encode::utf8"),
"utf8" => bless({ Name => "utf8" }, "Encode::utf8"),
}