Debian Codegraph @

upstream/opensuse-tumbleweed/man3/Encode::Alias.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Encode::Alias 3pm"
61 .TH Encode::Alias 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Encode::Alias \- alias definitions to encodings
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 5
71 \& use Encode;
72 \& use Encode::Alias;
73 \& define_alias( "newName" => ENCODING);
74 \& define_alias( qr/.../ => ENCODING);
75 \& define_alias( sub { return ENCODING if ...; } );
76 .Ve
77 .SH DESCRIPTION
78 .IX Header "DESCRIPTION"
79 Allows newName to be used as an alias for ENCODING. ENCODING may be
80 either the name of an encoding or an encoding object (as described
81 in Encode).
82 .PP
83 Currently the first argument to \fBdefine_alias()\fR can be specified in the
84 following ways:
85 .IP "As a simple string." 4
86 .IX Item "As a simple string."
87 .PD 0
88 .IP "As a qr// compiled regular expression, e.g.:" 4
89 .IX Item "As a qr// compiled regular expression, e.g.:"
90 .PD
91 .Vb 1
92 \& define_alias( qr/^iso8859\-(\ed+)$/i => \*(Aq"iso\-8859\-$1"\*(Aq );
93 .Ve
94 .Sp
95 In this case, if \fIENCODING\fR is not a reference, it is \f(CW\*(C`eval\*(C'\fR\-ed
96 in order to allow \f(CW$1\fR etc. to be substituted. The example is one
97 way to alias names as used in X11 fonts to the MIME names for the
98 iso\-8859\-* family. Note the double quotes inside the single quotes.
99 .Sp
100 (or, you don\*(Aqt have to do this yourself because this example is predefined)
101 .Sp
102 If you are using a regex here, you have to use the quotes as shown or
103 it won\*(Aqt work. Also note that regex handling is tricky even for the
104 experienced. Use this feature with caution.
105 .IP "As a code reference, e.g.:" 4
106 .IX Item "As a code reference, e.g.:"
107 .Vb 1
108 \& define_alias( sub {shift =~ /^iso8859\-(\ed+)$/i ? "iso\-8859\-$1" : undef } );
109 .Ve
110 .Sp
111 The same effect as the example above in a different way. The coderef
112 takes the alias name as an argument and returns a canonical name on
113 success or undef if not. Note the second argument is ignored if provided.
114 Use this with even more caution than the regex version.
115 .PP
116 \fIChanges in code reference aliasing\fR
117 .IX Subsection "Changes in code reference aliasing"
118 .PP
119 As of Encode 1.87, the older form
120 .PP
121 .Vb 1
122 \& define_alias( sub { return /^iso8859\-(\ed+)$/i ? "iso\-8859\-$1" : undef } );
123 .Ve
124 .PP
125 no longer works.
126 .PP
127 Encode up to 1.86 internally used "local \f(CW$_\fR" to implement this older
128 form. But consider the code below;
129 .PP
130 .Vb 6
131 \& use Encode;
132 \& $_ = "eeeee" ;
133 \& while (/(e)/g) {
134 \& my $utf = decode(\*(Aqaliased\-encoding\-name\*(Aq, $1);
135 \& print "position:",pos,"\en";
136 \& }
137 .Ve
138 .PP
139 Prior to Encode 1.86 this fails because of "local \f(CW$_\fR".
140 .SS "Alias overloading"
141 .IX Subsection "Alias overloading"
142 You can override predefined aliases by simply applying \fBdefine_alias()\fR.
143 The new alias is always evaluated first, and when necessary,
144 \&\fBdefine_alias()\fR flushes the internal cache to make the new definition
145 available.
146 .PP
147 .Vb 2
148 \& # redirect SHIFT_JIS to MS/IBM Code Page 932, which is a
149 \& # superset of SHIFT_JIS
150 \&
151 \& define_alias( qr/shift.*jis$/i => \*(Aq"cp932"\*(Aq );
152 \& define_alias( qr/sjis$/i => \*(Aq"cp932"\*(Aq );
153 .Ve
154 .PP
155 If you want to zap all predefined aliases, you can use
156 .PP
157 .Vb 1
158 \& Encode::Alias\->undef_aliases;
159 .Ve
160 .PP
161 to do so. And
162 .PP
163 .Vb 1
164 \& Encode::Alias\->init_aliases;
165 .Ve
166 .PP
167 gets the factory settings back.
168 .PP
169 Note that \fBdefine_alias()\fR will not be able to override the canonical name
170 of encodings. Encodings are first looked up by canonical name before
171 potential aliases are tried.
172 .SH "SEE ALSO"
173 .IX Header "SEE ALSO"
174 Encode, Encode::Supported