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.


In reply to Re^2: Create PerlIO::via layer to append data at the end of a file by ikegami
in thread Create PerlIO::via layer to append data at the end of a file by silly8888

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.