📄 b::concise.3
字号:
.IP "\fB#firstaddr\fR" 4.IX Item "#firstaddr"The address of the \s-1OP\s0's first child, in hexadecimal..IP "\fB#flags\fR" 4.IX Item "#flags"The \s-1OP\s0's flags, abbreviated as a series of symbols..IP "\fB#flagval\fR" 4.IX Item "#flagval"The numeric value of the \s-1OP\s0's flags..IP "\fB#hints\fR" 4.IX Item "#hints"The \s-1COP\s0's hint flags, rendered with abbreviated names if possible. An emptystring if this is not a \s-1COP\s0. Here are the symbols used:.Sp.Vb 10\& $ strict refs\& & strict subs\& * strict vars\& i integers\& l locale\& b bytes\& [ arybase\& { block scope\& % localise %^H\& < open in\& > open out\& I overload int\& F overload float\& B overload binary\& S overload string\& R overload re\& T taint\& E eval\& X filetest access\& U utf\-8.Ve.IP "\fB#hintsval\fR" 4.IX Item "#hintsval"The numeric value of the \s-1COP\s0's hint flags, or an empty string if this is nota \s-1COP\s0..IP "\fB#hyphseq\fR" 4.IX Item "#hyphseq"The sequence number of the \s-1OP\s0, or a hyphen if it doesn't have one..IP "\fB#label\fR" 4.IX Item "#label"\&'\s-1NEXT\s0', '\s-1LAST\s0', or '\s-1REDO\s0' if the \s-1OP\s0 is a target of one of those in execmode, or empty otherwise..IP "\fB#lastaddr\fR" 4.IX Item "#lastaddr"The address of the \s-1OP\s0's last child, in hexadecimal..IP "\fB#name\fR" 4.IX Item "#name"The \s-1OP\s0's name..IP "\fB#NAME\fR" 4.IX Item "#NAME"The \s-1OP\s0's name, in all caps..IP "\fB#next\fR" 4.IX Item "#next"The sequence number of the \s-1OP\s0's next \s-1OP\s0..IP "\fB#nextaddr\fR" 4.IX Item "#nextaddr"The address of the \s-1OP\s0's next \s-1OP\s0, in hexadecimal..IP "\fB#noise\fR" 4.IX Item "#noise"A one\- or two-character abbreviation for the \s-1OP\s0's name..IP "\fB#private\fR" 4.IX Item "#private"The \s-1OP\s0's private flags, rendered with abbreviated names if possible..IP "\fB#privval\fR" 4.IX Item "#privval"The numeric value of the \s-1OP\s0's private flags..IP "\fB#seq\fR" 4.IX Item "#seq"The sequence number of the \s-1OP\s0. Note that this is a sequence numbergenerated by B::Concise..IP "\fB#seqnum\fR" 4.IX Item "#seqnum"5.8.x and earlier only. 5.9 and later do not provide this..SpThe real sequence number of the \s-1OP\s0, as a regular number and not adjustedto be relative to the start of the real program. (This will generally bea fairly large number because all of \fBB::Concise\fR is compiled beforeyour program is)..IP "\fB#opt\fR" 4.IX Item "#opt"Whether or not the op has been optimised by the peephole optimiser..SpOnly available in 5.9 and later..IP "\fB#sibaddr\fR" 4.IX Item "#sibaddr"The address of the \s-1OP\s0's next youngest sibling, in hexadecimal..IP "\fB#svaddr\fR" 4.IX Item "#svaddr"The address of the \s-1OP\s0's \s-1SV\s0, if it has an \s-1SV\s0, in hexadecimal..IP "\fB#svclass\fR" 4.IX Item "#svclass"The class of the \s-1OP\s0's \s-1SV\s0, if it has one, in all caps (e.g., '\s-1IV\s0')..IP "\fB#svval\fR" 4.IX Item "#svval"The value of the \s-1OP\s0's \s-1SV\s0, if it has one, in a short human-readable format..IP "\fB#targ\fR" 4.IX Item "#targ"The numeric value of the \s-1OP\s0's targ..IP "\fB#targarg\fR" 4.IX Item "#targarg"The name of the variable the \s-1OP\s0's targ refers to, if any, otherwise theletter t followed by the \s-1OP\s0's targ in decimal..IP "\fB#targarglife\fR" 4.IX Item "#targarglife"Same as \fB#targarg\fR, but followed by the \s-1COP\s0 sequence numbers that delimitthe variable's lifetime (or 'end' for a variable in an open scope) for avariable..IP "\fB#typenum\fR" 4.IX Item "#typenum"The numeric value of the \s-1OP\s0's type, in decimal..SH "One-Liner Command tips".IX Header "One-Liner Command tips".IP "perl \-MO=Concise,bar foo.pl" 4.IX Item "perl -MO=Concise,bar foo.pl"Renders only \fIbar()\fR from foo.pl. To see main, drop the ',bar'. To seeboth, add ',\-main'.IP "perl \-MDigest::MD5=md5 \-MO=Concise,md5 \-e1" 4.IX Item "perl -MDigest::MD5=md5 -MO=Concise,md5 -e1"Identifies md5 as an \s-1XS\s0 function. The export is needed so that \s-1BC\s0 canfind it in main..IP "perl \-MPOSIX \-MO=Concise,_POSIX_ARG_MAX \-e1" 4.IX Item "perl -MPOSIX -MO=Concise,_POSIX_ARG_MAX -e1"Identifies _POSIX_ARG_MAX as a constant sub, optimized to an \s-1IV\s0.Although \s-1POSIX\s0 isn't entirely consistent across platforms, this islikely to be present in virtually all of them..IP "perl \-MPOSIX \-MO=Concise,a \-e 'print _POSIX_SAVED_IDS'" 4.IX Item "perl -MPOSIX -MO=Concise,a -e 'print _POSIX_SAVED_IDS'"This renders a print statement, which includes a call to the function.It's identical to rendering a file with a use call and that singlestatement, except for the filename which appears in the nextstate ops..IP "perl \-MPOSIX \-MO=Concise,a \-e 'sub a{_POSIX_SAVED_IDS}'" 4.IX Item "perl -MPOSIX -MO=Concise,a -e 'sub a{_POSIX_SAVED_IDS}'"This is \fBvery\fR similar to previous, only the first two ops differ. Thissubroutine rendering is more representative, insofar as a single mainprogram will have many subs..ie n .IP "perl \-MB::Concise \-e 'B::Concise::compile(""\-exec"",""\-src"", \e%B::Concise::)\->()'" 4.el .IP "perl \-MB::Concise \-e 'B::Concise::compile(``\-exec'',``\-src'', \e%B::Concise::)\->()'" 4.IX Item "perl -MB::Concise -e 'B::Concise::compile(-exec,-src, %B::Concise::)->()'"This renders all functions in the B::Concise package with the sourcelines. It eschews the O framework so that the stashref can be passeddirectly to \fIB::Concise::compile()\fR. See \-stash option for a moreconvenient way to render a package..SH "Using B::Concise outside of the O framework".IX Header "Using B::Concise outside of the O framework"The common (and original) usage of B::Concise was for command-linerenderings of simple code, as given in \s-1EXAMPLE\s0. But you can also use\&\fBB::Concise\fR from your code, and call \fIcompile()\fR directly, andrepeatedly. By doing so, you can avoid the compile-time onlyoperation of O.pm, and even use the debugger to step through\&\fIB::Concise::compile()\fR itself..PPOnce you're doing this, you may alter Concise output by adding newrendering styles, and by optionally adding callback routines whichpopulate new variables, if such were referenced from those (justadded) styles..Sh "Example: Altering Concise Renderings".IX Subsection "Example: Altering Concise Renderings".Vb 9\& use B::Concise qw(set_style add_callback);\& add_style($yourStyleName => $defaultfmt, $gotofmt, $treefmt);\& add_callback\& ( sub {\& my ($h, $op, $format, $level, $stylename) = @_;\& $h\->{variable} = some_func($op);\& });\& $walker = B::Concise::compile(@options,@subnames,@subrefs);\& $walker\->();.Ve.Sh "\fIset_style()\fP".IX Subsection "set_style()"\&\fBset_style\fR accepts 3 arguments, and updates the three format-specscomprising a line-style (basic-exec, goto, tree). It has one minordrawback though; it doesn't register the style under a new name. Thiscan become an issue if you render more than once and switch styles.Thus you may prefer to use \fIadd_style()\fR and/or \fIset_style_standard()\fRinstead..Sh "set_style_standard($name)".IX Subsection "set_style_standard($name)"This restores one of the standard line-styles: \f(CW\*(C`terse\*(C'\fR, \f(CW\*(C`concise\*(C'\fR,\&\f(CW\*(C`linenoise\*(C'\fR, \f(CW\*(C`debug\*(C'\fR, \f(CW\*(C`env\*(C'\fR, into effect. It also accepts stylenames previously defined with \fIadd_style()\fR..Sh "\fIadd_style()\fP".IX Subsection "add_style()"This subroutine accepts a new style name and three style arguments asabove, and creates, registers, and selects the newly named style. It isan error to re-add a style; call \fIset_style_standard()\fR to switch betweenseveral styles..Sh "\fIadd_callback()\fP".IX Subsection "add_callback()"If your newly minted styles refer to any new #variables, you'll needto define a callback subroutine that will populate (or modify) thosevariables. They are then available for use in the style you'vechosen..PPThe callbacks are called for each opcode visited by Concise, in thesame order as they are added. Each subroutine is passed fiveparameters..PP.Vb 6\& 1. A hashref, containing the variable names and values which are\& populated into the report\-line for the op\& 2. the op, as a B<B::OP> object\& 3. a reference to the format string\& 4. the formatting (indent) level\& 5. the selected stylename.Ve.PPTo define your own variables, simply add them to the hash, or changeexisting values if you need to. The level and format are passed in asreferences to scalars, but it is unlikely that they will need to bechanged or even used..Sh "Running \fIB::Concise::compile()\fP".IX Subsection "Running B::Concise::compile()"\&\fBcompile\fR accepts options as described above in \*(L"\s-1OPTIONS\s0\*(R", andarguments, which are either coderefs, or subroutine names..PPIt constructs and returns a \f(CW$treewalker\fR coderef, which when invoked,traverses, or walks, and renders the optrees of the given arguments to\&\s-1STDOUT\s0. You can reuse this, and can change the rendering style usedeach time; thereafter the coderef renders in the new style..PP\&\fBwalk_output\fR lets you change the print destination from \s-1STDOUT\s0 toanother open filehandle, or into a string passed as a ref (unlessyou've built perl with \-Uuseperlio)..PP.Vb 7\& my $walker = B::Concise::compile(\*(Aq\-terse\*(Aq,\*(AqaFuncName\*(Aq, \e&aSubRef); # 1\& walk_output(\emy $buf);\& $walker\->(); # 1 renders \-terse\& set_style_standard(\*(Aqconcise\*(Aq); # 2\& $walker\->(); # 2 renders \-concise\& $walker\->(@new); # 3 renders whatever\& print "3 different renderings: terse, concise, and @new: $buf\en";.Ve.PPWhen \f(CW$walker\fR is called, it traverses the subroutines supplied when itwas created, and renders them using the current style. You can changethe style afterwards in several different ways:.PP.Vb 3\& 1. call C<compile>, altering style or mode/order\& 2. call C<set_style_standard>\& 3. call $walker, passing @new options.Ve.PPPassing new options to the \f(CW$walker\fR is the easiest way to changeamongst any pre-defined styles (the ones you add are automaticallyrecognized as options), and is the only way to alter rendering orderwithout calling compile again. Note however that rendering state isstill shared amongst multiple \f(CW$walker\fR objects, so they must still beused in a coordinated manner..Sh "\fIB::Concise::reset_sequence()\fP".IX Subsection "B::Concise::reset_sequence()"This function (not exported) lets you reset the sequence numbers (notethat they're numbered arbitrarily, their goal being to be humanreadable). Its purpose is mostly to support testing, i.e. to comparethe concise output from two identical anonymous subroutines (butdifferent instances). Without the reset, B::Concise, seeing thatthey're separate optrees, generates different sequence numbers inthe output..Sh "Errors".IX Subsection "Errors"Errors in rendering (non-existent function-name, non-existent coderef)are written to the \s-1STDOUT\s0, or wherever you've set it via\&\fIwalk_output()\fR..PPErrors using the various *style* calls, and bad args to \fIwalk_output()\fR,result in \fIdie()\fR. Use an eval if you wish to catch these errors andcontinue processing..SH "AUTHOR".IX Header "AUTHOR"Stephen McCamant, <smcc@CSUA.Berkeley.EDU>.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -