perl-unicode

Re: Encode::compat (was Re: Encode functionality for Perl 5.6.1)

2002-09-23 03:30:05
Dear Autrijus,

On Sun, 22 Sep 2002, 11:06 GMT+08 Autrijus Tang wrote:

Incidentally I have just finished a skeleton of Encode::compat, named
after Apache::compat (lower case) since it's a 'pragma' for Encode
usage, instead of a subcomponent of Encode.

It is available on CPAN, or at:

    http://www.autrijus.org/Encode-compat-0.01.tar.gz

All it does is translate whatever call it receives into Text::Iconv, or
(in the future) Unicode::MapUTF8 to perform the actual work.

The is_utf8(), _utf8_on() and _utf8_off() calls are performed by the
method native to the perl version -- 5.6.1 would use pack/unpack, 5.6.0
uses tr//CU, etc.

The usage is:

    use Encode::compat; # a no-op for Perl v5.7.1+ use Encode qw(...);
    # all constants and imports works transparently

    # use Encode functions as normal

For now it only support perl v5.6.1, and merely provides the three
utility function above (encode(), decode() and from_to()), with a very
kludgy FB_HTMLCREF fallback against 'latin-1' in from_to.

Theoretically, it could be backported to 5.005 and earlier, with none of
the unicode-related semantics available, and serves only as a
abstraction layer above Text::Iconv, Unicode::MapUTF8 and possibly other
transcoding modules.

My own aim was to deploy applications that can work across Perl versions
with the same interface; what do you, and other people on -unicode, feel
about such an attempt?

Thanks,
/Autrijus/

this is a very cool way to use Encode with 5.6.1! Just adding 3 files
and using

use Encode::compat;

instead of

use Encode;

is absolutely great, IMO. The first thing I found with your version
0.01 is that, if used with 5.8.0, it does not use Encode directly. I
think, the

if ($] >= 5.007001 or $INC{'Encode.pm'}) {
    # nothing happens -- Encode.pm already available.
    $INC{'Encode.pm'} = __FILE__;
    require Encode::compat::common;
    require Encode::compat::5006001;
}

section of your 'compat.pm' file has to be changed to

if ($] >= 5.007001 or $INC{'Encode.pm'}) {
    # nothing happens -- Encode.pm already available.
    use Encode;
}

for proper use with 5.8.0+. To test it with 5.6.1, I first had to
install the Text::Iconv module. I will now play with it. Thanks a lot
for your efforts in providing such a nice enhancement.

--
rob.