Home | MIME::Body | MIME::Decoder | MIME::Entity | MIME::Head |
MIME::IO | MIME::Latin1 | MIME::Parser | MIME::ParserBase | |
MIME::ToolUtils |
MIME::
|
Therefore, all that MIME::Body, MIME::Decoder, and the other classes require (and, thus, all that they can assume) is that they are manipulating an object which responds to the following small, well-defined set of messages:
"\n"
(except, maybe, the last one).
wrap()
constructor an argument, it is expected to be one of the following:
"STDOUT"
or "Class::HANDLE"
. In this case, the filehandle name is wrapped in a MIME::IO object, which is returned.
\*STDOUT
. In this case, the filehandle glob is wrapped in a MIME::IO object, which is returned.
read()
method.
my $IO = wrap MIME::IO::Handle \*STDOUT;
All this class does is to provide a simple means for the MIME:: classes to wrap raw filehandles inside a class which responds to the above messages (by passing the messages on to the actual filehandle in the form of the standard function calls).
The bottom line: what you get back is an object which is guaranteed to support the methods defined above.
This interface is used by many of the MIME-tool classes, for backwards compatibility with earlier versions of MIME-parser: if you supply a raw filehandle where an INSTREAM or OUTSTREAM is expected, most MIME packages will automatically wrap that raw filehandle in a MIME::IO object, which fits the I/O handle criteria.
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.
Use it like this:
$IO = new MIME::IO::Scalar \$scalar; $IO->print("Some data\n"); $IO->print("Some more data\n"); $IO->close; # ...$scalar now holds "Some data\nSome more data\n"
MIME::IOHandle
and MIME::IOScalar
... but it just seemed more sensible to mimic the IO:: hierarchy, one level
down (under MIME::).
All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.