View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Daisuke Maki > Data-Decode-0.00006 > Data::Decode



Annotate this POD (1)


New  1
Open  1
View/Report Bugs
Module Version: 0.00006   Source   Latest Release: Data-Decode-0.00007_01


Data::Decode - Pluggable Data Decoder


  use Data::Decode;

  my $decoder = Data::Decode->new(
    strategy => Data::Decode::Encode::Guess->new()
  my $decoded = $decoder->decode($data);


WARNING: Alpha grade software.

Data::Decode implements a pluggable "decoder". The main aim is to provide a uniform interface to decode a given data while allowing the actual algorithm being used to be changed depending on your needs..

For now this is aimed at decoding miscellaneous text to perl's internal unicode encoding.


Japanese, which is the language that I mainly deal with, has an annoying property, in that it can come in at least 4 different flavors (utf-8, shift-jis, euc-jp and iso-2022-jp). Even worse, vendors may have more vendor-specific symbols, such as the pictograms in mobile phones.

Ways to decode these strings into unicode varies between each environment and application.

Many modules require that the strings be normalized to unicode, but they all handle this normalization process differently, which is, well, not exactly an optimal solution.

Data::Decode provides a uniform interface to this problem, and a few common ways decoding is handled. The actual decoding strategies are separated out from the surface interface, so other users who find a particular strategy to decode strings can then upload their way to CPAN, and everyone can benefit from it.


By default, this module comes with a few default strategies. These are just basic strategies -- they probably work in most cases, but you are strongly encouraged not to overtrust these algorithms.


Data::Decode comes with a simple chaining functionality. You can take as many decoders as you want, and you can stack them on top of each other.



Instantiates a new Data::Decode object.


Required. Takes in the object that encapsulates the actual decoding logic. The object must have a method named "decode", which takes in a reference to the Data::Decode object and a string to be decoded. An optional third parameter may be provided to specify any hints that could be used to figure out what to do.

  sub decode {
    my ($self, $decoder, $string, $hints) = @_;
    # $decoder = Data::Decode object
    # $string  = a scalar to be decoded
    # $hints   = a hashref of hints


Decodes a string. Takes in a string, and a hashref of hints to be used for decoding. The meaning or the usage of the hints may differ between the actual underlying decoders.


Get/set the underlying decoder object.


Copyright (c) 2007 Daisuke Maki <>


This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


syntax highlighting: