develooper Front page | perl.perl5.porters | Postings from February 2003

Re: PerlIO ":pop" / more elegant interface

From:
Nick Ing-Simmons
Date:
February 14, 2003 14:31
Subject:
Re: PerlIO ":pop" / more elegant interface
Message ID:
20030214222845.2128.1@bactrian.ni-s.u-net.com
Alex Efros <powerman@sky.net.ua> writes:
>Hi!
>
>>    open($fh,...)
>>    ...
>>    binmode($fh,":encoding(...)");  # next chunk is encoded
>>    ...
>>    binmode($fh,":pop");            # back to un-encocded
>>
>>    A more elegant (and safer) interface is needed.
>
>If PerlIO layers realized as stack/array, why not allow to edit them as array?

They are implemented as a singly linked list of C structs.
The other muddle is socket file-handles can have _two_ PerlIO lists
one for input and the other for output.
Mapping that on to a "stack/array" is not as trivial as it looks at first
but not hard.

>
>    open($fh,...)
>    ...
>    push @$fh, ":encoding(...)";
>    ...
>    pop @$fh;
>    ...
>    $_ = ":encoding(koi8-r)" for first {/encoding/} @$fh;
>    ...

Hmm - I though @$fh with $fh being a ref-to-glob would access the AV
That is 

my $ref = \*FOO;
push(@$ref,'Thing');

Would update @FOO 

But is seems it doesn't (anymore?)

Which may mean the syntax is available for this.
However the "arrays" are going to be very odd - e.g. your examples show 
items as strings and they are not strings - nearer objects, 
so some kind of implied-new is going on. (Which is not alien to the warped mind
that devised perl/Tk - but which may be  bit gross to go in the core...)

e.g. 

   push @$fh, ":encoding(koi8-r)";

would really have to be short-hand for something more like 

   push @$fh,PerlIO::layer->findClass('encoding')->construct('koi8-r');

And what would 

my $layer = pop($fh);

Set $layer to ? - if $layer is re-pushed should it remember the data it had
buffered?

etc. etc.

Copied to p5p as such ideas need wider discussion.


-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About