1Doc(3) User Contributed Perl Documentation Doc(3)
2
3
4
6 PDL::Doc - support for PDL online documentation
7
9 use PDL::Doc;
10 $onlinedc = new PDL::Doc ($docfile);
11 @match = $onlinedc->search('m/slice|clump/');
12
14 An implementation of online docs for PDL.
15
17 For a package like PDL that has a lot of functions it is very desirable
18 to have some form of online help to make it easy for the user to remind
19 himself of names, calling conventions and typical usage of the
20 multitude of functions at his disposal. To make it straightforward to
21 extract the relevant information from the POD documentation in source
22 files that make up the PDL distribution certain conventions have been
23 adopted in formatting this documentation.
24
25 The first convention says that all documentation for PDL functions
26 appears in the POD section introduced by
27
28 =head1 FUNCTIONS
29
30 Individual functions in this section are introduced by
31
32 =head2 funcname
33
34 where signature is the argumentlist for a PP defined function as
35 explained in PDL::PP. Generally, PDL documentation is in valid POD
36 format (see "perlpod") but uses the "=for" directive in a special way.
37 The "=for" directive is used to flag to the PDL Pod parser that
38 information is following that will be used to generate online help.
39
40 The PDL podparser is derived from the PDL::Pod::Parser class that had
41 to be patched in a few places, partly to fix minor bugs, partly to
42 enhance functionality for perusal by PDL::Doc. Since the PDL::Doc
43 module is still experimental the patched Pod-Parser distribution is
44 included with the current PDL-Doc distribution. Note that PDL::Doc will
45 not work correctly with the released Pod-Parser distribution.
46
47 The PDL Pod parser recognises the following "=for" directives:
48
49 Ref indicates that the one line reference for this function follows,
50 e.g.,
51
52 =for ref
53
54 Returns a piddle of lags to parent.
55
56 Sig the signature for the current function follows, e.g.,
57
58 =for sig
59
60 Signature: (a(n), [o]b(), [t]tmp(n))
61
62 Usage
63 an indication of the possible calling conventions for the current
64 function, e.g.,
65
66 =for usage
67
68 wpic($pdl,$filename[,{ options... }])
69
70 Opt lists options for the current function, e.g.,
71
72 =for options
73
74 CONVERTER => 'ppmtogif', # explicitly specify pbm converter
75 FLAGS => '-interlaced -transparent 0', # flags for converter
76 IFORM => 'PGM', # explicitly specify intermediate format
77 XTRAFLAGS => '-imagename iris', # additional flags to defaultflags
78 FORMAT => 'PCX', # explicitly specify output image format
79 COLOR => 'bw', # specify color conversion
80 LUT => $lut, # use color table information
81
82 Example
83 gives examples of typical usage for the current function:
84
85 =for example
86
87 wpic $pdl, $file;
88 $im->wpic('web.gif',{LUT => $lut});
89 for (@images) {
90 $_->wpic($name[0],{CONVERTER => 'ppmtogif'})
91 }
92
93 Bad provides information on how the function handles bad values (if
94 $PDL:Config{WITH_BADVAL} is set to 1). The intention is to have
95 this information automatically created for pp-compiled functions,
96 although it can be over-ridden.
97
98 The PDL podparser is implemented as a simple state machine. Any of the
99 above "=for" statements switches the podparser into a state where the
100 following paragraph is accepted as information for the respective field
101 ("Ref", "Usage", "Opt", "Example" or "Bad"). Only the text up to the
102 end of the current paragraph is accepted, for example:
103
104 =for example
105
106 ($x,$y) = $a->func(1,3); # this is part of the accepted info
107 $x = func($a,0,1); # this as well
108
109 $x = func($a,$b); # but this isn't
110
111 To make the resulting pod documentation also easily digestible for the
112 existing pod filters (pod2man, pod2text, pod2html, etc) the actual
113 textblock of information must be separated from the "=for" directive by
114 at least one blank line. Otherwise, the textblock will be lost in the
115 translation process when the "normal" podformatters are used. The
116 general idea behind this format is that it should be easy to extract
117 the information for online documentation, automatic generation of a
118 reference card, etc but at the same time the documentation should be
119 translated by the standard podformatters without loss of contents (and
120 without requiring any changes in the existing POD format).
121
122 The preceding explanations should be further explained by the following
123 example (extracted from PDL/IO/Misc/misc.pd):
124
125 =head2 rcols()
126
127 =for ref
128
129 Read ASCII whitespaced cols from file into piddles efficiently.
130
131 If no columns are specified all are assumed
132 Will optionally only process lines matching a pattern.
133 Can take file name or *HANDLE.
134
135 =for usage
136
137 Usage: ($x,$y,...) = rcols(*HANDLE|"filename", ["/pattern/",$col1, $col2,] ...)
138
139 e.g.,
140
141 =for example
142
143 ($x,$y) = rcols 'file1'
144 ($x,$y,$z) = rcols 'file2', "/foo/",3,4
145 $x = PDL->rcols 'file1';
146
147 Note: currently quotes are required on the pattern.
148
149 which is translated by, e.g, the standard "pod2text" converter into:
150
151 rcols()
152
153 Read ASCII whitespaced cols from file into piddles efficiently.
154
155 If no columns are specified all are assumed Will optionally only
156 process lines matching a pattern. Can take file name or *HANDLE.
157
158 Usage: ($x,$y,...) = rcols(*HANDLE|"filename", ["/pattern/",$col1, $col2,] ...)
159
160 e.g.,
161
162 ($x,$y) = rcols 'file1'
163 ($x,$y,$z) = rcols 'file2', "/foo/",3,4
164 $x = PDL->rcols 'file1';
165
166 Note: currently quotes are required on the pattern.
167
168 It should be clear from the preceding example that readable output can
169 be obtained from this format using the standard converters and the
170 reader will hopefully get a feeling how he can easily intersperse the
171 special "=for" directives with the normal POD documentation.
172
173 Which directives should be contained in the documentation
174 The module documentation should start with the
175
176 =head1 NAME
177
178 PDL::Modulename -- do something with piddles
179
180 section (as anyway required by "pod2man") since the PDL podparser
181 extracts the name of the module this function belongs to from that
182 section.
183
184 Each function that is not only for internal use by the module should be
185 documented, introduced with the "=head2" directive in the "=head1
186 FUNCTIONS" section. The only field that every function documented along
187 these lines should have is the Ref field preceding a one line
188 description of its intended functionality (suitable for inclusion in a
189 concise reference card). PP defined functions (see PDL::PP) should have
190 a Sig field stating their signature. To facilitate maintainance of this
191 documentation for such functions the 'Doc' field has been introduced
192 into the definition of "pp_def" (see again PDL::PP) which will take
193 care that name and signature of the so defined function are documented
194 in this way (for examples of this usage see, for example, the
195 PDL::Slices module, especially slices.pd and the resulting Slices.pm).
196 Similarly, the 'BadDoc' field provides a means of specifying
197 information on how the routine handles the presence of bad values: this
198 will be autpmatically created if "BadDoc" is not supplied, or set to
199 "undef".
200
201 Furthermore, the documentation for each function should contain at
202 least one of the Usage or Examples fields. Depending on the calling
203 conventions for the function under consideration presence of both
204 fields may be warranted.
205
206 If a function has options that should be given as a hash reference in
207 the form
208
209 {Option => Value, ...}
210
211 then the possible options (and aproppriate values) should be explained
212 in the textblock following the "=for Opt" directive (see example above
213 and, e.g., PDL::IO::Pic).
214
215 It is well possible that some of these conventions appear to be clumsy
216 at times and the author is keen to hear of any suggestions for better
217 alternatives.
218
220 new
221 $onlinedc = new PDL::Doc ('file.pdl',[more files]);
222
223 addfiles
224 add another file to the online database associated with this object.
225
226 outfile
227 set the name of the output file for this online db
228
229 ensuredb
230 Make sure that the database is slurped in
231
232 savedb
233 save the database (i.e., the hash of PDL symbols) to the file
234 associated with this object.
235
236 gethash
237 Return the PDL symhash (e.g. for custom search operations)
238
239 search
240 Search a PDL symhash
241
242 $onldc->search($regex, $fields [, $sort])
243
244 Searching is by default case insensitive. Other flags can be given by
245 specifying the regexp in the form "m/regex/ismx" where "/" can be
246 replaced with any other non-alphanumeric character. $fields is an array
247 reference for all hash fields that should be matched against the regex.
248 Valid fields are
249
250 Name, # name of the function
251 Module, # module the function belongs to
252 Ref, # the one-line reference description
253 Example, # the example for this function
254 Opt, # options
255 File, # the path to the source file this docs have been extracted from
256
257 scan
258 Scan a source file using the PDL podparser to extract information for
259 online documentation
260
261 scantree
262 Scan whole directory trees for online documentation in ".pm" (module
263 definition) and "*.pod" (general documentation) files (using the
264 File::Find module).
265
266 funcdocs
267 extract the complete documentation about a function from its
268 source file using the PDL::Pod::Parser filter.
269
272 Quite a few shortcomings which will hopefully be fixed following
273 discussions on the pdl-porters mailing list.
274
276 Copyright 1997 Christian Soeller <c.soeller@auckland.ac.nz> and Karl
277 Glazebrook <kgb@aaoepp.aao.gov.au> All rights reserved. There is no
278 warranty. You are allowed to redistribute this software / documentation
279 under certain conditions. For details, see the file COPYING in the PDL
280 distribution. If this file is separated from the PDL distribution, the
281 copyright notice should be included in the file.
282
283
284
285perl v5.12.3 2009-11-07 Doc(3)