in reply to Re: Create PerlIO::via layer to append data at the end of a file
in thread Create PerlIO::via layer to append data at the end of a file

I appeared to have been mistaken. PerlIONext gets the next layer towards the bottom (system level), so PerlIOBase_close closes the layers starting at the top.

The problem actually lies in PerlIO::via.

IV PerlIOVia_close(pTHX_ PerlIO * f) { PerlIOVia *s = PerlIOSelf(f, PerlIOVia); IV code = PerlIOBase_close(aTHX_ f); SV *result = PerlIOVia_method(aTHX_ f, MYMethod(CLOSE), G_SCALAR, Nullsv); if (result && SvIV(result) != 0) code = SvIV(result); PerlIOBase(f)->flags &= ~(PERLIO_F_RDBUF | PERLIO_F_WRBUF); return code; }

It calls the rest of the chain (down to the system level) before calling your custom handler.

  1. utf8
  2. encoding(UTF-8)
  3. via
  4. perlio
  5. unix
  6. Mine ← !!

It should be calling your custom handler in order.

  1. utf8
  2. encoding(UTF-8)
  3. via
  4. Mine ←
  5. perlio
  6. unix

Reported as Perl RT#75780, including a trivial fix.

Replies are listed 'Best First'.
Re^3: Create PerlIO::via layer to append data at the end of a file
by silly8888 (Initiate) on Jun 16, 2010 at 04:46 UTC
    Thanks for your thorough investigation of the matter. I already did a workaround as it seems that PerlIO::via cannot be used for my purpose.