home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _71f736f736553b4edff6c00dcf360c44 < prev    next >
Text File  |  2000-03-23  |  12KB  |  263 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>IO::Handle - supply object methods for I/O handles</TITLE>
  5. <LINK REL="stylesheet" HREF="../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> IO::Handle - supply object methods for I/O handles</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#constructor">CONSTRUCTOR</A></LI>
  26.     <LI><A HREF="#methods">METHODS</A></LI>
  27.     <LI><A HREF="#note">NOTE</A></LI>
  28.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  29.     <LI><A HREF="#bugs">BUGS</A></LI>
  30.     <LI><A HREF="#history">HISTORY</A></LI>
  31. </UL>
  32. <!-- INDEX END -->
  33.  
  34. <HR>
  35. <P>
  36. <H1><A NAME="name">NAME</A></H1>
  37. <P>IO::Handle - supply object methods for I/O handles</P>
  38. <P>
  39. <HR>
  40. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  41. <UL>
  42. <LI>Linux</LI>
  43. <LI>Solaris</LI>
  44. <LI>Windows</LI>
  45. </UL>
  46. <HR>
  47. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  48. <PRE>
  49.     use IO::Handle;</PRE>
  50. <PRE>
  51.     $io = new IO::Handle;
  52.     if ($io->fdopen(fileno(STDIN),"r")) {
  53.         print $io->getline;
  54.         $io->close;
  55.     }</PRE>
  56. <PRE>
  57.     $io = new IO::Handle;
  58.     if ($io->fdopen(fileno(STDOUT),"w")) {
  59.         $io->print("Some text\n");
  60.     }</PRE>
  61. <PRE>
  62.     use IO::Handle '_IOLBF';
  63.     $io->setvbuf($buffer_var, _IOLBF, 1024);</PRE>
  64. <PRE>
  65.     undef $io;       # automatically closes the file if it's open</PRE>
  66. <PRE>
  67.     autoflush STDOUT 1;</PRE>
  68. <P>
  69. <HR>
  70. <H1><A NAME="description">DESCRIPTION</A></H1>
  71. <P><CODE>IO::Handle</CODE> is the base class for all other IO handle classes. It is
  72. not intended that objects of <CODE>IO::Handle</CODE> would be created directly,
  73. but instead <CODE>IO::Handle</CODE> is inherited from by several other classes
  74. in the IO hierarchy.</P>
  75. <P>If you are reading this documentation, looking for a replacement for
  76. the <CODE>FileHandle</CODE> package, then I suggest you read the documentation
  77. for <CODE>IO::File</CODE> too.</P>
  78. <P>
  79. <HR>
  80. <H1><A NAME="constructor">CONSTRUCTOR</A></H1>
  81. <DL>
  82. <DT><STRONG><A NAME="item_new">new ()</A></STRONG><BR>
  83. <DD>
  84. Creates a new <CODE>IO::Handle</CODE> object.
  85. <P></P>
  86. <DT><STRONG><A NAME="item_new_from_fd">new_from_fd ( FD, MODE )</A></STRONG><BR>
  87. <DD>
  88. Creates a <CODE>IO::Handle</CODE> like <A HREF="#item_new"><CODE>new</CODE></A> does.
  89. It requires two parameters, which are passed to the method <A HREF="#item_fdopen"><CODE>fdopen</CODE></A>;
  90. if the fdopen fails, the object is destroyed. Otherwise, it is returned
  91. to the caller.
  92. <P></P></DL>
  93. <P>
  94. <HR>
  95. <H1><A NAME="methods">METHODS</A></H1>
  96. <P>See <A HREF="../../lib/Pod/perlfunc.html">the perlfunc manpage</A> for complete descriptions of each of the following
  97. supported <CODE>IO::Handle</CODE> methods, which are just front ends for the
  98. corresponding built-in functions:</P>
  99. <PRE>
  100.     $io->close
  101.     $io->eof
  102.     $io->fileno
  103.     $io->format_write( [FORMAT_NAME] )
  104.     $io->getc
  105.     $io->read ( BUF, LEN, [OFFSET] )
  106.     $io->print ( ARGS )
  107.     $io->printf ( FMT, [ARGS] )
  108.     $io->stat
  109.     $io->sysread ( BUF, LEN, [OFFSET] )
  110.     $io->syswrite ( BUF, LEN, [OFFSET] )
  111.     $io->truncate ( LEN )</PRE>
  112. <P>See <A HREF="../../lib/Pod/perlvar.html">the perlvar manpage</A> for complete descriptions of each of the following
  113. supported <CODE>IO::Handle</CODE> methods.  All of them return the previous
  114. value of the attribute and takes an optional single argument that when
  115. given will set the value.  If no argument is given the previous value
  116. is unchanged (except for $io->autoflush will actually turn ON
  117. autoflush by default).</P>
  118. <PRE>
  119.     $io->autoflush ( [BOOL] )                         $|
  120.     $io->format_page_number( [NUM] )                  $%
  121.     $io->format_lines_per_page( [NUM] )               $=
  122.     $io->format_lines_left( [NUM] )                   $-
  123.     $io->format_name( [STR] )                         $~
  124.     $io->format_top_name( [STR] )                     $^
  125.     $io->input_line_number( [NUM])                    $.</PRE>
  126. <P>The following methods are not supported on a per-filehandle basis.</P>
  127. <PRE>
  128.     IO::Handle->format_line_break_characters( [STR] ) $:
  129.     IO::Handle->format_formfeed( [STR])               $^L
  130.     IO::Handle->output_field_separator( [STR] )       $,
  131.     IO::Handle->output_record_separator( [STR] )      $\</PRE>
  132. <PRE>
  133.     IO::Handle->input_record_separator( [STR] )       $/</PRE>
  134. <P>Furthermore, for doing normal I/O you might need these:</P>
  135. <DL>
  136. <DT><STRONG><A NAME="item_fdopen">$io->fdopen ( FD, MODE )</A></STRONG><BR>
  137. <DD>
  138. <A HREF="#item_fdopen"><CODE>fdopen</CODE></A> is like an ordinary <A HREF="../../lib/Pod/perlfunc.html#item_open"><CODE>open</CODE></A> except that its first parameter
  139. is not a filename but rather a file handle name, a IO::Handle object,
  140. or a file descriptor number.
  141. <P></P>
  142. <DT><STRONG><A NAME="item_opened">$io->opened</A></STRONG><BR>
  143. <DD>
  144. Returns true if the object is currently a valid file descriptor.
  145. <P></P>
  146. <DT><STRONG><A NAME="item_getline">$io->getline</A></STRONG><BR>
  147. <DD>
  148. This works like <$io> described in <A HREF="../../lib/Pod/perlop.html#i/o operators">I/O Operators in the perlop manpage</A>
  149. except that it's more readable and can be safely called in an
  150. array context but still returns just one line.
  151. <P></P>
  152. <DT><STRONG><A NAME="item_getlines">$io->getlines</A></STRONG><BR>
  153. <DD>
  154. This works like <$io> when called in an array context to
  155. read all the remaining lines in a file, except that it's more readable.
  156. It will also <CODE>croak()</CODE> if accidentally called in a scalar context.
  157. <P></P>
  158. <DT><STRONG><A NAME="item_ungetc">$io->ungetc ( ORD )</A></STRONG><BR>
  159. <DD>
  160. Pushes a character with the given ordinal value back onto the given
  161. handle's input stream.  Only one character of pushback per handle is
  162. guaranteed.
  163. <P></P>
  164. <DT><STRONG><A NAME="item_write">$io->write ( BUF, LEN [, OFFSET ] )</A></STRONG><BR>
  165. <DD>
  166. This <A HREF="#item_write"><CODE>write</CODE></A> is like <A HREF="#item_write"><CODE>write</CODE></A> found in C, that is it is the
  167. opposite of read. The wrapper for the perl <A HREF="#item_write"><CODE>write</CODE></A> function is
  168. called <CODE>format_write</CODE>.
  169. <P></P>
  170. <DT><STRONG><A NAME="item_error">$io->error</A></STRONG><BR>
  171. <DD>
  172. Returns a true value if the given handle has experienced any errors
  173. since it was opened or since the last call to <A HREF="#item_clearerr"><CODE>clearerr</CODE></A>.
  174. <P></P>
  175. <DT><STRONG><A NAME="item_clearerr">$io->clearerr</A></STRONG><BR>
  176. <DD>
  177. Clear the given handle's error indicator.
  178. <P></P>
  179. <DT><STRONG><A NAME="item_sync">$io->sync</A></STRONG><BR>
  180. <DD>
  181. <A HREF="#item_sync"><CODE>sync</CODE></A> synchronizes a file's in-memory state  with  that  on the
  182. physical medium. <A HREF="#item_sync"><CODE>sync</CODE></A> does not operate at the perlio api level, but
  183. operates on the file descriptor, this means that any data held at the
  184. perlio api level will not be synchronized. To synchronize data that is
  185. buffered at the perlio api level you must use the flush method. <A HREF="#item_sync"><CODE>sync</CODE></A>
  186. is not implemented on all platforms. See <EM>fsync(3c)</EM>.
  187. <P></P>
  188. <DT><STRONG><A NAME="item_flush">$io->flush</A></STRONG><BR>
  189. <DD>
  190. <A HREF="#item_flush"><CODE>flush</CODE></A> causes perl to flush any buffered data at the perlio api level.
  191. Any unread data in the buffer will be discarded, and any unwritten data
  192. will be written to the underlying file descriptor.
  193. <P></P>
  194. <DT><STRONG><A NAME="item_printflush">$io->printflush ( ARGS )</A></STRONG><BR>
  195. <DD>
  196. Turns on autoflush, print ARGS and then restores the autoflush status of the
  197. <CODE>IO::Handle</CODE> object.
  198. <P></P>
  199. <DT><STRONG><A NAME="item_blocking">$io->blocking ( [ BOOL ] )</A></STRONG><BR>
  200. <DD>
  201. If called with an argument <A HREF="#item_blocking"><CODE>blocking</CODE></A> will turn on non-blocking IO if
  202. <CODE>BOOL</CODE> is false, and turn it off if <CODE>BOOL</CODE> is true.
  203. <P><A HREF="#item_blocking"><CODE>blocking</CODE></A> will return the value of the previous setting, or the
  204. current setting if <CODE>BOOL</CODE> is not given.</P>
  205. <P>If an error occurs <A HREF="#item_blocking"><CODE>blocking</CODE></A> will return undef and <CODE>$!</CODE> will be set.</P>
  206. <P></P></DL>
  207. <P>If the C functions <CODE>setbuf()</CODE> and/or <CODE>setvbuf()</CODE> are available, then
  208. <CODE>IO::Handle::setbuf</CODE> and <CODE>IO::Handle::setvbuf</CODE> set the buffering
  209. policy for an IO::Handle.  The calling sequences for the Perl functions
  210. are the same as their C counterparts--including the constants <CODE>_IOFBF</CODE>,
  211. <CODE>_IOLBF</CODE>, and <CODE>_IONBF</CODE> for setvbuf()--except that the buffer parameter
  212. specifies a scalar variable to use as a buffer.  WARNING: A variable
  213. used as a buffer by <CODE>setbuf</CODE> or <CODE>setvbuf</CODE> must not be modified in any
  214. way until the IO::Handle is closed or <CODE>setbuf</CODE> or <CODE>setvbuf</CODE> is called
  215. again, or memory corruption may result! Note that you need to import
  216. the constants <CODE>_IOFBF</CODE>, <CODE>_IOLBF</CODE>, and <CODE>_IONBF</CODE> explicitly.</P>
  217. <P>Lastly, there is a special method for working under <STRONG>-T</STRONG> and setuid/gid
  218. scripts:</P>
  219. <DL>
  220. <DT><STRONG><A NAME="item_untaint">$io->untaint</A></STRONG><BR>
  221. <DD>
  222. Marks the object as taint-clean, and as such data read from it will also
  223. be considered taint-clean. Note that this is a very trusting action to
  224. take, and appropriate consideration for the data source and potential
  225. vulnerability should be kept in mind.
  226. <P></P></DL>
  227. <P>
  228. <HR>
  229. <H1><A NAME="note">NOTE</A></H1>
  230. <P>A <CODE>IO::Handle</CODE> object is a reference to a symbol/GLOB reference (see
  231. the <CODE>Symbol</CODE> package).  Some modules that
  232. inherit from <CODE>IO::Handle</CODE> may want to keep object related variables
  233. in the hash table part of the GLOB. In an attempt to prevent modules
  234. trampling on each other I propose the that any such module should prefix
  235. its variables with its own name separated by _'s. For example the IO::Socket
  236. module keeps a <CODE>timeout</CODE> variable in 'io_socket_timeout'.</P>
  237. <P>
  238. <HR>
  239. <H1><A NAME="see also">SEE ALSO</A></H1>
  240. <P><A HREF="../../lib/Pod/perlfunc.html">the perlfunc manpage</A>, 
  241. <A HREF="../../lib/Pod/perlop.html#i/o operators">I/O Operators in the perlop manpage</A>,
  242. <A HREF="../../lib/IO/File.html">the IO::File manpage</A></P>
  243. <P>
  244. <HR>
  245. <H1><A NAME="bugs">BUGS</A></H1>
  246. <P>Due to backwards compatibility, all filehandles resemble objects
  247. of class <CODE>IO::Handle</CODE>, or actually classes derived from that class.
  248. They actually aren't.  Which means you can't derive your own 
  249. class from <CODE>IO::Handle</CODE> and inherit those methods.</P>
  250. <P>
  251. <HR>
  252. <H1><A NAME="history">HISTORY</A></H1>
  253. <P>Derived from FileHandle.pm by Graham Barr <<EM><A HREF="mailto:gbarr@pobox.com">gbarr@pobox.com</A></EM>></P>
  254. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  255. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  256. <STRONG><P CLASS=block> IO::Handle - supply object methods for I/O handles</P></STRONG>
  257. </TD></TR>
  258. </TABLE>
  259.  
  260. </BODY>
  261.  
  262. </HTML>
  263.