|
bgcolor="#FFFFFF" link="#CC3366" vlink="#993366" alink="#FF6666">
IO::Wrap 2.102This module is BETA code, which means that the interfaces are fairly stable BUT it has not been out in the community long enough to guarantee much testing. Use with caution! Please report any errors back to eryq@zeegee.com as soon as you can. NAMEIO::Wrap - wrap raw filehandles in IO::Handle interface SYNOPSISuse IO::Wrap; ### Do stuff with any kind of filehandle (including a bare globref), or ### any kind of blessed object that responds to a print() message. ### sub do_stuff { my $fh = shift; ### At this point, we have no idea what the user gave us... ### a globref? a FileHandle? a scalar filehandle name? $fh = wraphandle($fh); ### At this point, we know we have an IO::Handle-like object! $fh->print("Hey there!"); ... } DESCRIPTIONLet's say you want to write some code which does I/O, but you don't
want to force the caller to provide you with a FileHandle or IO::Handle
object. You want them to be able to say:
And even:
Sure, one way to do it is to force the caller to use tiehandle(). But that puts the burden on them. Another way to do it is to use IO::Wrap, which provides you with the following functions:
If you get back an IO::Wrap object, it will obey a basic subset of
the IO:: interface. That is, the following methods (note: I said
methods, not named operators) should work on the thing you get back:
NOTESClearly, when wrapping a raw external filehandle (like \*STDOUT), I didn't want to close the file descriptor when the "wrapper" object is destroyed... since the user might not appreciate that! Hence, there's no DESTROY method in this class. When wrapping a FileHandle object, however, I believe that Perl will invoke the FileHandle::DESTROY when the last reference goes away, so in that case, the filehandle is closed if the wrapped FileHandle really was the last reference to it. WARNINGSThis module does not allow you to wrap filehandle names which are given
as strings that lack the package they were opened in. That is, if a user
opens FOO in package Foo, they must pass it to you either as VERSION$Id: Wrap.pm,v 2.102 2001/08/17 02:06:33 eryq Exp $ AUTHOREryq ( Generated Mon Aug 20 16:36:50 2001 by cvu_pod2html |