layered io, in an old-skool stylee

richardc on 2002-07-31T04:28:27

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;
sub TIEHANDLE {
    bless {}, shift;
}
sub PRINT {
    shift;
    print "[".localtime()."] ", @_;
}
1;

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.


IO::Timestamp

Elthek on 2002-07-31T10:18:24

[..] 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 suggestions on what needs the attention of two hardcore Perl hackers and, well, me?

- Chris.

Re:IO::Timestamp

richardc on 2002-07-31T12:18:59

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 and I have this recurring conversation which goes something like:

Me:    I'm bored and have nothing to hack on.
Mark:  You're welcome to do anything from my todo-list.
Me:    But none of those I care about writing

which is especially odd as I like Marks modules, and one day will probably benefit from some of his todo-list items, should they get written.

That's not to say I'm rejecting the idea, it's a good one, but if I don't find anyones suggestions interesting in some way they're unlikely to get the attention they need.