Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "B::Deparse 3" | |
132 | .TH B::Deparse 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | B::Deparse \- Perl compiler backend to produce perl code | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | \&\fBperl\fR \fB\-MO=Deparse\fR[\fB,\-u\fR\fI\s-1PACKAGE\s0\fR][\fB,\-p\fR][\fB,\-q\fR][\fB,\-l\fR] | |
138 | [\fB,\-s\fR\fI\s-1LETTERS\s0\fR][\fB,\-x\fR\fI\s-1LEVEL\s0\fR] \fIprog.pl\fR | |
139 | .SH "DESCRIPTION" | |
140 | .IX Header "DESCRIPTION" | |
141 | B::Deparse is a backend module for the Perl compiler that generates | |
142 | perl source code, based on the internal compiled structure that perl | |
143 | itself creates after parsing a program. The output of B::Deparse won't | |
144 | be exactly the same as the original source, since perl doesn't keep | |
145 | track of comments or whitespace, and there isn't a one-to-one | |
146 | correspondence between perl's syntactical constructions and their | |
147 | compiled form, but it will often be close. When you use the \fB\-p\fR | |
148 | option, the output also includes parentheses even when they are not | |
149 | required by precedence, which can make it easy to see if perl is | |
150 | parsing your expressions the way you intended. | |
151 | .PP | |
152 | Please note that this module is mainly new and untested code and is | |
153 | still under development, so it may change in the future. | |
154 | .SH "OPTIONS" | |
155 | .IX Header "OPTIONS" | |
156 | As with all compiler backend options, these must follow directly after | |
157 | the '\-MO=Deparse', separated by a comma but not any white space. | |
158 | .IP "\fB\-l\fR" 4 | |
159 | .IX Item "-l" | |
160 | Add '#line' declarations to the output based on the line and file | |
161 | locations of the original code. | |
162 | .IP "\fB\-p\fR" 4 | |
163 | .IX Item "-p" | |
164 | Print extra parentheses. Without this option, B::Deparse includes | |
165 | parentheses in its output only when they are needed, based on the | |
166 | structure of your program. With \fB\-p\fR, it uses parentheses (almost) | |
167 | whenever they would be legal. This can be useful if you are used to | |
168 | \&\s-1LISP\s0, or if you want to see how perl parses your input. If you say | |
169 | .Sp | |
170 | .Vb 3 | |
171 | \& if ($var & 0x7f == 65) {print "Gimme an A!"} | |
172 | \& print ($which ? $a : $b), "\en"; | |
173 | \& $name = $ENV{USER} or "Bob"; | |
174 | .Ve | |
175 | .Sp | |
176 | \&\f(CW\*(C`B::Deparse,\-p\*(C'\fR will print | |
177 | .Sp | |
178 | .Vb 5 | |
179 | \& if (($var & 0)) { | |
180 | \& print('Gimme an A!') | |
181 | \& }; | |
182 | \& (print(($which ? $a : $b)), '???'); | |
183 | \& (($name = $ENV{'USER'}) or '???') | |
184 | .Ve | |
185 | .Sp | |
186 | which probably isn't what you intended (the \f(CW'???'\fR is a sign that | |
187 | perl optimized away a constant value). | |
188 | .IP "\fB\-P\fR" 4 | |
189 | .IX Item "-P" | |
190 | Disable prototype checking. With this option, all function calls are | |
191 | deparsed as if no prototype was defined for them. In other words, | |
192 | .Sp | |
193 | .Vb 1 | |
194 | \& perl -MO=Deparse,-P -e 'sub foo (\e@) { 1 } foo @x' | |
195 | .Ve | |
196 | .Sp | |
197 | will print | |
198 | .Sp | |
199 | .Vb 4 | |
200 | \& sub foo (\e@) { | |
201 | \& 1; | |
202 | \& } | |
203 | \& &foo(\e@x); | |
204 | .Ve | |
205 | .Sp | |
206 | making clear how the parameters are actually passed to \f(CW\*(C`foo\*(C'\fR. | |
207 | .IP "\fB\-q\fR" 4 | |
208 | .IX Item "-q" | |
209 | Expand double-quoted strings into the corresponding combinations of | |
210 | concatenation, uc, ucfirst, lc, lcfirst, quotemeta, and join. For | |
211 | instance, print | |
212 | .Sp | |
213 | .Vb 1 | |
214 | \& print "Hello, $world, @ladies, \eu$gentlemen\eE, \eu\eL$me!"; | |
215 | .Ve | |
216 | .Sp | |
217 | as | |
218 | .Sp | |
219 | .Vb 2 | |
220 | \& print 'Hello, ' . $world . ', ' . join($", @ladies) . ', ' | |
221 | \& . ucfirst($gentlemen) . ', ' . ucfirst(lc $me . '!'); | |
222 | .Ve | |
223 | .Sp | |
224 | Note that the expanded form represents the way perl handles such | |
225 | constructions internally \*(-- this option actually turns off the reverse | |
226 | translation that B::Deparse usually does. On the other hand, note that | |
227 | \&\f(CW\*(C`$x = "$y"\*(C'\fR is not the same as \f(CW\*(C`$x = $y\*(C'\fR: the former makes the value | |
228 | of \f(CW$y\fR into a string before doing the assignment. | |
229 | .IP "\fB\-f\fR\fI\s-1FILE\s0\fR" 4 | |
230 | .IX Item "-fFILE" | |
231 | Normally, B::Deparse deparses the main code of a program, and all the subs | |
232 | defined in the same file. To include subs defined in other files, pass the | |
233 | \&\fB\-f\fR option with the filename. You can pass the \fB\-f\fR option several times, to | |
234 | include more than one secondary file. (Most of the time you don't want to | |
235 | use it at all.) You can also use this option to include subs which are | |
236 | defined in the scope of a \fB#line\fR directive with two parameters. | |
237 | .IP "\fB\-s\fR\fI\s-1LETTERS\s0\fR" 4 | |
238 | .IX Item "-sLETTERS" | |
239 | Tweak the style of B::Deparse's output. The letters should follow | |
240 | directly after the 's', with no space or punctuation. The following | |
241 | options are available: | |
242 | .RS 4 | |
243 | .IP "\fBC\fR" 4 | |
244 | .IX Item "C" | |
245 | Cuddle \f(CW\*(C`elsif\*(C'\fR, \f(CW\*(C`else\*(C'\fR, and \f(CW\*(C`continue\*(C'\fR blocks. For example, print | |
246 | .Sp | |
247 | .Vb 5 | |
248 | \& if (...) { | |
249 | \& ... | |
250 | \& } else { | |
251 | \& ... | |
252 | \& } | |
253 | .Ve | |
254 | .Sp | |
255 | instead of | |
256 | .Sp | |
257 | .Vb 6 | |
258 | \& if (...) { | |
259 | \& ... | |
260 | \& } | |
261 | \& else { | |
262 | \& ... | |
263 | \& } | |
264 | .Ve | |
265 | .Sp | |
266 | The default is not to cuddle. | |
267 | .IP "\fBi\fR\fI\s-1NUMBER\s0\fR" 4 | |
268 | .IX Item "iNUMBER" | |
269 | Indent lines by multiples of \fI\s-1NUMBER\s0\fR columns. The default is 4 columns. | |
270 | .IP "\fBT\fR" 4 | |
271 | .IX Item "T" | |
272 | Use tabs for each 8 columns of indent. The default is to use only spaces. | |
273 | For instance, if the style options are \fB\-si4T\fR, a line that's indented | |
274 | 3 times will be preceded by one tab and four spaces; if the options were | |
275 | \&\fB\-si8T\fR, the same line would be preceded by three tabs. | |
276 | .IP "\fBv\fR\fI\s-1STRING\s0\fR\fB.\fR" 4 | |
277 | .IX Item "vSTRING." | |
278 | Print \fI\s-1STRING\s0\fR for the value of a constant that can't be determined | |
279 | because it was optimized away (mnemonic: this happens when a constant | |
280 | is used in \fBv\fRoid context). The end of the string is marked by a period. | |
281 | The string should be a valid perl expression, generally a constant. | |
282 | Note that unless it's a number, it probably needs to be quoted, and on | |
283 | a command line quotes need to be protected from the shell. Some | |
284 | conventional values include 0, 1, 42, '', 'foo', and | |
285 | \&'Useless use of constant omitted' (which may need to be | |
286 | \&\fB\-sv\*(L"'Useless use of constant omitted'.\*(R"\fR | |
287 | or something similar depending on your shell). The default is '???'. | |
288 | If you're using B::Deparse on a module or other file that's require'd, | |
289 | you shouldn't use a value that evaluates to false, since the customary | |
290 | true constant at the end of a module will be in void context when the | |
291 | file is compiled as a main program. | |
292 | .RE | |
293 | .RS 4 | |
294 | .RE | |
295 | .IP "\fB\-x\fR\fI\s-1LEVEL\s0\fR" 4 | |
296 | .IX Item "-xLEVEL" | |
297 | Expand conventional syntax constructions into equivalent ones that expose | |
298 | their internal operation. \fI\s-1LEVEL\s0\fR should be a digit, with higher values | |
299 | meaning more expansion. As with \fB\-q\fR, this actually involves turning off | |
300 | special cases in B::Deparse's normal operations. | |
301 | .Sp | |
302 | If \fI\s-1LEVEL\s0\fR is at least 3, for loops will be translated into equivalent | |
303 | while loops with continue blocks; for instance | |
304 | .Sp | |
305 | .Vb 3 | |
306 | \& for ($i = 0; $i < 10; ++$i) { | |
307 | \& print $i; | |
308 | \& } | |
309 | .Ve | |
310 | .Sp | |
311 | turns into | |
312 | .Sp | |
313 | .Vb 6 | |
314 | \& $i = 0; | |
315 | \& while ($i < 10) { | |
316 | \& print $i; | |
317 | \& } continue { | |
318 | \& ++$i | |
319 | \& } | |
320 | .Ve | |
321 | .Sp | |
322 | Note that in a few cases this translation can't be perfectly carried back | |
323 | into the source code \*(-- if the loop's initializer declares a my variable, | |
324 | for instance, it won't have the correct scope outside of the loop. | |
325 | .Sp | |
326 | If \fI\s-1LEVEL\s0\fR is at least 7, if statements will be translated into equivalent | |
327 | expressions using \f(CW\*(C`&&\*(C'\fR, \f(CW\*(C`?:\*(C'\fR and \f(CW\*(C`do {}\*(C'\fR; for instance | |
328 | .Sp | |
329 | .Vb 9 | |
330 | \& print 'hi' if $nice; | |
331 | \& if ($nice) { | |
332 | \& print 'hi'; | |
333 | \& } | |
334 | \& if ($nice) { | |
335 | \& print 'hi'; | |
336 | \& } else { | |
337 | \& print 'bye'; | |
338 | \& } | |
339 | .Ve | |
340 | .Sp | |
341 | turns into | |
342 | .Sp | |
343 | .Vb 3 | |
344 | \& $nice and print 'hi'; | |
345 | \& $nice and do { print 'hi' }; | |
346 | \& $nice ? do { print 'hi' } : do { print 'bye' }; | |
347 | .Ve | |
348 | .Sp | |
349 | Long sequences of elsifs will turn into nested ternary operators, which | |
350 | B::Deparse doesn't know how to indent nicely. | |
351 | .SH "USING B::Deparse AS A MODULE" | |
352 | .IX Header "USING B::Deparse AS A MODULE" | |
353 | .Sh "Synopsis" | |
354 | .IX Subsection "Synopsis" | |
355 | .Vb 4 | |
356 | \& use B::Deparse; | |
357 | \& $deparse = B::Deparse->new("-p", "-sC"); | |
358 | \& $body = $deparse->coderef2text(\e&func); | |
359 | \& eval "sub func $body"; # the inverse operation | |
360 | .Ve | |
361 | .Sh "Description" | |
362 | .IX Subsection "Description" | |
363 | B::Deparse can also be used on a sub-by-sub basis from other perl | |
364 | programs. | |
365 | .Sh "new" | |
366 | .IX Subsection "new" | |
367 | .Vb 1 | |
368 | \& $deparse = B::Deparse->new(OPTIONS) | |
369 | .Ve | |
370 | .PP | |
371 | Create an object to store the state of a deparsing operation and any | |
372 | options. The options are the same as those that can be given on the | |
373 | command line (see \*(L"\s-1OPTIONS\s0\*(R"); options that are separated by commas | |
374 | after \fB\-MO=Deparse\fR should be given as separate strings. Some | |
375 | options, like \fB\-u\fR, don't make sense for a single subroutine, so | |
376 | don't pass them. | |
377 | .Sh "ambient_pragmas" | |
378 | .IX Subsection "ambient_pragmas" | |
379 | .Vb 1 | |
380 | \& $deparse->ambient_pragmas(strict => 'all', '$[' => $[); | |
381 | .Ve | |
382 | .PP | |
383 | The compilation of a subroutine can be affected by a few compiler | |
384 | directives, \fBpragmas\fR. These are: | |
385 | .IP "\(bu" 4 | |
386 | use strict; | |
387 | .IP "\(bu" 4 | |
388 | use warnings; | |
389 | .IP "\(bu" 4 | |
390 | Assigning to the special variable $[ | |
391 | .IP "\(bu" 4 | |
392 | use integer; | |
393 | .IP "\(bu" 4 | |
394 | use bytes; | |
395 | .IP "\(bu" 4 | |
396 | use utf8; | |
397 | .IP "\(bu" 4 | |
398 | use re; | |
399 | .PP | |
400 | Ordinarily, if you use B::Deparse on a subroutine which has | |
401 | been compiled in the presence of one or more of these pragmas, | |
402 | the output will include statements to turn on the appropriate | |
403 | directives. So if you then compile the code returned by coderef2text, | |
404 | it will behave the same way as the subroutine which you deparsed. | |
405 | .PP | |
406 | However, you may know that you intend to use the results in a | |
407 | particular context, where some pragmas are already in scope. In | |
408 | this case, you use the \fBambient_pragmas\fR method to describe the | |
409 | assumptions you wish to make. | |
410 | .PP | |
411 | Not all of the options currently have any useful effect. See | |
412 | \&\*(L"\s-1BUGS\s0\*(R" for more details. | |
413 | .PP | |
414 | The parameters it accepts are: | |
415 | .IP "strict" 4 | |
416 | .IX Item "strict" | |
417 | Takes a string, possibly containing several values separated | |
418 | by whitespace. The special values \*(L"all\*(R" and \*(L"none\*(R" mean what you'd | |
419 | expect. | |
420 | .Sp | |
421 | .Vb 1 | |
422 | \& $deparse->ambient_pragmas(strict => 'subs refs'); | |
423 | .Ve | |
424 | .IP "$[" 4 | |
425 | Takes a number, the value of the array base $[. | |
426 | .IP "bytes" 4 | |
427 | .IX Item "bytes" | |
428 | .PD 0 | |
429 | .IP "utf8" 4 | |
430 | .IX Item "utf8" | |
431 | .IP "integer" 4 | |
432 | .IX Item "integer" | |
433 | .PD | |
434 | If the value is true, then the appropriate pragma is assumed to | |
435 | be in the ambient scope, otherwise not. | |
436 | .IP "re" 4 | |
437 | .IX Item "re" | |
438 | Takes a string, possibly containing a whitespace-separated list of | |
439 | values. The values \*(L"all\*(R" and \*(L"none\*(R" are special. It's also permissible | |
440 | to pass an array reference here. | |
441 | .Sp | |
442 | .Vb 1 | |
443 | \& $deparser->ambient_pragmas(re => 'eval'); | |
444 | .Ve | |
445 | .IP "warnings" 4 | |
446 | .IX Item "warnings" | |
447 | Takes a string, possibly containing a whitespace-separated list of | |
448 | values. The values \*(L"all\*(R" and \*(L"none\*(R" are special, again. It's also | |
449 | permissible to pass an array reference here. | |
450 | .Sp | |
451 | .Vb 1 | |
452 | \& $deparser->ambient_pragmas(warnings => [qw[void io]]); | |
453 | .Ve | |
454 | .Sp | |
455 | If one of the values is the string \*(L"\s-1FATAL\s0\*(R", then all the warnings | |
456 | in that list will be considered fatal, just as with the \fBwarnings\fR | |
457 | pragma itself. Should you need to specify that some warnings are | |
458 | fatal, and others are merely enabled, you can pass the \fBwarnings\fR | |
459 | parameter twice: | |
460 | .Sp | |
461 | .Vb 4 | |
462 | \& $deparser->ambient_pragmas( | |
463 | \& warnings => 'all', | |
464 | \& warnings => [FATAL => qw/void io/], | |
465 | \& ); | |
466 | .Ve | |
467 | .Sp | |
468 | See perllexwarn for more information about lexical warnings. | |
469 | .IP "hint_bits" 4 | |
470 | .IX Item "hint_bits" | |
471 | .PD 0 | |
472 | .IP "warning_bits" 4 | |
473 | .IX Item "warning_bits" | |
474 | .PD | |
475 | These two parameters are used to specify the ambient pragmas in | |
476 | the format used by the special variables $^H and ${^WARNING_BITS}. | |
477 | .Sp | |
478 | They exist principally so that you can write code like: | |
479 | .Sp | |
480 | .Vb 7 | |
481 | \& { my ($hint_bits, $warning_bits); | |
482 | \& BEGIN {($hint_bits, $warning_bits) = ($^H, ${^WARNING_BITS})} | |
483 | \& $deparser->ambient_pragmas ( | |
484 | \& hint_bits => $hint_bits, | |
485 | \& warning_bits => $warning_bits, | |
486 | \& '$[' => 0 + $[ | |
487 | \& ); } | |
488 | .Ve | |
489 | .Sp | |
490 | which specifies that the ambient pragmas are exactly those which | |
491 | are in scope at the point of calling. | |
492 | .Sh "coderef2text" | |
493 | .IX Subsection "coderef2text" | |
494 | .Vb 2 | |
495 | \& $body = $deparse->coderef2text(\e&func) | |
496 | \& $body = $deparse->coderef2text(sub ($$) { ... }) | |
497 | .Ve | |
498 | .PP | |
499 | Return source code for the body of a subroutine (a block, optionally | |
500 | preceded by a prototype in parens), given a reference to the | |
501 | sub. Because a subroutine can have no names, or more than one name, | |
502 | this method doesn't return a complete subroutine definition \*(-- if you | |
503 | want to eval the result, you should prepend \*(L"sub subname \*(R", or \*(L"sub \*(R" | |
504 | for an anonymous function constructor. Unless the sub was defined in | |
505 | the main:: package, the code will include a package declaration. | |
506 | .SH "BUGS" | |
507 | .IX Header "BUGS" | |
508 | .IP "\(bu" 4 | |
509 | The only pragmas to be completely supported are: \f(CW\*(C`use warnings\*(C'\fR, | |
510 | \&\f(CW\*(C`use strict 'refs'\*(C'\fR, \f(CW\*(C`use bytes\*(C'\fR, and \f(CW\*(C`use integer\*(C'\fR. (\f(CW$[\fR, which | |
511 | behaves like a pragma, is also supported.) | |
512 | .Sp | |
513 | Excepting those listed above, we're currently unable to guarantee that | |
514 | B::Deparse will produce a pragma at the correct point in the program. | |
515 | Since the effects of pragmas are often lexically scoped, this can mean | |
516 | that the pragma holds sway over a different portion of the program | |
517 | than in the input file. | |
518 | .IP "\(bu" 4 | |
519 | In fact, the above is a specific instance of a more general problem: | |
520 | we can't guarantee to produce \s-1BEGIN\s0 blocks or \f(CW\*(C`use\*(C'\fR declarations in | |
521 | exactly the right place. So if you use a module which affects compilation | |
522 | (such as by over-riding keywords, overloading constants or whatever) | |
523 | then the output code might not work as intended. | |
524 | .Sp | |
525 | This is the most serious outstanding problem, and will be very hard | |
526 | to fix. | |
527 | .IP "\(bu" 4 | |
528 | If a keyword is over\-ridden, and your program explicitly calls | |
529 | the built-in version by using CORE::keyword, the output of B::Deparse | |
530 | will not reflect this. If you run the resulting code, it will call | |
531 | the over-ridden version rather than the built-in one. (Maybe there | |
532 | should be an option to \fBalways\fR print keyword calls as \f(CW\*(C`CORE::name\*(C'\fR.) | |
533 | .IP "\(bu" 4 | |
534 | \&\f(CW\*(C`sort foo (1, 2, 3)\*(C'\fR comes out as \f(CW\*(C`sort (foo 1, 2, 3)\*(C'\fR, which | |
535 | causes perl to issue a warning. | |
536 | .Sp | |
537 | The obvious fix doesn't work, because these are different: | |
538 | .Sp | |
539 | .Vb 2 | |
540 | \& print (FOO 1, 2, 3), 4, 5, 6; | |
541 | \& print FOO (1, 2, 3), 4, 5, 6; | |
542 | .Ve | |
543 | .IP "\(bu" 4 | |
544 | Constants (other than simple strings or numbers) don't work properly. | |
545 | Pathological examples that fail (and probably always will) include: | |
546 | .Sp | |
547 | .Vb 2 | |
548 | \& use constant E2BIG => ($!=7); | |
549 | \& use constant x=>\e$x; print x | |
550 | .Ve | |
551 | .Sp | |
552 | The following could (and should) be made to work: | |
553 | .Sp | |
554 | .Vb 2 | |
555 | \& use constant regex => qr/blah/; | |
556 | \& print regex; | |
557 | .Ve | |
558 | .IP "\(bu" 4 | |
559 | An input file that uses source filtering probably won't be deparsed into | |
560 | runnable code, because it will still include the \fBuse\fR declaration | |
561 | for the source filtering module, even though the code that is | |
562 | produced is already ordinary Perl which shouldn't be filtered again. | |
563 | .IP "\(bu" 4 | |
564 | There are probably many more bugs on non-ASCII platforms (\s-1EBCDIC\s0). | |
565 | .SH "AUTHOR" | |
566 | .IX Header "AUTHOR" | |
567 | Stephen McCamant <smcc@CSUA.Berkeley.EDU>, based on an earlier | |
568 | version by Malcolm Beattie <mbeattie@sable.ox.ac.uk>, with | |
569 | contributions from Gisle Aas, James Duncan, Albert Dvornik, Robin | |
570 | Houston, Hugo van der Sanden, Gurusamy Sarathy, Nick Ing\-Simmons, | |
571 | and Rafael Garcia\-Suarez. |