[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl5-porters
Subject:    Re: binmode(FH => ":layer") should overwrite the previous layer
From:       Dan Kogai <dankogai () dan ! co ! jp>
Date:       2003-02-28 2:16:55
[Download RAW message or body]

On Friday, Feb 28, 2003, at 10:27 Asia/Tokyo, Benjamin Goldberg wrote:
>> It would be much easier if we had a handy way to tell what layer(s) a
>> given filehandle is in so we can go like;
>>
>>         my $layer = FH->layer; # only if this is possible
>>         unless ($layer =~ s/:encoding([^\)+])/:encoding(newlayer)/o{
>>                 $layer .= ":encoding(newlayer)";
>>         }
>>         binmode(FH => $layer);
>
> This seems silly -- I think it would be much more sensible if the
> function that's called when :encoding is pushed (the function name
> probably has '_Pushd' as part of it) were to examine the layers
> underneath it, and pop off any :encoding layer that's already there.

Yes, examine the layer but how?  For the time being we can poke layers 
as much as we want via binmode() but you can't peek.

We also have to consider such cases as the current layer being 
":encoding(foo) :crlf", not vice versa.  So simply popping :encoding 
does not cut general cases.  Not to mention :pop is still considered 
experimental...

> By having :encoding do that itself, it eases the burden on the user.

I'd love to, provided there is a way to peek layers.

> In addition, it avoids the need to creating a new API.

We still need one since there is no official way to peek the layer.

On Friday, Feb 28, 2003, at 10:53 Asia/Tokyo, Autrijus Tang wrote:
> Also, the new :encoding layer should be placed at exactly the same
> position as the old one, instead of on top, i.e.
>
>     :encoding(big5) :via(Base64)
>
> should not become
>
>     :via(Base64) :encoding(gbk)

That's exactly the reason you can't simply pop and push.  We have to 
"splice".  At any rate, the whole discussion is pointless without an 
API to peek the layer.

__SIGNATURE_FOLLOWS__
package PerlIO::via::JAPH;
my $japh = 'Just Another PerlIO Hacker';
sub PUSHED{
     bless \my $buf => shift;
}
sub FILL{
     my ($obj,$fh) = @_;
     return defined(my $line = <$fh>) ? $japh : undef;
}
sub WRITE{
     my ($obj,$buf,$fh) = @_;
     $$obj .= $japh;
     return length($buf);
}
sub FLUSH{
     my ($obj,$fh) = @_;
     print $fh $$obj or return -1;
     $$obj = '';
     return 0;
}
package main;
binmode STDOUT => ":via(JAPH)";
print "Dan the Encode Maintainer\n";



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic