Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

richardc (1662)

  (email not shown publicly)

Journal of richardc (1662)

Tuesday July 30, 2002
11:28 PM

layered io, in an old-skool stylee

[ #6780 ]
In what may seem to be the ultimate relay-race module, I've currently being sinking cycles into IO::Timestamp. It's a relay race in as much as mstevens, my housemate, first suggested the idea to Elthek, my other housemate, as something that needed writing. I also stuck my nose in fairly early on with some ideas to hide the tie interface away.

The other day while bored I started looking at the code with a mind to finishing it off and noticed a buglet. The module was pretty much implemented as so:

package IO::Timestamp;
    bless {}, shift;
sub PRINT {
    print "[".localtime()."] ", @_;

Now this was just enough that this appears to work

tie *STDERR, 'IO::Timestamp';
print STDERR "I like pie\n";

but the output really goes to the currently selected filehandle, STDOUT. Now so far, this isn't really very exciting, unless you either fix the module, or do this:

tie *STDOUT, 'IO::Timestamp';
print "I like pie\n";

Boom! It recurses infinitely, or until something goes ping, whichever comes sooner.

It turns out that what would be really good for this would be a proper new-fangled perlio layer, but then it's useless for the next few years until people go to production on 5.8, so instead I've been trying to fake it. There's another payoff coming in that I'm not currently a huge fan of the interface that you need to implement to write a PerlIO::via::* module - it feels like a very literal translation of the underlying C api.

My mid-term goal is to produce some code that lets you use classes derived from Tie::StdHandle as perlio layers, and to further allow these to work using ties on nonperlio configurations.

So far I've cracked wrangling BAREWORD style package filehandles as ties, next up is lexicals (think open my $fh ">file"; wrap $fh, 'IO::Timestamp';) and then the seemingly short hop to native perlio layers.

The code lives here but it'll probably be refactored into it's own module once this progresses further.

So, have I finally flipped my lid? Answers on the back of a journal comment to the usual address.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • [..] but the output really goes to the currently selected filehandle, STDOUT.

    Oops. That is all.

    Well, not quite all. The 'relay race' idea got me thinking. We should get suggestions on something for the three of us to work on; something that would hopefully be better than usual owing to us being in the same room and being able to shout at each other. We could even invite Other Perl People over occasionally to lend a hand, too. Productivity galore.

    What do you think? Does anyone have any suggestion

    $a=""; Chris Ball | chris@void.$a | www.$a | finger: chris@$a
    • What do you think?

      Pie is good.
      Pie 6 will be better.

      In a way I think this is an exception, from my recent memory the only time we've all been in at the same time, and capable of writing code, was Saturday afternoon, just before I went to the pictures.

      There's a non-domestic angle too, in case people are worrying we're going to start to argue about the washing up. I can sometimes find it really hard to get interested in someone else's suggestion, especially if it scratches none of my itches. Mark