1Encode::Alias(3pm)     Perl Programmers Reference Guide     Encode::Alias(3pm)
2
3
4

NAME

6       Encode::Alias - alias definitions to encodings
7

SYNOPSIS

9         use Encode;
10         use Encode::Alias;
11         define_alias( newName => ENCODING);
12

DESCRIPTION

14       Allows newName to be used as an alias for ENCODING. ENCODING may be
15       either the name of an encoding or an encoding object (as described in
16       Encode).
17
18       Currently newName can be specified in the following ways:
19
20       As a simple string.
21       As a qr// compiled regular expression, e.g.:
22             define_alias( qr/^iso8859-(\d+)$/i => '"iso-8859-$1"' );
23
24           In this case, if ENCODING is not a reference, it is "eval"-ed in
25           order to allow $1 etc. to be substituted.  The example is one way
26           to alias names as used in X11 fonts to the MIME names for the
27           iso-8859-* family.  Note the double quotes inside the single
28           quotes.
29
30           (or, you don't have to do this yourself because this example is
31           predefined)
32
33           If you are using a regex here, you have to use the quotes as shown
34           or it won't work.  Also note that regex handling is tricky even for
35           the experienced.  Use this feature with caution.
36
37       As a code reference, e.g.:
38             define_alias( sub {shift =~ /^iso8859-(\d+)$/i ? "iso-8859-$1" : undef } );
39
40           The same effect as the example above in a different way.  The
41           coderef takes the alias name as an argument and returns a canonical
42           name on success or undef if not.  Note the second argument is not
43           required.  Use this with even more caution than the regex version.
44
45       Changes in code reference aliasing
46
47       As of Encode 1.87, the older form
48
49         define_alias( sub { return  /^iso8859-(\d+)$/i ? "iso-8859-$1" : undef } );
50
51       no longer works.
52
53       Encode up to 1.86 internally used "local $_" to implement ths older
54       form.  But consider the code below;
55
56         use Encode;
57         $_ = "eeeee" ;
58         while (/(e)/g) {
59           my $utf = decode('aliased-encoding-name', $1);
60           print "position:",pos,"\n";
61         }
62
63       Prior to Encode 1.86 this fails because of "local $_".
64
65       Alias overloading
66
67       You can override predefined aliases by simply applying define_alias().
68       The new alias is always evaluated first, and when necessary,
69       define_alias() flushes the internal cache to make the new definition
70       available.
71
72         # redirect SHIFT_JIS to MS/IBM Code Page 932, which is a
73         # superset of SHIFT_JIS
74
75         define_alias( qr/shift.*jis$/i  => '"cp932"' );
76         define_alias( qr/sjis$/i        => '"cp932"' );
77
78       If you want to zap all predefined aliases, you can use
79
80         Encode::Alias->undef_aliases;
81
82       to do so.  And
83
84         Encode::Alias->init_aliases;
85
86       gets the factory settings back.
87

SEE ALSO

89       Encode, Encode::Supported
90
91
92
93perl v5.8.8                       2001-09-21                Encode::Alias(3pm)
Impressum