```{index} single: PerlIO::encoding; Perl module ``` # PerlIO::encoding ```{pperl-module-badges} PerlIO::encoding ``` Open a filehandle with a transparent character-set encoding filter. This is a PerlIO layer implementation. It registers a PerlIO layer vtable (`PerlIO_encode`) that perl5's PerlIO system calls for I/O operations on handles opened with `:encoding(...)`. The layer works by overloading "fill" and "flush" methods of PerlIOBuf: - "fill" reads bytes from the layer below, calls Encode->decode() to convert to UTF-8, and presents the result to layers above. - "flush" takes UTF-8 data from the write buffer, calls Encode->encode() to convert to the target encoding, and writes to the layer below. `encoding.xs` struct PerlIOEncode extends PerlIOBuf with: bufsv — SV buffer seen by layers above dataSV — data read from layer below (pending bytes) enc — the Encode encoding object chk — CHECK flag for encode/decode calls flags — `NEEDS_LINES` flag inEncodeCall — re-entrancy guard The BOOT section: 1. Loads Encode module if not already loaded (via load_module) 2. Fetches `Encode::STOP_AT_PARTIAL` and `Encode::LEAVE_SRC` constants 3. Registers the "encoding" PerlIO layer via PerlIO_define_layer ## Functions ### Other Functions #### `pop_result` Pop a single SV result off the Perl stack (equivalent of SPAGAIN; POPs). Returns a p5api SV*.