No action required

rafael on 2002-06-05T13:34:27

IOLayer::StripHTML has been uploaded to CPAN. That's a small input-only perlio layer, written in perl, whose idea was suggested at the latest Lyon.pm meeting. Next step is to write the output-only counterpart. Further step may be to write a small article about it, first in a hypothetical series what's new in the shiny world of Perl 5.8.

P.S. If you like closures, this module (although very short) uses some of them in an interesting way. There's even an lvalue closure. Cool.


interesting

gav on 2002-06-05T15:02:27

I'm definatly looking forward to some of the interesting things in 5.8.

One small point, don't you seem to call $p->eof. I've had odd things happen sometimes without it.

Re:interesting

rafael on 2002-06-09T20:26:57

Thanks ! now upgraded.

Extremely Exciting

darobin on 2002-06-05T15:15:26

This is of course incredibly cool. I've been toying with the idea of making one myself, but I can't seem to find docs on how one passes arguments to a layer (say open $fh,"<:Via(Foo::Bar=arg1,arg2)"; ?). The docs for PerlIO::Via haven't been very helpful there (or I've been very dumb).

Re:Extremely Exciting

rafael on 2002-06-05T15:53:34

In fact, in your example, Foo::Bar=arg1,arg2 is an argument passed to the "true" layer PerlIO::Via via its Getarg function (the proper documentation about this is in the perliol man page.) PerlIO::Via interprets it as a class name, on which the tie-like functions should be called. To do anything more complicated, you should write your layer in C.

Re:Extremely Exciting

darobin on 2002-06-05T17:28:11

Hmm, that's a pity. I was hoping that PerlIO::Via would have argument passing semantics (as the above would be an illegal class name) so that arguments could be passed to the layer.

The reason I came up with this was while thinking about IOLayer::XSLT. One would need to provide the path to the stylesheet as an argument, and if one can't then there's no way of implementing that module.

I'll look into subclassing PerlIO::Via to see if that could work, as I would very much like to avoid having to deal with C.

Re:Extremely Exciting

rafael on 2002-06-06T16:19:28

I don't think that subclassing PerlIO::Via is going
to work. In fact the internals of this thing are not very clearly documented and I'm just beginning to get how it works.

To keep it simple, I suggest action-at-distance :

my $fh = do {
    # this global variable is read at push-time
    local $IOLayer::XSLT::path = "....";
    open my $fh, ">:Via(IOLayer::XSLT)", "..."
        or die $!;
    $fh;
};

Re:Extremely Exciting

darobin on 2002-06-06T17:06:21

I very much doubt subclassing will work either, in fact I tried and it didn't appear to do anything, though I might have done it wrong.

Action-at-a-distance is out of the picture, either it can be done cleanly or I won't bother. One thing I thought about was $fh->setPath('/path/to/file.xsl') but that's not really satisfying, if indeed it does work (I'm pretty much sure it won't if IOLayer::XSLT isn't the last one in the stack).

I don't have much time to consecrate to this, but my current plans include either finding a way to extend PerlIO::Via, or directly submitting a patch (which given my C skills ought to be a bit hard). It's not so much that I care about IOLayer::XSLT in particular, but I find that not being able to pass params to the module when it instantiates its object (as one could with tie()) is a silly limitation.

Of course, don't let this cloud the fact that I feel that 5.8 is an awesome Perl. I've been playing a bit with RC1 and it's quite simply unbelievably good. It's just that Perl has got me used to having very few limits, and that one seems arbitrary.

Re:Extremely Exciting

rafael on 2002-06-06T20:37:50

Hey, that's not a perl limit, that's a limit in the particular PerlIO::Via module. You can do it very differently if you wish. You can implement PerlIO::ViaWithArgs that will do what you want. (It's a bit late to submit a code patch for 5.8.0.) Note that the whole perlio functionality is new and needs to be proof-tested with production code. Nick Ing-Simmons' amount of work to get this done was unbelievable.

Re:Extremely Exciting

darobin on 2002-06-06T21:21:34

Sorry, I didn't mean to imply that this was a Perl limit, just a limit in an implementation of something that ships with Perl.

I very much know that I can go ahead and implement a different Via module, I just wish that it were in this module (note: I'm not complaining, otherwise I'd be working on that right now and sending stuff to p5p). Part of this idea was precisely to implement something that would help test perlio, it's in fact the main reason why I grabbed RC1 (apart from checking that my stuff works there). I know that NIS's work was tremendous, I followed it as much as I could (with major gaps as I didn't always have time).

Again, I do not wish to badmouth 5.8, it's an awesome release. I just got used to Perl being much than I expected, not simply a lot better ;-)