PerlIO::via::dynamic(3pm)

PerlIO::via::dynamic3pm

Dynamic perlio layers

Usage

 open $fh, $fname;
 $p = PerlIO::via::dynamic->new
  (translate =>
    sub { $_[1] =~ s/\$Filename[:\w\s\-\.\/\\]*\$/\$Filename: $fname\$/e},
   untranslate =>
    sub { $_[1] =~ s/\$Filename[:\w\s\-\.\/\\]*\$/\$Filename\$/});
 $p->via ($fh);
 binmode $fh, $p->via; # deprecated

Overview

"PerlIO::via::dynamic" is used for creating dynamic PerlIO layers. It is useful when the behavior or the layer depends on variables. You should not use this module as via layer directly (ie :via(dynamic)).

Use the constructor to create new layers, with two arguments: translate and untranslate. Then use "$p-"via ($fh)> to wrap the handle. Once <$fh> is destroyed, the temporary namespace for the IO layer will be removed.

Note that PerlIO::via::dynamic uses the scalar fields to reference to the object representing the dynamic namespace.

Options

translate

A function that translate buffer upon write.

untranslate

A function that translate buffer upon read.

use_read

Use "READ" instead of "FILL" for the layer. Useful when caller expect exact amount of data from read, and the "untranslate" function might return different length.

By default "PerlIO::via::dynamic" creates line-based layer to make "translate" implementation easier.

Releases

12 releases since Debian 3.1 (Sarge); the text changed 5 times.

  1. 3.1–4.0
  2. 5.0–7
  3. 8–10
  4. 11
  5. 12–13
  6. Arch

Authors

Chia-liang Kao <[email protected]>

From perlio-via-dynamic 0.14-14 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.