enc2xs(1)
NAME
enc2xs — Perl Encode Module Generator
SYNOPSIS
enc2xs -[options] enc2xs -M ModName mapfiles... enc2xs -C
DESCRIPTION
enc2xs builds a Perl extension for use by Encode from either Unicode Character Mapping files (.ucm) or Tcl Encoding Files (.enc). Besides being used internally during the build process of the Encode module, you can use enc2xs to add your own encoding to perl. No knowledge of XS is necessary.
Quick Guide
If you want to know as little about Perl as possible but need to add a new encoding, just read this chapter and forget the rest.
- 0.
- Have a .ucm file ready. You can get it from somewhere or you can write your own from scratch or you can grab one from the Encode distribution and customize it. For the UCM format, see the next Chapter. In the example below, I’ll call my theoretical encoding myascii, defined in my.ucm. "$" is a shell prompt.
- 1.
- Issue a command as follows;
- 1.1.
- If you want *.ucm installed together with the modules, do as follows;
- 2.
- Edit the files generated. You don’t have to if you have no time AND no intention to give it to someone else. But it is a good idea to edit the pod and to add more tests.
- 3.
- Now issue a command all Perl Mongers love:
- 4.
- Now all you have to do is make.
- 5.
- You can “make install” already but you should test first.
- 6.
- If you are content with the test result, just “make install”
- 7.
- If you want to add your encoding to Encode’s demand-loading list (so you don’t have to “use Encode::YourEncoding”), run
$ ls -F my.ucm
$ enc2xs -M My my.ucm generating Makefile.PL generating My.pm generating README generating Changes
Now take a look at your current directory. It should look like this.
$ ls -F Makefile.PL My.pm my.ucm t/
The following files were created.
Makefile.PL - MakeMaker script My.pm - Encode submodule t/My.t - test file
$ mkdir Encode $ mv *.ucm Encode $ enc2xs -M My Encode/*ucm
$ perl Makefile.PL Writing Makefile for Encode::My
$ make
cp My.pm blib/lib/Encode/My.pm
/usr/local/bin/perl /usr/local/bin/enc2xs -Q -O \
-o encode_t.c -f encode_t.fnm
Reading myascii (myascii)
Writing compiled form
128 bytes in string tables
384 bytes (75%) saved spotting duplicates
1 bytes (0.775%) saved using substrings
....
chmod 644 blib/arch/auto/Encode/My/My.bs
$
The time it takes varies depending on how fast your machine is and how large your encoding is. Unless you are working on something big like euc-tw, it won’t take too long.
$ make test
PERL_DL_NONLAZY = 1 / usr / local / bin / perl - Iblib / arch - Iblib / lib - e 'use Test::Harness qw(&runtests $verbose); \
$verbose=0; runtests @ARGV;' t/*.t
t/My....ok
All tests successful.
Files=1, Tests=2, 0 wallclock secs
( 0.09 cusr + 0.01 csys = 0.09 CPU)
enc2xs -C
to update Encode::ConfigLocal, a module that controls local settings. After that, “use Encode;” is enough to load your encodings on demand.
The Unicode Character Map
Encode uses the Unicode Character Map (UCM) format for source character mappings. This format is used by IBM‘s ICU package and was adopted by Nick Ing-Simmons for use with the Encode module. Since UCM is more flexible than Tcl’s Encoding Map and far more user-friendly, this is the recommended format for Encode now.
A UCM file looks like this.
# # Comments # <code_set_name> "US-ascii" # Required <code_set_alias> "ascii" # Optional <mb_cur_min> 1 # Required; usually 1 <mb_cur_max> 1 # Max. # of bytes/char <subchar> ? # Substitution char # CHARMAP <U0000>