Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
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 "IO::Handle 3" | |
132 | .TH IO::Handle 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | IO::Handle \- supply object methods for I/O handles | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | .Vb 1 | |
138 | \& use IO::Handle; | |
139 | .Ve | |
140 | .PP | |
141 | .Vb 5 | |
142 | \& $io = new IO::Handle; | |
143 | \& if ($io->fdopen(fileno(STDIN),"r")) { | |
144 | \& print $io->getline; | |
145 | \& $io->close; | |
146 | \& } | |
147 | .Ve | |
148 | .PP | |
149 | .Vb 4 | |
150 | \& $io = new IO::Handle; | |
151 | \& if ($io->fdopen(fileno(STDOUT),"w")) { | |
152 | \& $io->print("Some text\en"); | |
153 | \& } | |
154 | .Ve | |
155 | .PP | |
156 | .Vb 2 | |
157 | \& use IO::Handle '_IOLBF'; | |
158 | \& $io->setvbuf($buffer_var, _IOLBF, 1024); | |
159 | .Ve | |
160 | .PP | |
161 | .Vb 1 | |
162 | \& undef $io; # automatically closes the file if it's open | |
163 | .Ve | |
164 | .PP | |
165 | .Vb 1 | |
166 | \& autoflush STDOUT 1; | |
167 | .Ve | |
168 | .SH "DESCRIPTION" | |
169 | .IX Header "DESCRIPTION" | |
170 | \&\f(CW\*(C`IO::Handle\*(C'\fR is the base class for all other \s-1IO\s0 handle classes. It is | |
171 | not intended that objects of \f(CW\*(C`IO::Handle\*(C'\fR would be created directly, | |
172 | but instead \f(CW\*(C`IO::Handle\*(C'\fR is inherited from by several other classes | |
173 | in the \s-1IO\s0 hierarchy. | |
174 | .PP | |
175 | If you are reading this documentation, looking for a replacement for | |
176 | the \f(CW\*(C`FileHandle\*(C'\fR package, then I suggest you read the documentation | |
177 | for \f(CW\*(C`IO::File\*(C'\fR too. | |
178 | .SH "CONSTRUCTOR" | |
179 | .IX Header "CONSTRUCTOR" | |
180 | .IP "new ()" 4 | |
181 | .IX Item "new ()" | |
182 | Creates a new \f(CW\*(C`IO::Handle\*(C'\fR object. | |
183 | .IP "new_from_fd ( \s-1FD\s0, \s-1MODE\s0 )" 4 | |
184 | .IX Item "new_from_fd ( FD, MODE )" | |
185 | Creates an \f(CW\*(C`IO::Handle\*(C'\fR like \f(CW\*(C`new\*(C'\fR does. | |
186 | It requires two parameters, which are passed to the method \f(CW\*(C`fdopen\*(C'\fR; | |
187 | if the fdopen fails, the object is destroyed. Otherwise, it is returned | |
188 | to the caller. | |
189 | .SH "METHODS" | |
190 | .IX Header "METHODS" | |
191 | See perlfunc for complete descriptions of each of the following | |
192 | supported \f(CW\*(C`IO::Handle\*(C'\fR methods, which are just front ends for the | |
193 | corresponding built-in functions: | |
194 | .PP | |
195 | .Vb 12 | |
196 | \& $io->close | |
197 | \& $io->eof | |
198 | \& $io->fileno | |
199 | \& $io->format_write( [FORMAT_NAME] ) | |
200 | \& $io->getc | |
201 | \& $io->read ( BUF, LEN, [OFFSET] ) | |
202 | \& $io->print ( ARGS ) | |
203 | \& $io->printf ( FMT, [ARGS] ) | |
204 | \& $io->stat | |
205 | \& $io->sysread ( BUF, LEN, [OFFSET] ) | |
206 | \& $io->syswrite ( BUF, [LEN, [OFFSET]] ) | |
207 | \& $io->truncate ( LEN ) | |
208 | .Ve | |
209 | .PP | |
210 | See perlvar for complete descriptions of each of the following | |
211 | supported \f(CW\*(C`IO::Handle\*(C'\fR methods. All of them return the previous | |
212 | value of the attribute and takes an optional single argument that when | |
213 | given will set the value. If no argument is given the previous value | |
214 | is unchanged (except for \f(CW$io\fR\->autoflush will actually turn \s-1ON\s0 | |
215 | autoflush by default). | |
216 | .PP | |
217 | .Vb 7 | |
218 | \& $io->autoflush ( [BOOL] ) $| | |
219 | \& $io->format_page_number( [NUM] ) $% | |
220 | \& $io->format_lines_per_page( [NUM] ) $= | |
221 | \& $io->format_lines_left( [NUM] ) $- | |
222 | \& $io->format_name( [STR] ) $~ | |
223 | \& $io->format_top_name( [STR] ) $^ | |
224 | \& $io->input_line_number( [NUM]) $. | |
225 | .Ve | |
226 | .PP | |
227 | The following methods are not supported on a per-filehandle basis. | |
228 | .PP | |
229 | .Vb 4 | |
230 | \& IO::Handle->format_line_break_characters( [STR] ) $: | |
231 | \& IO::Handle->format_formfeed( [STR]) $^L | |
232 | \& IO::Handle->output_field_separator( [STR] ) $, | |
233 | \& IO::Handle->output_record_separator( [STR] ) $\e | |
234 | .Ve | |
235 | .PP | |
236 | .Vb 1 | |
237 | \& IO::Handle->input_record_separator( [STR] ) $/ | |
238 | .Ve | |
239 | .PP | |
240 | Furthermore, for doing normal I/O you might need these: | |
241 | .IP "$io\->fdopen ( \s-1FD\s0, \s-1MODE\s0 )" 4 | |
242 | .IX Item "$io->fdopen ( FD, MODE )" | |
243 | \&\f(CW\*(C`fdopen\*(C'\fR is like an ordinary \f(CW\*(C`open\*(C'\fR except that its first parameter | |
244 | is not a filename but rather a file handle name, an IO::Handle object, | |
245 | or a file descriptor number. | |
246 | .IP "$io\->opened" 4 | |
247 | .IX Item "$io->opened" | |
248 | Returns true if the object is currently a valid file descriptor, false | |
249 | otherwise. | |
250 | .IP "$io\->getline" 4 | |
251 | .IX Item "$io->getline" | |
252 | This works like <$io> described in \*(L"I/O Operators\*(R" in perlop | |
253 | except that it's more readable and can be safely called in a | |
254 | list context but still returns just one line. | |
255 | .IP "$io\->getlines" 4 | |
256 | .IX Item "$io->getlines" | |
257 | This works like <$io> when called in a list context to read all | |
258 | the remaining lines in a file, except that it's more readable. | |
259 | It will also \fIcroak()\fR if accidentally called in a scalar context. | |
260 | .IP "$io\->ungetc ( \s-1ORD\s0 )" 4 | |
261 | .IX Item "$io->ungetc ( ORD )" | |
262 | Pushes a character with the given ordinal value back onto the given | |
263 | handle's input stream. Only one character of pushback per handle is | |
264 | guaranteed. | |
265 | .IP "$io\->write ( \s-1BUF\s0, \s-1LEN\s0 [, \s-1OFFSET\s0 ] )" 4 | |
266 | .IX Item "$io->write ( BUF, LEN [, OFFSET ] )" | |
267 | This \f(CW\*(C`write\*(C'\fR is like \f(CW\*(C`write\*(C'\fR found in C, that is it is the | |
268 | opposite of read. The wrapper for the perl \f(CW\*(C`write\*(C'\fR function is | |
269 | called \f(CW\*(C`format_write\*(C'\fR. | |
270 | .IP "$io\->error" 4 | |
271 | .IX Item "$io->error" | |
272 | Returns a true value if the given handle has experienced any errors | |
273 | since it was opened or since the last call to \f(CW\*(C`clearerr\*(C'\fR, or if the | |
274 | handle is invalid. It only returns false for a valid handle with no | |
275 | outstanding errors. | |
276 | .IP "$io\->clearerr" 4 | |
277 | .IX Item "$io->clearerr" | |
278 | Clear the given handle's error indicator. Returns \-1 if the handle is | |
279 | invalid, 0 otherwise. | |
280 | .IP "$io\->sync" 4 | |
281 | .IX Item "$io->sync" | |
282 | \&\f(CW\*(C`sync\*(C'\fR synchronizes a file's in-memory state with that on the | |
283 | physical medium. \f(CW\*(C`sync\*(C'\fR does not operate at the perlio api level, but | |
284 | operates on the file descriptor (similar to sysread, sysseek and | |
285 | systell). This means that any data held at the perlio api level will not | |
286 | be synchronized. To synchronize data that is buffered at the perlio api | |
287 | level you must use the flush method. \f(CW\*(C`sync\*(C'\fR is not implemented on all | |
288 | platforms. Returns \*(L"0 but true\*(R" on success, \f(CW\*(C`undef\*(C'\fR on error, \f(CW\*(C`undef\*(C'\fR | |
289 | for an invalid handle. See \fIfsync\fR\|(3c). | |
290 | .IP "$io\->flush" 4 | |
291 | .IX Item "$io->flush" | |
292 | \&\f(CW\*(C`flush\*(C'\fR causes perl to flush any buffered data at the perlio api level. | |
293 | Any unread data in the buffer will be discarded, and any unwritten data | |
294 | will be written to the underlying file descriptor. Returns \*(L"0 but true\*(R" | |
295 | on success, \f(CW\*(C`undef\*(C'\fR on error. | |
296 | .IP "$io\->printflush ( \s-1ARGS\s0 )" 4 | |
297 | .IX Item "$io->printflush ( ARGS )" | |
298 | Turns on autoflush, print \s-1ARGS\s0 and then restores the autoflush status of the | |
299 | \&\f(CW\*(C`IO::Handle\*(C'\fR object. Returns the return value from print. | |
300 | .IP "$io\->blocking ( [ \s-1BOOL\s0 ] )" 4 | |
301 | .IX Item "$io->blocking ( [ BOOL ] )" | |
302 | If called with an argument \f(CW\*(C`blocking\*(C'\fR will turn on non-blocking \s-1IO\s0 if | |
303 | \&\f(CW\*(C`BOOL\*(C'\fR is false, and turn it off if \f(CW\*(C`BOOL\*(C'\fR is true. | |
304 | .Sp | |
305 | \&\f(CW\*(C`blocking\*(C'\fR will return the value of the previous setting, or the | |
306 | current setting if \f(CW\*(C`BOOL\*(C'\fR is not given. | |
307 | .Sp | |
308 | If an error occurs \f(CW\*(C`blocking\*(C'\fR will return undef and \f(CW$!\fR will be set. | |
309 | .PP | |
310 | If the C functions \fIsetbuf()\fR and/or \fIsetvbuf()\fR are available, then | |
311 | \&\f(CW\*(C`IO::Handle::setbuf\*(C'\fR and \f(CW\*(C`IO::Handle::setvbuf\*(C'\fR set the buffering | |
312 | policy for an IO::Handle. The calling sequences for the Perl functions | |
313 | are the same as their C counterparts\*(--including the constants \f(CW\*(C`_IOFBF\*(C'\fR, | |
314 | \&\f(CW\*(C`_IOLBF\*(C'\fR, and \f(CW\*(C`_IONBF\*(C'\fR for \fIsetvbuf()\fR\-\-except that the buffer parameter | |
315 | specifies a scalar variable to use as a buffer. You should only | |
316 | change the buffer before any I/O, or immediately after calling flush. | |
317 | .PP | |
318 | \&\s-1WARNING:\s0 A variable used as a buffer by \f(CW\*(C`setbuf\*(C'\fR or \f(CW\*(C`setvbuf\*(C'\fR \fBmust not | |
319 | be modified\fR in any way until the IO::Handle is closed or \f(CW\*(C`setbuf\*(C'\fR or | |
320 | \&\f(CW\*(C`setvbuf\*(C'\fR is called again, or memory corruption may result! Remember that | |
321 | the order of global destruction is undefined, so even if your buffer | |
322 | variable remains in scope until program termination, it may be undefined | |
323 | before the file IO::Handle is closed. Note that you need to import the | |
324 | constants \f(CW\*(C`_IOFBF\*(C'\fR, \f(CW\*(C`_IOLBF\*(C'\fR, and \f(CW\*(C`_IONBF\*(C'\fR explicitly. Like C, setbuf | |
325 | returns nothing. setvbuf returns \*(L"0 but true\*(R", on success, \f(CW\*(C`undef\*(C'\fR on | |
326 | failure. | |
327 | .PP | |
328 | Lastly, there is a special method for working under \fB\-T\fR and setuid/gid | |
329 | scripts: | |
330 | .IP "$io\->untaint" 4 | |
331 | .IX Item "$io->untaint" | |
332 | Marks the object as taint\-clean, and as such data read from it will also | |
333 | be considered taint\-clean. Note that this is a very trusting action to | |
334 | take, and appropriate consideration for the data source and potential | |
335 | vulnerability should be kept in mind. Returns 0 on success, \-1 if setting | |
336 | the taint-clean flag failed. (eg invalid handle) | |
337 | .SH "NOTE" | |
338 | .IX Header "NOTE" | |
339 | An \f(CW\*(C`IO::Handle\*(C'\fR object is a reference to a symbol/GLOB reference (see | |
340 | the \f(CW\*(C`Symbol\*(C'\fR package). Some modules that | |
341 | inherit from \f(CW\*(C`IO::Handle\*(C'\fR may want to keep object related variables | |
342 | in the hash table part of the \s-1GLOB\s0. In an attempt to prevent modules | |
343 | trampling on each other I propose the that any such module should prefix | |
344 | its variables with its own name separated by _'s. For example the IO::Socket | |
345 | module keeps a \f(CW\*(C`timeout\*(C'\fR variable in 'io_socket_timeout'. | |
346 | .SH "SEE ALSO" | |
347 | .IX Header "SEE ALSO" | |
348 | perlfunc, | |
349 | \&\*(L"I/O Operators\*(R" in perlop, | |
350 | IO::File | |
351 | .SH "BUGS" | |
352 | .IX Header "BUGS" | |
353 | Due to backwards compatibility, all filehandles resemble objects | |
354 | of class \f(CW\*(C`IO::Handle\*(C'\fR, or actually classes derived from that class. | |
355 | They actually aren't. Which means you can't derive your own | |
356 | class from \f(CW\*(C`IO::Handle\*(C'\fR and inherit those methods. | |
357 | .SH "HISTORY" | |
358 | .IX Header "HISTORY" | |
359 | Derived from FileHandle.pm by Graham Barr <\fIgbarr@pobox.com\fR> |