| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "B::Xref 3perl" |
| 58 |
.TH B::Xref 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
B::Xref \- Generates cross reference reports for Perl programs |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
perl \-MO=Xref[,OPTIONS] foo.pl |
| 68 |
.SH DESCRIPTION |
| 69 |
.IX Header "DESCRIPTION" |
| 70 |
The B::Xref module is used to generate a cross reference listing of all |
| 71 |
definitions and uses of variables, subroutines and formats in a Perl program. |
| 72 |
It is implemented as a backend for the Perl compiler. |
| 73 |
.PP |
| 74 |
The report generated is in the following format: |
| 75 |
.PP |
| 76 |
.Vb 8 |
| 77 |
\& File filename1 |
| 78 |
\& Subroutine subname1 |
| 79 |
\& Package package1 |
| 80 |
\& object1 line numbers |
| 81 |
\& object2 line numbers |
| 82 |
\& ... |
| 83 |
\& Package package2 |
| 84 |
\& ... |
| 85 |
.Ve |
| 86 |
.PP |
| 87 |
Each \fBFile\fR section reports on a single file. Each \fBSubroutine\fR section |
| 88 |
reports on a single subroutine apart from the special cases |
| 89 |
"(definitions)" and "(main)". These report, respectively, on subroutine |
| 90 |
definitions found by the initial symbol table walk and on the main part of |
| 91 |
the program or module external to all subroutines. |
| 92 |
.PP |
| 93 |
The report is then grouped by the \fBPackage\fR of each variable, |
| 94 |
subroutine or format with the special case "(lexicals)" meaning |
| 95 |
lexical variables. Each \fBobject\fR name (implicitly qualified by its |
| 96 |
containing \fBPackage\fR) includes its type character(s) at the beginning |
| 97 |
where possible. Lexical variables are easier to track and even |
| 98 |
included dereferencing information where possible. |
| 99 |
.PP |
| 100 |
The \f(CW\*(C`line numbers\*(C'\fR are a comma separated list of line numbers (some |
| 101 |
preceded by code letters) where that object is used in some way. |
| 102 |
Simple uses aren't preceded by a code letter. Introductions (such as |
| 103 |
where a lexical is first defined with \f(CW\*(C`my\*(C'\fR) are indicated with the |
| 104 |
letter "i". Subroutine and method calls are indicated by the character |
| 105 |
"&". Subroutine definitions are indicated by "s" and format |
| 106 |
definitions by "f". |
| 107 |
.PP |
| 108 |
For instance, here's part of the report from the \fIpod2man\fR program that |
| 109 |
comes with Perl: |
| 110 |
.PP |
| 111 |
.Vb 12 |
| 112 |
\& Subroutine clear_noremap |
| 113 |
\& Package (lexical) |
| 114 |
\& $ready_to_print i1069, 1079 |
| 115 |
\& Package main |
| 116 |
\& $& 1086 |
| 117 |
\& $. 1086 |
| 118 |
\& $0 1086 |
| 119 |
\& $1 1087 |
| 120 |
\& $2 1085, 1085 |
| 121 |
\& $3 1085, 1085 |
| 122 |
\& $ARGV 1086 |
| 123 |
\& %HTML_Escapes 1085, 1085 |
| 124 |
.Ve |
| 125 |
.PP |
| 126 |
This shows the variables used in the subroutine \f(CW\*(C`clear_noremap\*(C'\fR. The |
| 127 |
variable \f(CW$ready_to_print\fR is a \fBmy()\fR (lexical) variable, |
| 128 |
\&\fBi\fRntroduced (first declared with \fBmy()\fR) on line 1069, and used on |
| 129 |
line 1079. The variable \f(CW$&\fR from the main package is used on 1086, |
| 130 |
and so on. |
| 131 |
.PP |
| 132 |
A line number may be prefixed by a single letter: |
| 133 |
.IP i 4 |
| 134 |
.IX Item "i" |
| 135 |
Lexical variable introduced (declared with \fBmy()\fR) for the first time. |
| 136 |
.IP & 4 |
| 137 |
Subroutine or method call. |
| 138 |
.IP s 4 |
| 139 |
.IX Item "s" |
| 140 |
Subroutine defined. |
| 141 |
.IP r 4 |
| 142 |
.IX Item "r" |
| 143 |
Format defined. |
| 144 |
.PP |
| 145 |
The most useful option the cross referencer has is to save the report |
| 146 |
to a separate file. For instance, to save the report on |
| 147 |
\&\fImyperlprogram\fR to the file \fIreport\fR: |
| 148 |
.PP |
| 149 |
.Vb 1 |
| 150 |
\& $ perl \-MO=Xref,\-oreport myperlprogram |
| 151 |
.Ve |
| 152 |
.SH OPTIONS |
| 153 |
.IX Header "OPTIONS" |
| 154 |
Option words are separated by commas (not whitespace) and follow the |
| 155 |
usual conventions of compiler backend options. |
| 156 |
.ie n .IP """\-oFILENAME""" 8 |
| 157 |
.el .IP \f(CW\-oFILENAME\fR 8 |
| 158 |
.IX Item "-oFILENAME" |
| 159 |
Directs output to \f(CW\*(C`FILENAME\*(C'\fR instead of standard output. |
| 160 |
.ie n .IP """\-r""" 8 |
| 161 |
.el .IP \f(CW\-r\fR 8 |
| 162 |
.IX Item "-r" |
| 163 |
Raw output. Instead of producing a human-readable report, outputs a line |
| 164 |
in machine-readable form for each definition/use of a variable/sub/format. |
| 165 |
.ie n .IP """\-d""" 8 |
| 166 |
.el .IP \f(CW\-d\fR 8 |
| 167 |
.IX Item "-d" |
| 168 |
Don't output the "(definitions)" sections. |
| 169 |
.ie n .IP """\-D[tO]""" 8 |
| 170 |
.el .IP \f(CW\-D[tO]\fR 8 |
| 171 |
.IX Item "-D[tO]" |
| 172 |
(Internal) debug options, probably only useful if \f(CW\*(C`\-r\*(C'\fR included. |
| 173 |
The \f(CW\*(C`t\*(C'\fR option prints the object on the top of the stack as it's |
| 174 |
being tracked. The \f(CW\*(C`O\*(C'\fR option prints each operator as it's being |
| 175 |
processed in the execution order of the program. |
| 176 |
.SH BUGS |
| 177 |
.IX Header "BUGS" |
| 178 |
Non-lexical variables are quite difficult to track through a program. |
| 179 |
Sometimes the type of a non-lexical variable's use is impossible to |
| 180 |
determine. Introductions of non-lexical non-scalars don't seem to be |
| 181 |
reported properly. |
| 182 |
.SH AUTHOR |
| 183 |
.IX Header "AUTHOR" |
| 184 |
Malcolm Beattie, [email protected]. |