Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / Encode / Alias.html
blob00bb42a4cd21d6e0f6f54c7b5389171390ceb4f7
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>Encode::Alias - alias definitions to encodings</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;Encode::Alias - alias definitions to encodings</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <ul>
27 <ul>
29 <li><a href="#changes_in_code_reference_aliasing">Changes in code reference aliasing</a></li>
30 </ul>
32 <li><a href="#alias_overloading">Alias overloading</a></li>
33 </ul>
35 <li><a href="#see_also">SEE ALSO</a></li>
36 </ul>
37 <!-- INDEX END -->
39 <hr />
40 <p>
41 </p>
42 <h1><a name="name">NAME</a></h1>
43 <p>Encode::Alias - alias definitions to encodings</p>
44 <p>
45 </p>
46 <hr />
47 <h1><a name="synopsis">SYNOPSIS</a></h1>
48 <pre>
49 use Encode;
50 use Encode::Alias;
51 define_alias( newName =&gt; ENCODING);</pre>
52 <p>
53 </p>
54 <hr />
55 <h1><a name="description">DESCRIPTION</a></h1>
56 <p>Allows newName to be used as an alias for ENCODING. ENCODING may be
57 either the name of an encoding or an encoding object (as described
58 in <a href="file://C|\msysgit\mingw\html/lib/Encode.html">the Encode manpage</a>).</p>
59 <p>Currently <em>newName</em> can be specified in the following ways:</p>
60 <dl>
61 <dt><strong><a name="item_as_a_simple_string_2e">As a simple string.</a></strong>
63 <dt><strong><a name="item_as_a_qr_2f_2f_compiled_regular_expression_2c_e_2eg">As a qr// compiled regular expression, e.g.:</a></strong>
65 <dd>
66 <pre>
67 define_alias( qr/^iso8859-(\d+)$/i =&gt; '&quot;iso-8859-$1&quot;' );</pre>
68 </dd>
69 <dd>
70 <p>In this case, if <em>ENCODING</em> is not a reference, it is <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>-ed
71 in order to allow <code>$1</code> etc. to be substituted. The example is one
72 way to alias names as used in X11 fonts to the MIME names for the
73 iso-8859-* family. Note the double quotes inside the single quotes.</p>
74 </dd>
75 <dd>
76 <p>(or, you don't have to do this yourself because this example is predefined)</p>
77 </dd>
78 <dd>
79 <p>If you are using a regex here, you have to use the quotes as shown or
80 it won't work. Also note that regex handling is tricky even for the
81 experienced. Use this feature with caution.</p>
82 </dd>
83 <dt><strong><a name="item_as_a_code_reference_2c_e_2eg_2e_3a">As a code reference, e.g.:</a></strong>
85 <dd>
86 <pre>
87 define_alias( sub {shift =~ /^iso8859-(\d+)$/i ? &quot;iso-8859-$1&quot; : undef } );</pre>
88 </dd>
89 <dd>
90 <p>The same effect as the example above in a different way. The coderef
91 takes the alias name as an argument and returns a canonical name on
92 success or undef if not. Note the second argument is not required.
93 Use this with even more caution than the regex version.</p>
94 </dd>
95 </dl>
96 <p>
97 </p>
98 <h3><a name="changes_in_code_reference_aliasing">Changes in code reference aliasing</a></h3>
99 <p>As of Encode 1.87, the older form</p>
100 <pre>
101 define_alias( sub { return /^iso8859-(\d+)$/i ? &quot;iso-8859-$1&quot; : undef } );</pre>
102 <p>no longer works.</p>
103 <p>Encode up to 1.86 internally used ``local $_'' to implement ths older
104 form. But consider the code below;</p>
105 <pre>
106 use Encode;
107 $_ = &quot;eeeee&quot; ;
108 while (/(e)/g) {
109 my $utf = decode('aliased-encoding-name', $1);
110 print &quot;position:&quot;,pos,&quot;\n&quot;;
111 }</pre>
112 <p>Prior to Encode 1.86 this fails because of ``local $_''.</p>
114 </p>
115 <h2><a name="alias_overloading">Alias overloading</a></h2>
116 <p>You can override predefined aliases by simply applying define_alias().
117 The new alias is always evaluated first, and when necessary,
118 <code>define_alias()</code> flushes the internal cache to make the new definition
119 available.</p>
120 <pre>
121 # redirect SHIFT_JIS to MS/IBM Code Page 932, which is a
122 # superset of SHIFT_JIS</pre>
123 <pre>
124 define_alias( qr/shift.*jis$/i =&gt; '&quot;cp932&quot;' );
125 define_alias( qr/sjis$/i =&gt; '&quot;cp932&quot;' );</pre>
126 <p>If you want to zap all predefined aliases, you can use</p>
127 <pre>
128 Encode::Alias-&gt;undef_aliases;</pre>
129 <p>to do so. And</p>
130 <pre>
131 Encode::Alias-&gt;init_aliases;</pre>
132 <p>gets the factory settings back.</p>
134 </p>
135 <hr />
136 <h1><a name="see_also">SEE ALSO</a></h1>
137 <p><a href="file://C|\msysgit\mingw\html/lib/Encode.html">the Encode manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/Encode/Supported.html">the Encode::Supported manpage</a></p>
138 <table border="0" width="100%" cellspacing="0" cellpadding="3">
139 <tr><td class="block" style="background-color: #cccccc" valign="middle">
140 <big><strong><span class="block">&nbsp;Encode::Alias - alias definitions to encodings</span></strong></big>
141 </td></tr>
142 </table>
144 </body>
146 </html>