home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _130f74751955d521713124a931e700b9 < prev    next >
Text File  |  2000-03-23  |  10KB  |  244 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>B::Deparse - Perl compiler backend to produce perl code</TITLE>
  5. <LINK REL="stylesheet" HREF="../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> B::Deparse - Perl compiler backend to produce perl code</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#options">OPTIONS</A></LI>
  26.     <LI><A HREF="#using b::deparse as a module">USING B::Deparse AS A MODULE</A></LI>
  27.     <UL>
  28.  
  29.         <LI><A HREF="#synopsis">Synopsis</A></LI>
  30.         <LI><A HREF="#description">Description</A></LI>
  31.         <LI><A HREF="#new">new</A></LI>
  32.         <LI><A HREF="#coderef2text">coderef2text</A></LI>
  33.     </UL>
  34.  
  35.     <LI><A HREF="#bugs">BUGS</A></LI>
  36.     <LI><A HREF="#author">AUTHOR</A></LI>
  37. </UL>
  38. <!-- INDEX END -->
  39.  
  40. <HR>
  41. <P>
  42. <H1><A NAME="name">NAME</A></H1>
  43. <P>B::Deparse - Perl compiler backend to produce perl code</P>
  44. <P>
  45. <HR>
  46. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  47. <UL>
  48. <LI>Linux</LI>
  49. <LI>Solaris</LI>
  50. <LI>Windows</LI>
  51. </UL>
  52. <HR>
  53. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  54. <P><STRONG>perl</STRONG> <STRONG>-MO=Deparse</STRONG>[<STRONG>,-u</STRONG><EM>PACKAGE</EM>][<STRONG>,-p</STRONG>][<STRONG>,-q</STRONG>][<STRONG>,-l</STRONG>][<STRONG>,-s</STRONG><EM>LETTERS</EM>]
  55.      <EM>prog.pl</EM></P>
  56. <P>
  57. <HR>
  58. <H1><A NAME="description">DESCRIPTION</A></H1>
  59. <P>B::Deparse is a backend module for the Perl compiler that generates
  60. perl source code, based on the internal compiled structure that perl
  61. itself creates after parsing a program. The output of B::Deparse won't
  62. be exactly the same as the original source, since perl doesn't keep
  63. track of comments or whitespace, and there isn't a one-to-one
  64. correspondence between perl's syntactical constructions and their
  65. compiled form, but it will often be close. When you use the <STRONG>-p</STRONG>
  66. option, the output also includes parentheses even when they are not
  67. required by precedence, which can make it easy to see if perl is
  68. parsing your expressions the way you intended.</P>
  69. <P>Please note that this module is mainly new and untested code and is
  70. still under development, so it may change in the future.</P>
  71. <P>
  72. <HR>
  73. <H1><A NAME="options">OPTIONS</A></H1>
  74. <P>As with all compiler backend options, these must follow directly after
  75. the '-MO=Deparse', separated by a comma but not any white space.</P>
  76. <DL>
  77. <DT><STRONG><A NAME="item_%2Dl"><STRONG>-l</STRONG></A></STRONG><BR>
  78. <DD>
  79. Add '#line' declarations to the output based on the line and file
  80. locations of the original code.
  81. <P></P>
  82. <DT><STRONG><A NAME="item_%2Dp"><STRONG>-p</STRONG></A></STRONG><BR>
  83. <DD>
  84. Print extra parentheses. Without this option, B::Deparse includes
  85. parentheses in its output only when they are needed, based on the
  86. structure of your program. With <STRONG>-p</STRONG>, it uses parentheses (almost)
  87. whenever they would be legal. This can be useful if you are used to
  88. LISP, or if you want to see how perl parses your input. If you say
  89. <PRE>
  90.     if ($var & 0x7f == 65) {print "Gimme an A!"} 
  91.     print ($which ? $a : $b), "\n";
  92.     $name = $ENV{USER} or "Bob";</PRE>
  93. <P><CODE>B::Deparse,-p</CODE> will print</P>
  94. <PRE>
  95.     if (($var & 0)) {
  96.         print('Gimme an A!')
  97.     };
  98.     (print(($which ? $a : $b)), '???');
  99.     (($name = $ENV{'USER'}) or '???')</PRE>
  100. <P>which probably isn't what you intended (the <CODE>'???'</CODE> is a sign that
  101. perl optimized away a constant value).</P>
  102. <P></P>
  103. <DT><STRONG><A NAME="item_%2Dq"><STRONG>-q</STRONG></A></STRONG><BR>
  104. <DD>
  105. Expand double-quoted strings into the corresponding combinations of
  106. concatenation, uc, ucfirst, lc, lcfirst, quotemeta, and join. For
  107. instance, print
  108. <PRE>
  109.     print "Hello, $world, @ladies, \u$gentlemen\E, \u\L$me!";</PRE>
  110. <P>as</P>
  111. <PRE>
  112.     print 'Hello, ' . $world . ', ' . join($", @ladies) . ', '
  113.           . ucfirst($gentlemen) . ', ' . ucfirst(lc $me . '!');</PRE>
  114. <P>Note that the expanded form represents the way perl handles such
  115. constructions internally -- this option actually turns off the reverse
  116. translation that B::Deparse usually does. On the other hand, note that
  117. <CODE>$x = "$y"</CODE> is not the same as <CODE>$x = $y</CODE>: the former makes the value
  118. of $y into a string before doing the assignment.</P>
  119. <P></P>
  120. <DT><STRONG><A NAME="item_%2DuPACKAGE"><STRONG>-u</STRONG><EM>PACKAGE</EM></A></STRONG><BR>
  121. <DD>
  122. Normally, B::Deparse deparses the main code of a program, all the subs
  123. called by the main program (and all the subs called by them,
  124. recursively), and any other subs in the main:: package. To include
  125. subs in other packages that aren't called directly, such as AUTOLOAD,
  126. DESTROY, other subs called automatically by perl, and methods (which
  127. aren't resolved to subs until runtime), use the <STRONG>-u</STRONG> option. The
  128. argument to <STRONG>-u</STRONG> is the name of a package, and should follow directly
  129. after the 'u'. Multiple <STRONG>-u</STRONG> options may be given, separated by
  130. commas.  Note that unlike some other backends, B::Deparse doesn't
  131. (yet) try to guess automatically when <STRONG>-u</STRONG> is needed -- you must
  132. invoke it yourself.
  133. <P></P>
  134. <DT><STRONG><A NAME="item_%2DsLETTERS"><STRONG>-s</STRONG><EM>LETTERS</EM></A></STRONG><BR>
  135. <DD>
  136. Tweak the style of B::Deparse's output. The letters should follow
  137. directly after the 's', with no space or punctuation. The following
  138. options are available:
  139. <DL>
  140. <DT><STRONG><A NAME="item_C"><STRONG>C</STRONG></A></STRONG><BR>
  141. <DD>
  142. Cuddle <CODE>elsif</CODE>, <CODE>else</CODE>, and <A HREF="../../lib/Pod/perlfunc.html#item_continue"><CODE>continue</CODE></A> blocks. For example, print
  143. <PRE>
  144.     if (...) {
  145.          ...
  146.     } else {
  147.          ...
  148.     }</PRE>
  149. <P>instead of</P>
  150. <PRE>
  151.     if (...) {
  152.          ...
  153.     }
  154.     else {
  155.          ...
  156.     }</PRE>
  157. <P>The default is not to cuddle.</P>
  158. <P></P>
  159. <DT><STRONG><A NAME="item_iNUMBER"><STRONG>i</STRONG><EM>NUMBER</EM></A></STRONG><BR>
  160. <DD>
  161. Indent lines by multiples of <EM>NUMBER</EM> columns. The default is 4 columns.
  162. <P></P>
  163. <DT><STRONG><A NAME="item_T"><STRONG>T</STRONG></A></STRONG><BR>
  164. <DD>
  165. Use tabs for each 8 columns of indent. The default is to use only spaces.
  166. For instance, if the style options are <STRONG>-si4T</STRONG>, a line that's indented
  167. 3 times will be preceded by one tab and four spaces; if the options were
  168. <STRONG>-si8T</STRONG>, the same line would be preceded by three tabs.
  169. <P></P>
  170. <DT><STRONG><A NAME="item_vSTRING%2E"><STRONG>v</STRONG><EM>STRING</EM><STRONG>.</STRONG></A></STRONG><BR>
  171. <DD>
  172. Print <EM>STRING</EM> for the value of a constant that can't be determined
  173. because it was optimized away (mnemonic: this happens when a constant
  174. is used in <STRONG>v</STRONG>oid context). The end of the string is marked by a period.
  175. The string should be a valid perl expression, generally a constant.
  176. Note that unless it's a number, it probably needs to be quoted, and on
  177. a command line quotes need to be protected from the shell. Some
  178. conventional values include 0, 1, 42, '', 'foo', and
  179. 'Useless use of constant omitted' (which may need to be
  180. <STRONG>-sv``'Useless use of constant omitted'.''</STRONG>
  181. or something similar depending on your shell). The default is '???'.
  182. If you're using B::Deparse on a module or other file that's require'd,
  183. you shouldn't use a value that evaluates to false, since the customary
  184. true constant at the end of a module will be in void context when the
  185. file is compiled as a main program.
  186. <P></P></DL>
  187. </DL>
  188. <P>
  189. <HR>
  190. <H1><A NAME="using b::deparse as a module">USING B::Deparse AS A MODULE</A></H1>
  191. <P>
  192. <H2><A NAME="synopsis">Synopsis</A></H2>
  193. <PRE>
  194.     use B::Deparse;
  195.     $deparse = B::Deparse->new("-p", "-sC");
  196.     $body = $deparse->coderef2text(\&func);
  197.     eval "sub func $body"; # the inverse operation</PRE>
  198. <P>
  199. <H2><A NAME="description">Description</A></H2>
  200. <P>B::Deparse can also be used on a sub-by-sub basis from other perl
  201. programs.</P>
  202. <P>
  203. <H2><A NAME="new">new</A></H2>
  204. <PRE>
  205.     $deparse = B::Deparse->new(OPTIONS)</PRE>
  206. <P>Create an object to store the state of a deparsing operation and any
  207. options. The options are the same as those that can be given on the
  208. command line (see <A HREF="#options">OPTIONS</A>); options that are separated by commas
  209. after <STRONG>-MO=Deparse</STRONG> should be given as separate strings. Some
  210. options, like <STRONG>-u</STRONG>, don't make sense for a single subroutine, so
  211. don't pass them.</P>
  212. <P>
  213. <H2><A NAME="coderef2text">coderef2text</A></H2>
  214. <PRE>
  215.     $body = $deparse->coderef2text(\&func)
  216.     $body = $deparse->coderef2text(sub ($$) { ... })</PRE>
  217. <P>Return source code for the body of a subroutine (a block, optionally
  218. preceded by a prototype in parens), given a reference to the
  219. sub. Because a subroutine can have no names, or more than one name,
  220. this method doesn't return a complete subroutine definition -- if you
  221. want to eval the result, you should prepend ``sub subname '', or ``sub ''
  222. for an anonymous function constructor. Unless the sub was defined in
  223. the main:: package, the code will include a package declaration.</P>
  224. <P>
  225. <HR>
  226. <H1><A NAME="bugs">BUGS</A></H1>
  227. <P>See the 'to do' list at the beginning of the module file.</P>
  228. <P>
  229. <HR>
  230. <H1><A NAME="author">AUTHOR</A></H1>
  231. <P>Stephen McCamant <<A HREF="mailto:smccam@uclink4.berkeley.edu">smccam@uclink4.berkeley.edu</A>>, based on an earlier
  232. version by Malcolm Beattie <<A HREF="mailto:mbeattie@sable.ox.ac.uk">mbeattie@sable.ox.ac.uk</A>>, with
  233. contributions from Gisle Aas, James Duncan, Albert Dvornik, Hugo van
  234. der Sanden, Gurusamy Sarathy, and Nick Ing-Simmons.</P>
  235. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  236. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  237. <STRONG><P CLASS=block> B::Deparse - Perl compiler backend to produce perl code</P></STRONG>
  238. </TD></TR>
  239. </TABLE>
  240.  
  241. </BODY>
  242.  
  243. </HTML>
  244.