| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Encode::Alias 3perl" |
| 58 |
.TH Encode::Alias 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Encode::Alias \- alias definitions to encodings |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 5 |
| 68 |
\& use Encode; |
| 69 |
\& use Encode::Alias; |
| 70 |
\& define_alias( "newName" => ENCODING); |
| 71 |
\& define_alias( qr/.../ => ENCODING); |
| 72 |
\& define_alias( sub { return ENCODING if ...; } ); |
| 73 |
.Ve |
| 74 |
.SH DESCRIPTION |
| 75 |
.IX Header "DESCRIPTION" |
| 76 |
Allows newName to be used as an alias for ENCODING. ENCODING may be |
| 77 |
either the name of an encoding or an encoding object (as described |
| 78 |
in Encode). |
| 79 |
.PP |
| 80 |
Currently the first argument to \fBdefine_alias()\fR can be specified in the |
| 81 |
following ways: |
| 82 |
.IP "As a simple string." 4 |
| 83 |
.IX Item "As a simple string." |
| 84 |
.PD 0 |
| 85 |
.IP "As a qr// compiled regular expression, e.g.:" 4 |
| 86 |
.IX Item "As a qr// compiled regular expression, e.g.:" |
| 87 |
.PD |
| 88 |
.Vb 1 |
| 89 |
\& define_alias( qr/^iso8859\-(\ed+)$/i => \*(Aq"iso\-8859\-$1"\*(Aq ); |
| 90 |
.Ve |
| 91 |
.Sp |
| 92 |
In this case, if \fIENCODING\fR is not a reference, it is \f(CW\*(C`eval\*(C'\fR\-ed |
| 93 |
in order to allow \f(CW$1\fR etc. to be substituted. The example is one |
| 94 |
way to alias names as used in X11 fonts to the MIME names for the |
| 95 |
iso\-8859\-* family. Note the double quotes inside the single quotes. |
| 96 |
.Sp |
| 97 |
(or, you don't have to do this yourself because this example is predefined) |
| 98 |
.Sp |
| 99 |
If you are using a regex here, you have to use the quotes as shown or |
| 100 |
it won't work. Also note that regex handling is tricky even for the |
| 101 |
experienced. Use this feature with caution. |
| 102 |
.IP "As a code reference, e.g.:" 4 |
| 103 |
.IX Item "As a code reference, e.g.:" |
| 104 |
.Vb 1 |
| 105 |
\& define_alias( sub {shift =~ /^iso8859\-(\ed+)$/i ? "iso\-8859\-$1" : undef } ); |
| 106 |
.Ve |
| 107 |
.Sp |
| 108 |
The same effect as the example above in a different way. The coderef |
| 109 |
takes the alias name as an argument and returns a canonical name on |
| 110 |
success or undef if not. Note the second argument is ignored if provided. |
| 111 |
Use this with even more caution than the regex version. |
| 112 |
.PP |
| 113 |
\fIChanges in code reference aliasing\fR |
| 114 |
.IX Subsection "Changes in code reference aliasing" |
| 115 |
.PP |
| 116 |
As of Encode 1.87, the older form |
| 117 |
.PP |
| 118 |
.Vb 1 |
| 119 |
\& define_alias( sub { return /^iso8859\-(\ed+)$/i ? "iso\-8859\-$1" : undef } ); |
| 120 |
.Ve |
| 121 |
.PP |
| 122 |
no longer works. |
| 123 |
.PP |
| 124 |
Encode up to 1.86 internally used "local \f(CW$_\fR" to implement this older |
| 125 |
form. But consider the code below; |
| 126 |
.PP |
| 127 |
.Vb 6 |
| 128 |
\& use Encode; |
| 129 |
\& $_ = "eeeee" ; |
| 130 |
\& while (/(e)/g) { |
| 131 |
\& my $utf = decode(\*(Aqaliased\-encoding\-name\*(Aq, $1); |
| 132 |
\& print "position:",pos,"\en"; |
| 133 |
\& } |
| 134 |
.Ve |
| 135 |
.PP |
| 136 |
Prior to Encode 1.86 this fails because of "local \f(CW$_\fR". |
| 137 |
.SS "Alias overloading" |
| 138 |
.IX Subsection "Alias overloading" |
| 139 |
You can override predefined aliases by simply applying \fBdefine_alias()\fR. |
| 140 |
The new alias is always evaluated first, and when necessary, |
| 141 |
\&\fBdefine_alias()\fR flushes the internal cache to make the new definition |
| 142 |
available. |
| 143 |
.PP |
| 144 |
.Vb 2 |
| 145 |
\& # redirect SHIFT_JIS to MS/IBM Code Page 932, which is a |
| 146 |
\& # superset of SHIFT_JIS |
| 147 |
\& |
| 148 |
\& define_alias( qr/shift.*jis$/i => \*(Aq"cp932"\*(Aq ); |
| 149 |
\& define_alias( qr/sjis$/i => \*(Aq"cp932"\*(Aq ); |
| 150 |
.Ve |
| 151 |
.PP |
| 152 |
If you want to zap all predefined aliases, you can use |
| 153 |
.PP |
| 154 |
.Vb 1 |
| 155 |
\& Encode::Alias\->undef_aliases; |
| 156 |
.Ve |
| 157 |
.PP |
| 158 |
to do so. And |
| 159 |
.PP |
| 160 |
.Vb 1 |
| 161 |
\& Encode::Alias\->init_aliases; |
| 162 |
.Ve |
| 163 |
.PP |
| 164 |
gets the factory settings back. |
| 165 |
.PP |
| 166 |
Note that \fBdefine_alias()\fR will not be able to override the canonical name |
| 167 |
of encodings. Encodings are first looked up by canonical name before |
| 168 |
potential aliases are tried. |
| 169 |
.SH "SEE ALSO" |
| 170 |
.IX Header "SEE ALSO" |
| 171 |
Encode, Encode::Supported |