1Encode::Alias(3)      User Contributed Perl Documentation     Encode::Alias(3)
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         define_alias( qr/.../ => ENCODING);
13         define_alias( sub { return ENCODING if ...; } );
14

DESCRIPTION

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

SEE ALSO

96       Encode, Encode::Supported
97
98
99
100perl v5.36.0                      2022-08-15                  Encode::Alias(3)
Impressum