Marc M. Adkins Marc.M.Adkins at Doorways.org
Sat Jan 11 14:41:19 CST 2003

I finally got around to messing with the Perl IO layer mechanism.  I have
several output logging classes implemented as tied handles and I figured I
would convert one to a layer and see how it worked.

One characteristic of some of my tied handle classes is that they have
various methods that allow control of the stream.  For example, I have a log
stream that supports indentation, and it has methods for incrementing or
decrementing the current amount of indentation.  I call these methods using
the tied() method on the filehandle, which works just ducky.  For example:

	tie $log, 'IndentLog', '>indented.log';

	print $log "No indent\n";
	  print $log "Indented by two spaces\n";
	      print $log "Indented by six spaces\n";
	  print $log "Indented by two spaces\n";
	print $log "No indent\n";

	untie $log;

[or something like that, not working code, please forgive any syntax errors]

Anyway, I tried to implement one of my classes as a layer using PerlIO::via
and much to my surprise (shock/horror) there is no way to get a pointer to
the object after the fact.  There isn't even a way to pass extra arguments
into the layer creation.  So I can't manipulate the streams on the fly (or
even configure them at definition) as I wanted.

It occurred to me that perhaps I was pushing the paradigm where it shouldn't
go...that maybe the layer model was intended for relatively simple
transformations such as :crlf versus :raw which wouldn't require access to
the layer object...and that I should leave my code as tied handles.  Then I
found references in the perl5-porters mailing list to issues 'twixt layers
and tied handles and the possibility that the latter might go away at some
point in favor of the former.

The PerlIO::via::LineNumber module (available on CPAN) solves this problem
by using class methods to alter the characteristics of the stream.  This
would handle some cases but it wouldn't support having multiple streams of
the same type at the same time with different characteristics.  I don't do
this much, but occasionally it is useful, especially with the indentation

Have I missed something?  Am I abusing the paradigm?  Any thoughts or


More information about the spug-list mailing list