Data::Visitor::Encode - Encode/Decode Values In A Structure
use Data::Visitor::Encode; my $dev = Data::Visitor::Encode->new(); my %hash = (...); # assume data is in Perl native Unicode $dev->encode('euc-jp', \%hash); # now strings are in euc-jp $dev->decode('euc-jp', \%hash); # now strings are back in unicode $dev->utf8_on(\%hash); $dev->utf8_off(\%hash);
Data::Visitor::Encode visits each node of a structure, and returns a new structure with each node's encoding (or similar action). If you ever wished to do a bulk encode/decode of the contents of a structure, then this module may help you.
$dev->utf8_on(\%hash); $dev->utf8_on(\@list); $dev->utf8_on(\$scalar); $dev->utf8_on($scalar); $dev->utf8_on($object);
Returns a structure containing nodes with utf8 flag on
$dev->utf8_off(\%hash); $dev->utf8_off(\@list); $dev->utf8_off(\$scalar); $dev->utf8_off($scalar); $dev->utf8_off($object);
Returns a structure containing nodes with utf8 flag off
$dev->encode($encoding, \%hash [, CHECK]); $dev->encode($encoding, \@list [, CHECK]); $dev->encode($encoding, \$scalar [, CHECK]); $dev->encode($encoding, $scalar [, CHECK]); $dev->encode($encoding, $object [, CHECK]);
Returns a structure containing nodes which are encoded in the specified encoding.
$dev->decode($encoding, \%hash); $dev->decode($encoding, \@list); $dev->decode($encoding, \$scalar); $dev->decode($encoding, $scalar); $dev->decode($encoding, $object);
Returns a structure containing nodes which are decoded from the specified encoding.
$dev->decode_utf8(\%hash); $dev->decode_utf8(\@list); $dev->decode_utf8(\$scalar); $dev->decode_utf8($scalar); $dev->decode_utf8($object);
Returns a structure containing nodes which have been processed through decode_utf8.
$dev->encode_utf8(\%hash); $dev->encode_utf8(\@list); $dev->encode_utf8(\$scalar); $dev->encode_utf8($scalar); $dev->encode_utf8($object);
Returns a structure containing nodes which have been processed through encode_utf8.
$dev->h2z($encoding, \%hash); $dev->h2z($encoding, \@list); $dev->h2z($encoding, \$scalar); $dev->h2z($encoding, $scalar); $dev->h2z($encoding, $object);
h2z and z2h are Japanese-only methods (hey, I'm a little biased like that). They perform the task of mapping half-width katakana to full-width katakana and vice-versa.
These methods use Encode::JP::H2Z, which requires us to go from the original encoding to euc-jp and then back. There are other modules that are built to handle exactly this problem, which may come out to be faster than using Encode.pm's somewhat hidden Encode::JP::H2Z, but I really don't care for adding another dependency to this module other than Encode.pm, so here it is.
If you're significantly worried about performance, I'll gladly accept patches as long as there are no prerequisite modules or the prerequisite is optional.
Encode.pm contains a Pure Perl mapping
These methods are private. Only use if it you are subclassing this class.
Daisuke Maki <daisuke@endeworks.jp>
Data::Visitor, Encode
To install Data::Visitor::Encode, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Visitor::Encode
CPAN shell
perl -MCPAN -e shell install Data::Visitor::Encode
For more information on module installation, please visit the detailed CPAN module installation guide.