Commit | Line | Data |
774d564b |
1 | |
8add82fc |
2 | package IO::Handle; |
3 | |
4 | =head1 NAME |
5 | |
27d4819a |
6 | IO::Handle - supply object methods for I/O handles |
8add82fc |
7 | |
8 | =head1 SYNOPSIS |
9 | |
10 | use IO::Handle; |
11 | |
cf7fe8a2 |
12 | $io = new IO::Handle; |
13 | if ($io->fdopen(fileno(STDIN),"r")) { |
14 | print $io->getline; |
15 | $io->close; |
8add82fc |
16 | } |
17 | |
cf7fe8a2 |
18 | $io = new IO::Handle; |
19 | if ($io->fdopen(fileno(STDOUT),"w")) { |
20 | $io->print("Some text\n"); |
8add82fc |
21 | } |
22 | |
3370baa8 |
23 | use IO::Handle '_IOLBF'; |
cf7fe8a2 |
24 | $io->setvbuf($buffer_var, _IOLBF, 1024); |
8add82fc |
25 | |
cf7fe8a2 |
26 | undef $io; # automatically closes the file if it's open |
774d564b |
27 | |
8add82fc |
28 | autoflush STDOUT 1; |
29 | |
30 | =head1 DESCRIPTION |
31 | |
774d564b |
32 | C<IO::Handle> is the base class for all other IO handle classes. It is |
33 | not intended that objects of C<IO::Handle> would be created directly, |
34 | but instead C<IO::Handle> is inherited from by several other classes |
35 | in the IO hierarchy. |
36 | |
37 | If you are reading this documentation, looking for a replacement for |
38 | the C<FileHandle> package, then I suggest you read the documentation |
cf7fe8a2 |
39 | for C<IO::File> too. |
8add82fc |
40 | |
27d4819a |
41 | =head1 CONSTRUCTOR |
42 | |
43 | =over 4 |
44 | |
45 | =item new () |
8add82fc |
46 | |
27d4819a |
47 | Creates a new C<IO::Handle> object. |
8add82fc |
48 | |
27d4819a |
49 | =item new_from_fd ( FD, MODE ) |
50 | |
51 | Creates a C<IO::Handle> like C<new> does. |
52 | It requires two parameters, which are passed to the method C<fdopen>; |
53 | if the fdopen fails, the object is destroyed. Otherwise, it is returned |
54 | to the caller. |
55 | |
56 | =back |
57 | |
58 | =head1 METHODS |
8add82fc |
59 | |
8add82fc |
60 | See L<perlfunc> for complete descriptions of each of the following |
61 | supported C<IO::Handle> methods, which are just front ends for the |
62 | corresponding built-in functions: |
a6006777 |
63 | |
cf7fe8a2 |
64 | $io->close |
65 | $io->eof |
66 | $io->fileno |
67 | $io->format_write( [FORMAT_NAME] ) |
68 | $io->getc |
69 | $io->read ( BUF, LEN, [OFFSET] ) |
70 | $io->print ( ARGS ) |
71 | $io->printf ( FMT, [ARGS] ) |
72 | $io->stat |
73 | $io->sysread ( BUF, LEN, [OFFSET] ) |
74 | $io->syswrite ( BUF, LEN, [OFFSET] ) |
75 | $io->truncate ( LEN ) |
8add82fc |
76 | |
77 | See L<perlvar> for complete descriptions of each of the following |
cf7fe8a2 |
78 | supported C<IO::Handle> methods. All of them return the previous |
79 | value of the attribute and takes an optional single argument that when |
80 | given will set the value. If no argument is given the previous value |
81 | is unchanged (except for $io->autoflush will actually turn ON |
82 | autoflush by default). |
8add82fc |
83 | |
cf7fe8a2 |
84 | $io->autoflush ( [BOOL] ) $| |
85 | $io->format_page_number( [NUM] ) $% |
86 | $io->format_lines_per_page( [NUM] ) $= |
87 | $io->format_lines_left( [NUM] ) $- |
88 | $io->format_name( [STR] ) $~ |
89 | $io->format_top_name( [STR] ) $^ |
90 | $io->input_line_number( [NUM]) $. |
91 | |
92 | The following methods are not supported on a per-filehandle basis. |
93 | |
94 | IO::Handle->format_line_break_characters( [STR] ) $: |
95 | IO::Handle->format_formfeed( [STR]) $^L |
96 | IO::Handle->output_field_separator( [STR] ) $, |
97 | IO::Handle->output_record_separator( [STR] ) $\ |
98 | |
99 | IO::Handle->input_record_separator( [STR] ) $/ |
8add82fc |
100 | |
101 | Furthermore, for doing normal I/O you might need these: |
102 | |
103 | =over |
104 | |
cf7fe8a2 |
105 | =item $io->fdopen ( FD, MODE ) |
948ecc40 |
106 | |
107 | C<fdopen> is like an ordinary C<open> except that its first parameter |
108 | is not a filename but rather a file handle name, a IO::Handle object, |
109 | or a file descriptor number. |
110 | |
cf7fe8a2 |
111 | =item $io->opened |
948ecc40 |
112 | |
113 | Returns true if the object is currently a valid file descriptor. |
114 | |
cf7fe8a2 |
115 | =item $io->getline |
8add82fc |
116 | |
cf7fe8a2 |
117 | This works like <$io> described in L<perlop/"I/O Operators"> |
8add82fc |
118 | except that it's more readable and can be safely called in an |
119 | array context but still returns just one line. |
120 | |
cf7fe8a2 |
121 | =item $io->getlines |
8add82fc |
122 | |
cf7fe8a2 |
123 | This works like <$io> when called in an array context to |
8add82fc |
124 | read all the remaining lines in a file, except that it's more readable. |
125 | It will also croak() if accidentally called in a scalar context. |
126 | |
cf7fe8a2 |
127 | =item $io->ungetc ( ORD ) |
27d4819a |
128 | |
948ecc40 |
129 | Pushes a character with the given ordinal value back onto the given |
cf7fe8a2 |
130 | handle's input stream. Only one character of pushback per handle is |
131 | guaranteed. |
27d4819a |
132 | |
cf7fe8a2 |
133 | =item $io->write ( BUF, LEN [, OFFSET ] ) |
27d4819a |
134 | |
948ecc40 |
135 | This C<write> is like C<write> found in C, that is it is the |
27d4819a |
136 | opposite of read. The wrapper for the perl C<write> function is |
137 | called C<format_write>. |
138 | |
cf7fe8a2 |
139 | =item $io->error |
948ecc40 |
140 | |
141 | Returns a true value if the given handle has experienced any errors |
142 | since it was opened or since the last call to C<clearerr>. |
143 | |
cf7fe8a2 |
144 | =item $io->clearerr |
948ecc40 |
145 | |
146 | Clear the given handle's error indicator. |
27d4819a |
147 | |
cf7fe8a2 |
148 | =item $io->sync |
149 | |
150 | C<sync> synchronizes a file's in-memory state with that on the |
151 | physical medium. C<sync> does not operate at the perlio api level, but |
152 | operates on the file descriptor, this means that any data held at the |
153 | perlio api level will not be synchronized. To synchronize data that is |
154 | buffered at the perlio api level you must use the flush method. C<sync> |
155 | is not implemented on all platforms. See L<fsync(3c)>. |
156 | |
157 | =item $io->flush |
158 | |
159 | C<flush> causes perl to flush any buffered data at the perlio api level. |
160 | Any unread data in the buffer will be discarded, and any unwritten data |
161 | will be written to the underlying file descriptor. |
162 | |
163 | =item $io->printflush ( ARGS ) |
164 | |
165 | Turns on autoflush, print ARGS and then restores the autoflush status of the |
166 | C<IO::Handle> object. |
167 | |
168 | =item $io->blocking ( [ BOOL ] ) |
169 | |
170 | If called with an argument C<blocking> will turn on non-blocking IO if |
171 | C<BOOL> is false, and turn it off if C<BOOL> is true. |
172 | |
173 | C<blocking> will return the value of the previous setting, or the |
174 | current setting if C<BOOL> is not given. |
175 | |
176 | If an error occurs C<blocking> will return undef and C<$!> will be set. |
177 | |
8add82fc |
178 | =back |
179 | |
cf7fe8a2 |
180 | |
948ecc40 |
181 | If the C functions setbuf() and/or setvbuf() are available, then |
182 | C<IO::Handle::setbuf> and C<IO::Handle::setvbuf> set the buffering |
183 | policy for an IO::Handle. The calling sequences for the Perl functions |
184 | are the same as their C counterparts--including the constants C<_IOFBF>, |
185 | C<_IOLBF>, and C<_IONBF> for setvbuf()--except that the buffer parameter |
186 | specifies a scalar variable to use as a buffer. WARNING: A variable |
187 | used as a buffer by C<setbuf> or C<setvbuf> must not be modified in any |
188 | way until the IO::Handle is closed or C<setbuf> or C<setvbuf> is called |
cf7fe8a2 |
189 | again, or memory corruption may result! Note that you need to import |
3370baa8 |
190 | the constants C<_IOFBF>, C<_IOLBF>, and C<_IONBF> explicitly. |
948ecc40 |
191 | |
192 | Lastly, there is a special method for working under B<-T> and setuid/gid |
193 | scripts: |
515e7bd7 |
194 | |
195 | =over |
196 | |
cf7fe8a2 |
197 | =item $io->untaint |
515e7bd7 |
198 | |
199 | Marks the object as taint-clean, and as such data read from it will also |
200 | be considered taint-clean. Note that this is a very trusting action to |
201 | take, and appropriate consideration for the data source and potential |
202 | vulnerability should be kept in mind. |
203 | |
204 | =back |
205 | |
27d4819a |
206 | =head1 NOTE |
8add82fc |
207 | |
cf7fe8a2 |
208 | A C<IO::Handle> object is a reference to a symbol/GLOB reference (see |
209 | the C<Symbol> package). Some modules that |
8add82fc |
210 | inherit from C<IO::Handle> may want to keep object related variables |
211 | in the hash table part of the GLOB. In an attempt to prevent modules |
212 | trampling on each other I propose the that any such module should prefix |
213 | its variables with its own name separated by _'s. For example the IO::Socket |
214 | module keeps a C<timeout> variable in 'io_socket_timeout'. |
215 | |
216 | =head1 SEE ALSO |
217 | |
218 | L<perlfunc>, |
219 | L<perlop/"I/O Operators">, |
774d564b |
220 | L<IO::File> |
8add82fc |
221 | |
222 | =head1 BUGS |
223 | |
224 | Due to backwards compatibility, all filehandles resemble objects |
225 | of class C<IO::Handle>, or actually classes derived from that class. |
226 | They actually aren't. Which means you can't derive your own |
227 | class from C<IO::Handle> and inherit those methods. |
228 | |
229 | =head1 HISTORY |
230 | |
cf7fe8a2 |
231 | Derived from FileHandle.pm by Graham Barr E<lt>F<gbarr@pobox.com>E<gt> |
8add82fc |
232 | |
233 | =cut |
234 | |
17f410f9 |
235 | require 5.005_64; |
7a4c00b4 |
236 | use strict; |
17f410f9 |
237 | our($VERSION, @EXPORT_OK, @ISA); |
8add82fc |
238 | use Carp; |
239 | use Symbol; |
240 | use SelectSaver; |
cf7fe8a2 |
241 | use IO (); # Load the XS module |
8add82fc |
242 | |
243 | require Exporter; |
244 | @ISA = qw(Exporter); |
245 | |
cf7fe8a2 |
246 | $VERSION = "1.21"; |
8add82fc |
247 | |
248 | @EXPORT_OK = qw( |
249 | autoflush |
250 | output_field_separator |
251 | output_record_separator |
252 | input_record_separator |
253 | input_line_number |
254 | format_page_number |
255 | format_lines_per_page |
256 | format_lines_left |
257 | format_name |
258 | format_top_name |
259 | format_line_break_characters |
260 | format_formfeed |
261 | format_write |
262 | |
263 | print |
264 | printf |
265 | getline |
266 | getlines |
267 | |
cf7fe8a2 |
268 | printflush |
269 | flush |
270 | |
8add82fc |
271 | SEEK_SET |
272 | SEEK_CUR |
273 | SEEK_END |
274 | _IOFBF |
275 | _IOLBF |
276 | _IONBF |
8add82fc |
277 | ); |
278 | |
8add82fc |
279 | ################################################ |
280 | ## Constructors, destructors. |
281 | ## |
282 | |
283 | sub new { |
27d4819a |
284 | my $class = ref($_[0]) || $_[0] || "IO::Handle"; |
285 | @_ == 1 or croak "usage: new $class"; |
cf7fe8a2 |
286 | my $io = gensym; |
287 | bless $io, $class; |
8add82fc |
288 | } |
289 | |
290 | sub new_from_fd { |
27d4819a |
291 | my $class = ref($_[0]) || $_[0] || "IO::Handle"; |
292 | @_ == 3 or croak "usage: new_from_fd $class FD, MODE"; |
cf7fe8a2 |
293 | my $io = gensym; |
c927212d |
294 | shift; |
cf7fe8a2 |
295 | IO::Handle::fdopen($io, @_) |
8add82fc |
296 | or return undef; |
cf7fe8a2 |
297 | bless $io, $class; |
8add82fc |
298 | } |
299 | |
98d4926f |
300 | # |
301 | # There is no need for DESTROY to do anything, because when the |
302 | # last reference to an IO object is gone, Perl automatically |
303 | # closes its associated files (if any). However, to avoid any |
304 | # attempts to autoload DESTROY, we here define it to do nothing. |
305 | # |
306 | sub DESTROY {} |
7a4c00b4 |
307 | |
8add82fc |
308 | |
309 | ################################################ |
310 | ## Open and close. |
311 | ## |
312 | |
313 | sub _open_mode_string { |
314 | my ($mode) = @_; |
315 | $mode =~ /^\+?(<|>>?)$/ |
316 | or $mode =~ s/^r(\+?)$/$1</ |
317 | or $mode =~ s/^w(\+?)$/$1>/ |
318 | or $mode =~ s/^a(\+?)$/$1>>/ |
319 | or croak "IO::Handle: bad open mode: $mode"; |
320 | $mode; |
321 | } |
322 | |
323 | sub fdopen { |
cf7fe8a2 |
324 | @_ == 3 or croak 'usage: $io->fdopen(FD, MODE)'; |
325 | my ($io, $fd, $mode) = @_; |
8add82fc |
326 | local(*GLOB); |
327 | |
328 | if (ref($fd) && "".$fd =~ /GLOB\(/o) { |
329 | # It's a glob reference; Alias it as we cannot get name of anon GLOBs |
330 | my $n = qualify(*GLOB); |
331 | *GLOB = *{*$fd}; |
332 | $fd = $n; |
333 | } elsif ($fd =~ m#^\d+$#) { |
334 | # It's an FD number; prefix with "=". |
335 | $fd = "=$fd"; |
336 | } |
337 | |
cf7fe8a2 |
338 | open($io, _open_mode_string($mode) . '&' . $fd) |
339 | ? $io : undef; |
8add82fc |
340 | } |
341 | |
342 | sub close { |
cf7fe8a2 |
343 | @_ == 1 or croak 'usage: $io->close()'; |
344 | my($io) = @_; |
8add82fc |
345 | |
cf7fe8a2 |
346 | close($io); |
8add82fc |
347 | } |
348 | |
349 | ################################################ |
350 | ## Normal I/O functions. |
351 | ## |
352 | |
8add82fc |
353 | # flock |
8add82fc |
354 | # select |
8add82fc |
355 | |
356 | sub opened { |
cf7fe8a2 |
357 | @_ == 1 or croak 'usage: $io->opened()'; |
8add82fc |
358 | defined fileno($_[0]); |
359 | } |
360 | |
361 | sub fileno { |
cf7fe8a2 |
362 | @_ == 1 or croak 'usage: $io->fileno()'; |
8add82fc |
363 | fileno($_[0]); |
364 | } |
365 | |
366 | sub getc { |
cf7fe8a2 |
367 | @_ == 1 or croak 'usage: $io->getc()'; |
8add82fc |
368 | getc($_[0]); |
369 | } |
370 | |
8add82fc |
371 | sub eof { |
cf7fe8a2 |
372 | @_ == 1 or croak 'usage: $io->eof()'; |
8add82fc |
373 | eof($_[0]); |
374 | } |
375 | |
376 | sub print { |
cf7fe8a2 |
377 | @_ or croak 'usage: $io->print(ARGS)'; |
8add82fc |
378 | my $this = shift; |
379 | print $this @_; |
380 | } |
381 | |
382 | sub printf { |
cf7fe8a2 |
383 | @_ >= 2 or croak 'usage: $io->printf(FMT,[ARGS])'; |
8add82fc |
384 | my $this = shift; |
385 | printf $this @_; |
386 | } |
387 | |
388 | sub getline { |
cf7fe8a2 |
389 | @_ == 1 or croak 'usage: $io->getline()'; |
8add82fc |
390 | my $this = shift; |
391 | return scalar <$this>; |
392 | } |
393 | |
f86702cc |
394 | *gets = \&getline; # deprecated |
395 | |
8add82fc |
396 | sub getlines { |
cf7fe8a2 |
397 | @_ == 1 or croak 'usage: $io->getlines()'; |
8add82fc |
398 | wantarray or |
cf7fe8a2 |
399 | croak 'Can\'t call $io->getlines in a scalar context, use $io->getline'; |
27d4819a |
400 | my $this = shift; |
8add82fc |
401 | return <$this>; |
402 | } |
403 | |
404 | sub truncate { |
cf7fe8a2 |
405 | @_ == 2 or croak 'usage: $io->truncate(LEN)'; |
8add82fc |
406 | truncate($_[0], $_[1]); |
407 | } |
408 | |
409 | sub read { |
cf7fe8a2 |
410 | @_ == 3 || @_ == 4 or croak 'usage: $io->read(BUF, LEN [, OFFSET])'; |
8add82fc |
411 | read($_[0], $_[1], $_[2], $_[3] || 0); |
412 | } |
413 | |
27d4819a |
414 | sub sysread { |
cf7fe8a2 |
415 | @_ == 3 || @_ == 4 or croak 'usage: $io->sysread(BUF, LEN [, OFFSET])'; |
27d4819a |
416 | sysread($_[0], $_[1], $_[2], $_[3] || 0); |
417 | } |
418 | |
8add82fc |
419 | sub write { |
8fd73a68 |
420 | @_ >= 2 && @_ <= 4 or croak 'usage: $io->write(BUF [, LEN [, OFFSET]])'; |
8add82fc |
421 | local($\) = ""; |
8fd73a68 |
422 | $_[2] = length($_[1]) unless defined $_[2]; |
8add82fc |
423 | print { $_[0] } substr($_[1], $_[3] || 0, $_[2]); |
424 | } |
425 | |
27d4819a |
426 | sub syswrite { |
8fd73a68 |
427 | @_ >= 2 && @_ <= 4 or croak 'usage: $io->syswrite(BUF [, LEN [, OFFSET]])'; |
428 | $_[2] = length($_[1]) unless defined $_[2]; |
5f05dabc |
429 | syswrite($_[0], $_[1], $_[2], $_[3] || 0); |
27d4819a |
430 | } |
431 | |
8add82fc |
432 | sub stat { |
cf7fe8a2 |
433 | @_ == 1 or croak 'usage: $io->stat()'; |
8add82fc |
434 | stat($_[0]); |
435 | } |
436 | |
437 | ################################################ |
438 | ## State modification functions. |
439 | ## |
440 | |
441 | sub autoflush { |
cf7fe8a2 |
442 | my $old = new SelectSaver qualify($_[0], caller); |
8add82fc |
443 | my $prev = $|; |
444 | $| = @_ > 1 ? $_[1] : 1; |
445 | $prev; |
446 | } |
447 | |
448 | sub output_field_separator { |
cf7fe8a2 |
449 | carp "output_field_separator is not supported on a per-handle basis" |
450 | if ref($_[0]); |
8add82fc |
451 | my $prev = $,; |
452 | $, = $_[1] if @_ > 1; |
453 | $prev; |
454 | } |
455 | |
456 | sub output_record_separator { |
cf7fe8a2 |
457 | carp "output_record_separator is not supported on a per-handle basis" |
458 | if ref($_[0]); |
8add82fc |
459 | my $prev = $\; |
460 | $\ = $_[1] if @_ > 1; |
461 | $prev; |
462 | } |
463 | |
464 | sub input_record_separator { |
cf7fe8a2 |
465 | carp "input_record_separator is not supported on a per-handle basis" |
466 | if ref($_[0]); |
8add82fc |
467 | my $prev = $/; |
468 | $/ = $_[1] if @_ > 1; |
469 | $prev; |
470 | } |
471 | |
472 | sub input_line_number { |
91cce263 |
473 | local $.; |
474 | my $tell = tell qualify($_[0], caller) if ref($_[0]); |
475 | my $prev = $.; |
476 | $. = $_[1] if @_ > 1; |
477 | $prev; |
478 | } |
91cce263 |
479 | |
8add82fc |
480 | sub format_page_number { |
b61d194c |
481 | my $old = new SelectSaver qualify($_[0], caller) if ref($_[0]); |
8add82fc |
482 | my $prev = $%; |
483 | $% = $_[1] if @_ > 1; |
484 | $prev; |
485 | } |
486 | |
487 | sub format_lines_per_page { |
b61d194c |
488 | my $old = new SelectSaver qualify($_[0], caller) if ref($_[0]); |
8add82fc |
489 | my $prev = $=; |
490 | $= = $_[1] if @_ > 1; |
491 | $prev; |
492 | } |
493 | |
494 | sub format_lines_left { |
b61d194c |
495 | my $old = new SelectSaver qualify($_[0], caller) if ref($_[0]); |
8add82fc |
496 | my $prev = $-; |
497 | $- = $_[1] if @_ > 1; |
498 | $prev; |
499 | } |
500 | |
501 | sub format_name { |
b61d194c |
502 | my $old = new SelectSaver qualify($_[0], caller) if ref($_[0]); |
8add82fc |
503 | my $prev = $~; |
504 | $~ = qualify($_[1], caller) if @_ > 1; |
505 | $prev; |
506 | } |
507 | |
508 | sub format_top_name { |
b61d194c |
509 | my $old = new SelectSaver qualify($_[0], caller) if ref($_[0]); |
8add82fc |
510 | my $prev = $^; |
511 | $^ = qualify($_[1], caller) if @_ > 1; |
512 | $prev; |
513 | } |
514 | |
515 | sub format_line_break_characters { |
cf7fe8a2 |
516 | carp "format_line_break_characters is not supported on a per-handle basis" |
517 | if ref($_[0]); |
8add82fc |
518 | my $prev = $:; |
519 | $: = $_[1] if @_ > 1; |
520 | $prev; |
521 | } |
522 | |
523 | sub format_formfeed { |
cf7fe8a2 |
524 | carp "format_formfeed is not supported on a per-handle basis" |
525 | if ref($_[0]); |
8add82fc |
526 | my $prev = $^L; |
527 | $^L = $_[1] if @_ > 1; |
528 | $prev; |
529 | } |
530 | |
531 | sub formline { |
cf7fe8a2 |
532 | my $io = shift; |
8add82fc |
533 | my $picture = shift; |
534 | local($^A) = $^A; |
535 | local($\) = ""; |
536 | formline($picture, @_); |
cf7fe8a2 |
537 | print $io $^A; |
8add82fc |
538 | } |
539 | |
540 | sub format_write { |
cf7fe8a2 |
541 | @_ < 3 || croak 'usage: $io->write( [FORMAT_NAME] )'; |
8add82fc |
542 | if (@_ == 2) { |
cf7fe8a2 |
543 | my ($io, $fmt) = @_; |
544 | my $oldfmt = $io->format_name($fmt); |
545 | CORE::write($io); |
546 | $io->format_name($oldfmt); |
8add82fc |
547 | } else { |
56f7f34b |
548 | CORE::write($_[0]); |
8add82fc |
549 | } |
550 | } |
551 | |
21e970cc |
552 | # XXX undocumented |
27d4819a |
553 | sub fcntl { |
cf7fe8a2 |
554 | @_ == 3 || croak 'usage: $io->fcntl( OP, VALUE );'; |
21e970cc |
555 | my ($io, $op) = @_; |
556 | return fcntl($io, $op, $_[2]); |
27d4819a |
557 | } |
558 | |
21e970cc |
559 | # XXX undocumented |
27d4819a |
560 | sub ioctl { |
cf7fe8a2 |
561 | @_ == 3 || croak 'usage: $io->ioctl( OP, VALUE );'; |
21e970cc |
562 | my ($io, $op) = @_; |
563 | return ioctl($io, $op, $_[2]); |
27d4819a |
564 | } |
8add82fc |
565 | |
cf7fe8a2 |
566 | # this sub is for compatability with older releases of IO that used |
567 | # a sub called constant to detemine if a constant existed -- GMB |
568 | # |
569 | # The SEEK_* and _IO?BF constants were the only constants at that time |
570 | # any new code should just chech defined(&CONSTANT_NAME) |
571 | |
572 | sub constant { |
573 | no strict 'refs'; |
574 | my $name = shift; |
575 | (($name =~ /^(SEEK_(SET|CUR|END)|_IO[FLN]BF)$/) && defined &{$name}) |
576 | ? &{$name}() : undef; |
577 | } |
578 | |
579 | |
580 | # so that flush.pl can be depriciated |
581 | |
582 | sub printflush { |
583 | my $io = shift; |
584 | my $old = new SelectSaver qualify($io, caller) if ref($io); |
585 | local $| = 1; |
586 | if(ref($io)) { |
587 | print $io @_; |
588 | } |
589 | else { |
590 | print @_; |
591 | } |
592 | } |
593 | |
8add82fc |
594 | 1; |