Greetings,

For argument's sake, let's say you wanted to create a wrapper class for FileHandle, where you store a real FileHandle as a member of the class (OO aggregation instead of inheritance). (More details: Best way to implement ungetstring?).

One approach is to: (1) Have your class provide custom definitions for all the standard FileHandle methods which would simply call the analogous method on the real FileHandle object:

sub read { my $self = shift; $self->{real_filehandle}->read(@_); }
(2) You'd also need to tie the FileHandle so that stuff like eof would work.

Question: Is there something special about CORE::pipe? There's no TIEHANDLE function for it, and somehow it seems to know that I'm not using a "real" FileHandle. That is, this code:

my $out = new MyFileHandleWrapper; my $in = new MyFileHandleWrapper; pipe $out, $in or die; # Fork, close $in and read from $out in the parent, # print to $in in the child
Raises warnings about trying to close and print to unopened filehandles. However, if I change MyFileHandleWrapper to FileHandle, it works fine. If I'm careful to provide all the methods of FileHandle, and I tie all the TIEHANDLE functions, shouldn't this work?

Code is here if you want to run "make test" on my distro.

Thanks!


In reply to Is CORE::pipe magical? by coppit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.