| 1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
| 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 "2001-09-21" "perl v5.8.8" "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,\-d\fR][\fB,\-f\fR\fI\s-1FILE\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 | While B::Deparse goes to some lengths to try to figure out what your |
| 153 | original program was doing, some parts of the language can still trip |
| 154 | it up; it still fails even on some parts of Perl's own test suite. If |
| 155 | you encounter a failure other than the most common ones described in |
| 156 | the \s-1BUGS\s0 section below, you can help contribute to B::Deparse's |
| 157 | ongoing development by submitting a bug report with a small |
| 158 | example. |
| 159 | .SH "OPTIONS" |
| 160 | .IX Header "OPTIONS" |
| 161 | As with all compiler backend options, these must follow directly after |
| 162 | the '\-MO=Deparse', separated by a comma but not any white space. |
| 163 | .IP "\fB\-d\fR" 4 |
| 164 | .IX Item "-d" |
| 165 | Output data values (when they appear as constants) using Data::Dumper. |
| 166 | Without this option, B::Deparse will use some simple routines of its |
| 167 | own for the same purpose. Currently, Data::Dumper is better for some |
| 168 | kinds of data (such as complex structures with sharing and |
| 169 | self\-reference) while the built-in routines are better for others |
| 170 | (such as odd floating-point values). |
| 171 | .IP "\fB\-f\fR\fI\s-1FILE\s0\fR" 4 |
| 172 | .IX Item "-fFILE" |
| 173 | Normally, B::Deparse deparses the main code of a program, and all the subs |
| 174 | defined in the same file. To include subs defined in other files, pass the |
| 175 | \&\fB\-f\fR option with the filename. You can pass the \fB\-f\fR option several times, to |
| 176 | include more than one secondary file. (Most of the time you don't want to |
| 177 | use it at all.) You can also use this option to include subs which are |
| 178 | defined in the scope of a \fB#line\fR directive with two parameters. |
| 179 | .IP "\fB\-l\fR" 4 |
| 180 | .IX Item "-l" |
| 181 | Add '#line' declarations to the output based on the line and file |
| 182 | locations of the original code. |
| 183 | .IP "\fB\-p\fR" 4 |
| 184 | .IX Item "-p" |
| 185 | Print extra parentheses. Without this option, B::Deparse includes |
| 186 | parentheses in its output only when they are needed, based on the |
| 187 | structure of your program. With \fB\-p\fR, it uses parentheses (almost) |
| 188 | whenever they would be legal. This can be useful if you are used to |
| 189 | \&\s-1LISP\s0, or if you want to see how perl parses your input. If you say |
| 190 | .Sp |
| 191 | .Vb 3 |
| 192 | \& if ($var & 0x7f == 65) {print "Gimme an A!"} |
| 193 | \& print ($which ? $a : $b), "\en"; |
| 194 | \& $name = $ENV{USER} or "Bob"; |
| 195 | .Ve |
| 196 | .Sp |
| 197 | \&\f(CW\*(C`B::Deparse,\-p\*(C'\fR will print |
| 198 | .Sp |
| 199 | .Vb 5 |
| 200 | \& if (($var & 0)) { |
| 201 | \& print('Gimme an A!') |
| 202 | \& }; |
| 203 | \& (print(($which ? $a : $b)), '???'); |
| 204 | \& (($name = $ENV{'USER'}) or '???') |
| 205 | .Ve |
| 206 | .Sp |
| 207 | which probably isn't what you intended (the \f(CW'???'\fR is a sign that |
| 208 | perl optimized away a constant value). |
| 209 | .IP "\fB\-P\fR" 4 |
| 210 | .IX Item "-P" |
| 211 | Disable prototype checking. With this option, all function calls are |
| 212 | deparsed as if no prototype was defined for them. In other words, |
| 213 | .Sp |
| 214 | .Vb 1 |
| 215 | \& perl -MO=Deparse,-P -e 'sub foo (\e@) { 1 } foo @x' |
| 216 | .Ve |
| 217 | .Sp |
| 218 | will print |
| 219 | .Sp |
| 220 | .Vb 4 |
| 221 | \& sub foo (\e@) { |
| 222 | \& 1; |
| 223 | \& } |
| 224 | \& &foo(\e@x); |
| 225 | .Ve |
| 226 | .Sp |
| 227 | making clear how the parameters are actually passed to \f(CW\*(C`foo\*(C'\fR. |
| 228 | .IP "\fB\-q\fR" 4 |
| 229 | .IX Item "-q" |
| 230 | Expand double-quoted strings into the corresponding combinations of |
| 231 | concatenation, uc, ucfirst, lc, lcfirst, quotemeta, and join. For |
| 232 | instance, print |
| 233 | .Sp |
| 234 | .Vb 1 |
| 235 | \& print "Hello, $world, @ladies, \eu$gentlemen\eE, \eu\eL$me!"; |
| 236 | .Ve |
| 237 | .Sp |
| 238 | as |
| 239 | .Sp |
| 240 | .Vb 2 |
| 241 | \& print 'Hello, ' . $world . ', ' . join($", @ladies) . ', ' |
| 242 | \& . ucfirst($gentlemen) . ', ' . ucfirst(lc $me . '!'); |
| 243 | .Ve |
| 244 | .Sp |
| 245 | Note that the expanded form represents the way perl handles such |
| 246 | constructions internally \*(-- this option actually turns off the reverse |
| 247 | translation that B::Deparse usually does. On the other hand, note that |
| 248 | \&\f(CW\*(C`$x = "$y"\*(C'\fR is not the same as \f(CW\*(C`$x = $y\*(C'\fR: the former makes the value |
| 249 | of \f(CW$y\fR into a string before doing the assignment. |
| 250 | .IP "\fB\-s\fR\fI\s-1LETTERS\s0\fR" 4 |
| 251 | .IX Item "-sLETTERS" |
| 252 | Tweak the style of B::Deparse's output. The letters should follow |
| 253 | directly after the 's', with no space or punctuation. The following |
| 254 | options are available: |
| 255 | .RS 4 |
| 256 | .IP "\fBC\fR" 4 |
| 257 | .IX Item "C" |
| 258 | Cuddle \f(CW\*(C`elsif\*(C'\fR, \f(CW\*(C`else\*(C'\fR, and \f(CW\*(C`continue\*(C'\fR blocks. For example, print |
| 259 | .Sp |
| 260 | .Vb 5 |
| 261 | \& if (...) { |
| 262 | \& ... |
| 263 | \& } else { |
| 264 | \& ... |
| 265 | \& } |
| 266 | .Ve |
| 267 | .Sp |
| 268 | instead of |
| 269 | .Sp |
| 270 | .Vb 6 |
| 271 | \& if (...) { |
| 272 | \& ... |
| 273 | \& } |
| 274 | \& else { |
| 275 | \& ... |
| 276 | \& } |
| 277 | .Ve |
| 278 | .Sp |
| 279 | The default is not to cuddle. |
| 280 | .IP "\fBi\fR\fI\s-1NUMBER\s0\fR" 4 |
| 281 | .IX Item "iNUMBER" |
| 282 | Indent lines by multiples of \fI\s-1NUMBER\s0\fR columns. The default is 4 columns. |
| 283 | .IP "\fBT\fR" 4 |
| 284 | .IX Item "T" |
| 285 | Use tabs for each 8 columns of indent. The default is to use only spaces. |
| 286 | For instance, if the style options are \fB\-si4T\fR, a line that's indented |
| 287 | 3 times will be preceded by one tab and four spaces; if the options were |
| 288 | \&\fB\-si8T\fR, the same line would be preceded by three tabs. |
| 289 | .IP "\fBv\fR\fI\s-1STRING\s0\fR\fB.\fR" 4 |
| 290 | .IX Item "vSTRING." |
| 291 | Print \fI\s-1STRING\s0\fR for the value of a constant that can't be determined |
| 292 | because it was optimized away (mnemonic: this happens when a constant |
| 293 | is used in \fBv\fRoid context). The end of the string is marked by a period. |
| 294 | The string should be a valid perl expression, generally a constant. |
| 295 | Note that unless it's a number, it probably needs to be quoted, and on |
| 296 | a command line quotes need to be protected from the shell. Some |
| 297 | conventional values include 0, 1, 42, '', 'foo', and |
| 298 | \&'Useless use of constant omitted' (which may need to be |
| 299 | \&\fB\-sv\*(L"'Useless use of constant omitted'.\*(R"\fR |
| 300 | or something similar depending on your shell). The default is '???'. |
| 301 | If you're using B::Deparse on a module or other file that's require'd, |
| 302 | you shouldn't use a value that evaluates to false, since the customary |
| 303 | true constant at the end of a module will be in void context when the |
| 304 | file is compiled as a main program. |
| 305 | .RE |
| 306 | .RS 4 |
| 307 | .RE |
| 308 | .IP "\fB\-x\fR\fI\s-1LEVEL\s0\fR" 4 |
| 309 | .IX Item "-xLEVEL" |
| 310 | Expand conventional syntax constructions into equivalent ones that expose |
| 311 | their internal operation. \fI\s-1LEVEL\s0\fR should be a digit, with higher values |
| 312 | meaning more expansion. As with \fB\-q\fR, this actually involves turning off |
| 313 | special cases in B::Deparse's normal operations. |
| 314 | .Sp |
| 315 | If \fI\s-1LEVEL\s0\fR is at least 3, \f(CW\*(C`for\*(C'\fR loops will be translated into equivalent |
| 316 | while loops with continue blocks; for instance |
| 317 | .Sp |
| 318 | .Vb 3 |
| 319 | \& for ($i = 0; $i < 10; ++$i) { |
| 320 | \& print $i; |
| 321 | \& } |
| 322 | .Ve |
| 323 | .Sp |
| 324 | turns into |
| 325 | .Sp |
| 326 | .Vb 6 |
| 327 | \& $i = 0; |
| 328 | \& while ($i < 10) { |
| 329 | \& print $i; |
| 330 | \& } continue { |
| 331 | \& ++$i |
| 332 | \& } |
| 333 | .Ve |
| 334 | .Sp |
| 335 | Note that in a few cases this translation can't be perfectly carried back |
| 336 | into the source code \*(-- if the loop's initializer declares a my variable, |
| 337 | for instance, it won't have the correct scope outside of the loop. |
| 338 | .Sp |
| 339 | If \fI\s-1LEVEL\s0\fR is at least 5, \f(CW\*(C`use\*(C'\fR declarations will be translated into |
| 340 | \&\f(CW\*(C`BEGIN\*(C'\fR blocks containing calls to \f(CW\*(C`require\*(C'\fR and \f(CW\*(C`import\*(C'\fR; for |
| 341 | instance, |
| 342 | .Sp |
| 343 | .Vb 1 |
| 344 | \& use strict 'refs'; |
| 345 | .Ve |
| 346 | .Sp |
| 347 | turns into |
| 348 | .Sp |
| 349 | .Vb 6 |
| 350 | \& sub BEGIN { |
| 351 | \& require strict; |
| 352 | \& do { |
| 353 | \& 'strict'->import('refs') |
| 354 | \& }; |
| 355 | \& } |
| 356 | .Ve |
| 357 | .Sp |
| 358 | If \fI\s-1LEVEL\s0\fR is at least 7, \f(CW\*(C`if\*(C'\fR statements will be translated into |
| 359 | equivalent expressions using \f(CW\*(C`&&\*(C'\fR, \f(CW\*(C`?:\*(C'\fR and \f(CW\*(C`do {}\*(C'\fR; for instance |
| 360 | .Sp |
| 361 | .Vb 9 |
| 362 | \& print 'hi' if $nice; |
| 363 | \& if ($nice) { |
| 364 | \& print 'hi'; |
| 365 | \& } |
| 366 | \& if ($nice) { |
| 367 | \& print 'hi'; |
| 368 | \& } else { |
| 369 | \& print 'bye'; |
| 370 | \& } |
| 371 | .Ve |
| 372 | .Sp |
| 373 | turns into |
| 374 | .Sp |
| 375 | .Vb 3 |
| 376 | \& $nice and print 'hi'; |
| 377 | \& $nice and do { print 'hi' }; |
| 378 | \& $nice ? do { print 'hi' } : do { print 'bye' }; |
| 379 | .Ve |
| 380 | .Sp |
| 381 | Long sequences of elsifs will turn into nested ternary operators, which |
| 382 | B::Deparse doesn't know how to indent nicely. |
| 383 | .SH "USING B::Deparse AS A MODULE" |
| 384 | .IX Header "USING B::Deparse AS A MODULE" |
| 385 | .Sh "Synopsis" |
| 386 | .IX Subsection "Synopsis" |
| 387 | .Vb 4 |
| 388 | \& use B::Deparse; |
| 389 | \& $deparse = B::Deparse->new("-p", "-sC"); |
| 390 | \& $body = $deparse->coderef2text(\e&func); |
| 391 | \& eval "sub func $body"; # the inverse operation |
| 392 | .Ve |
| 393 | .Sh "Description" |
| 394 | .IX Subsection "Description" |
| 395 | B::Deparse can also be used on a sub-by-sub basis from other perl |
| 396 | programs. |
| 397 | .Sh "new" |
| 398 | .IX Subsection "new" |
| 399 | .Vb 1 |
| 400 | \& $deparse = B::Deparse->new(OPTIONS) |
| 401 | .Ve |
| 402 | .PP |
| 403 | Create an object to store the state of a deparsing operation and any |
| 404 | options. The options are the same as those that can be given on the |
| 405 | command line (see \*(L"\s-1OPTIONS\s0\*(R"); options that are separated by commas |
| 406 | after \fB\-MO=Deparse\fR should be given as separate strings. Some |
| 407 | options, like \fB\-u\fR, don't make sense for a single subroutine, so |
| 408 | don't pass them. |
| 409 | .Sh "ambient_pragmas" |
| 410 | .IX Subsection "ambient_pragmas" |
| 411 | .Vb 1 |
| 412 | \& $deparse->ambient_pragmas(strict => 'all', '$[' => $[); |
| 413 | .Ve |
| 414 | .PP |
| 415 | The compilation of a subroutine can be affected by a few compiler |
| 416 | directives, \fBpragmas\fR. These are: |
| 417 | .IP "\(bu" 4 |
| 418 | use strict; |
| 419 | .IP "\(bu" 4 |
| 420 | use warnings; |
| 421 | .IP "\(bu" 4 |
| 422 | Assigning to the special variable $[ |
| 423 | .IP "\(bu" 4 |
| 424 | use integer; |
| 425 | .IP "\(bu" 4 |
| 426 | use bytes; |
| 427 | .IP "\(bu" 4 |
| 428 | use utf8; |
| 429 | .IP "\(bu" 4 |
| 430 | use re; |
| 431 | .PP |
| 432 | Ordinarily, if you use B::Deparse on a subroutine which has |
| 433 | been compiled in the presence of one or more of these pragmas, |
| 434 | the output will include statements to turn on the appropriate |
| 435 | directives. So if you then compile the code returned by coderef2text, |
| 436 | it will behave the same way as the subroutine which you deparsed. |
| 437 | .PP |
| 438 | However, you may know that you intend to use the results in a |
| 439 | particular context, where some pragmas are already in scope. In |
| 440 | this case, you use the \fBambient_pragmas\fR method to describe the |
| 441 | assumptions you wish to make. |
| 442 | .PP |
| 443 | Not all of the options currently have any useful effect. See |
| 444 | \&\*(L"\s-1BUGS\s0\*(R" for more details. |
| 445 | .PP |
| 446 | The parameters it accepts are: |
| 447 | .IP "strict" 4 |
| 448 | .IX Item "strict" |
| 449 | Takes a string, possibly containing several values separated |
| 450 | by whitespace. The special values \*(L"all\*(R" and \*(L"none\*(R" mean what you'd |
| 451 | expect. |
| 452 | .Sp |
| 453 | .Vb 1 |
| 454 | \& $deparse->ambient_pragmas(strict => 'subs refs'); |
| 455 | .Ve |
| 456 | .IP "$[" 4 |
| 457 | Takes a number, the value of the array base $[. |
| 458 | .IP "bytes" 4 |
| 459 | .IX Item "bytes" |
| 460 | .PD 0 |
| 461 | .IP "utf8" 4 |
| 462 | .IX Item "utf8" |
| 463 | .IP "integer" 4 |
| 464 | .IX Item "integer" |
| 465 | .PD |
| 466 | If the value is true, then the appropriate pragma is assumed to |
| 467 | be in the ambient scope, otherwise not. |
| 468 | .IP "re" 4 |
| 469 | .IX Item "re" |
| 470 | Takes a string, possibly containing a whitespace-separated list of |
| 471 | values. The values \*(L"all\*(R" and \*(L"none\*(R" are special. It's also permissible |
| 472 | to pass an array reference here. |
| 473 | .Sp |
| 474 | .Vb 1 |
| 475 | \& $deparser->ambient_pragmas(re => 'eval'); |
| 476 | .Ve |
| 477 | .IP "warnings" 4 |
| 478 | .IX Item "warnings" |
| 479 | Takes a string, possibly containing a whitespace-separated list of |
| 480 | values. The values \*(L"all\*(R" and \*(L"none\*(R" are special, again. It's also |
| 481 | permissible to pass an array reference here. |
| 482 | .Sp |
| 483 | .Vb 1 |
| 484 | \& $deparser->ambient_pragmas(warnings => [qw[void io]]); |
| 485 | .Ve |
| 486 | .Sp |
| 487 | If one of the values is the string \*(L"\s-1FATAL\s0\*(R", then all the warnings |
| 488 | in that list will be considered fatal, just as with the \fBwarnings\fR |
| 489 | pragma itself. Should you need to specify that some warnings are |
| 490 | fatal, and others are merely enabled, you can pass the \fBwarnings\fR |
| 491 | parameter twice: |
| 492 | .Sp |
| 493 | .Vb 4 |
| 494 | \& $deparser->ambient_pragmas( |
| 495 | \& warnings => 'all', |
| 496 | \& warnings => [FATAL => qw/void io/], |
| 497 | \& ); |
| 498 | .Ve |
| 499 | .Sp |
| 500 | See perllexwarn for more information about lexical warnings. |
| 501 | .IP "hint_bits" 4 |
| 502 | .IX Item "hint_bits" |
| 503 | .PD 0 |
| 504 | .IP "warning_bits" 4 |
| 505 | .IX Item "warning_bits" |
| 506 | .PD |
| 507 | These two parameters are used to specify the ambient pragmas in |
| 508 | the format used by the special variables $^H and ${^WARNING_BITS}. |
| 509 | .Sp |
| 510 | They exist principally so that you can write code like: |
| 511 | .Sp |
| 512 | .Vb 7 |
| 513 | \& { my ($hint_bits, $warning_bits); |
| 514 | \& BEGIN {($hint_bits, $warning_bits) = ($^H, ${^WARNING_BITS})} |
| 515 | \& $deparser->ambient_pragmas ( |
| 516 | \& hint_bits => $hint_bits, |
| 517 | \& warning_bits => $warning_bits, |
| 518 | \& '$[' => 0 + $[ |
| 519 | \& ); } |
| 520 | .Ve |
| 521 | .Sp |
| 522 | which specifies that the ambient pragmas are exactly those which |
| 523 | are in scope at the point of calling. |
| 524 | .Sh "coderef2text" |
| 525 | .IX Subsection "coderef2text" |
| 526 | .Vb 2 |
| 527 | \& $body = $deparse->coderef2text(\e&func) |
| 528 | \& $body = $deparse->coderef2text(sub ($$) { ... }) |
| 529 | .Ve |
| 530 | .PP |
| 531 | Return source code for the body of a subroutine (a block, optionally |
| 532 | preceded by a prototype in parens), given a reference to the |
| 533 | sub. Because a subroutine can have no names, or more than one name, |
| 534 | this method doesn't return a complete subroutine definition \*(-- if you |
| 535 | want to eval the result, you should prepend \*(L"sub subname \*(R", or \*(L"sub \*(R" |
| 536 | for an anonymous function constructor. Unless the sub was defined in |
| 537 | the main:: package, the code will include a package declaration. |
| 538 | .SH "BUGS" |
| 539 | .IX Header "BUGS" |
| 540 | .IP "\(bu" 4 |
| 541 | The only pragmas to be completely supported are: \f(CW\*(C`use warnings\*(C'\fR, |
| 542 | \&\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 |
| 543 | behaves like a pragma, is also supported.) |
| 544 | .Sp |
| 545 | Excepting those listed above, we're currently unable to guarantee that |
| 546 | B::Deparse will produce a pragma at the correct point in the program. |
| 547 | (Specifically, pragmas at the beginning of a block often appear right |
| 548 | before the start of the block instead.) |
| 549 | Since the effects of pragmas are often lexically scoped, this can mean |
| 550 | that the pragma holds sway over a different portion of the program |
| 551 | than in the input file. |
| 552 | .IP "\(bu" 4 |
| 553 | In fact, the above is a specific instance of a more general problem: |
| 554 | we can't guarantee to produce \s-1BEGIN\s0 blocks or \f(CW\*(C`use\*(C'\fR declarations in |
| 555 | exactly the right place. So if you use a module which affects compilation |
| 556 | (such as by over-riding keywords, overloading constants or whatever) |
| 557 | then the output code might not work as intended. |
| 558 | .Sp |
| 559 | This is the most serious outstanding problem, and will require some help |
| 560 | from the Perl core to fix. |
| 561 | .IP "\(bu" 4 |
| 562 | If a keyword is over\-ridden, and your program explicitly calls |
| 563 | the built-in version by using CORE::keyword, the output of B::Deparse |
| 564 | will not reflect this. If you run the resulting code, it will call |
| 565 | the over-ridden version rather than the built-in one. (Maybe there |
| 566 | should be an option to \fBalways\fR print keyword calls as \f(CW\*(C`CORE::name\*(C'\fR.) |
| 567 | .IP "\(bu" 4 |
| 568 | Some constants don't print correctly either with or without \fB\-d\fR. |
| 569 | For instance, neither B::Deparse nor Data::Dumper know how to print |
| 570 | dual-valued scalars correctly, as in: |
| 571 | .Sp |
| 572 | .Vb 1 |
| 573 | \& use constant E2BIG => ($!=7); $y = E2BIG; print $y, 0+$y; |
| 574 | .Ve |
| 575 | .IP "\(bu" 4 |
| 576 | An input file that uses source filtering probably won't be deparsed into |
| 577 | runnable code, because it will still include the \fBuse\fR declaration |
| 578 | for the source filtering module, even though the code that is |
| 579 | produced is already ordinary Perl which shouldn't be filtered again. |
| 580 | .IP "\(bu" 4 |
| 581 | Optimised away statements are rendered as '???'. This includes statements that |
| 582 | have a compile-time side\-effect, such as the obscure |
| 583 | .Sp |
| 584 | .Vb 1 |
| 585 | \& my $x if 0; |
| 586 | .Ve |
| 587 | .Sp |
| 588 | which is not, consequently, deparsed correctly. |
| 589 | .IP "\(bu" 4 |
| 590 | There are probably many more bugs on non-ASCII platforms (\s-1EBCDIC\s0). |
| 591 | .SH "AUTHOR" |
| 592 | .IX Header "AUTHOR" |
| 593 | Stephen McCamant <smcc@CSUA.Berkeley.EDU>, based on an earlier version |
| 594 | by Malcolm Beattie <mbeattie@sable.ox.ac.uk>, with contributions from |
| 595 | Gisle Aas, James Duncan, Albert Dvornik, Robin Houston, Dave Mitchell, |
| 596 | Hugo van der Sanden, Gurusamy Sarathy, Nick Ing\-Simmons, and Rafael |
| 597 | Garcia\-Suarez. |