The POD for Encode::Encoding offers this snippet as an example of creating a custom encoding:
use base qw(Encode::Encoding);
my ($obj, $str, $chk) = @_;
$str =~ tr/A-Za-z/N-ZA-Mn-za-m/;
$_ = '' if $chk; # this is what in-place edit means
# Jr pna or ynml yvxr guvf;
*decode = \&encode;
Encode provides the following explanation for defining encodings:
To define a new encoding, use:
use Encode qw(define_encoding);
define_encoding($object, CANONICAL_NAME [, alias...]);
CANONICAL_NAME will be associated with $object. The object should provide the interface described in Encode::Encoding. If more than two arguments are provided, additional arguments are considered aliases for $object.
See Encode::Encoding for details.
I seem to be failing to connect the dots. How would one instantiate $object, which in the case of the example code above, I think, should be an instance of the Encode::Rot13 class? What needs to happen before I can "binmode $fh, ':rot13';"?