davido has asked for the wisdom of the Perl Monks concerning the following question:
The POD for Encode::Encoding offers this snippet as an example of creating a custom encoding:
package Encode::ROT13; use strict; use base 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; # this is what in-place edit means return $str; } # Jr pna or ynml yvxr guvf; *decode = \&encode; 1;
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';"?
Dave
|
---|