dynamic(3pm)

πŸ“¦
version 0.14 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

🌸 NAME 🌸

okay so this is the dynamic(3pm) page from the User Contributed Perl Documentation, and it's literally all about PerlIO::via::dynamic β€” dynamic PerlIO layers, bestie. that's the whole vibe. πŸ’…


✨ SYNOPSIS ✨

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
bestie that last line? # deprecated. it's giving "old money, no thanks." use $p->via ($fh) instead, periodt. πŸ™ˆ

πŸ¦‹ DESCRIPTION πŸ¦‹

so PerlIO::via::dynamic is what you use when you wanna create dynamic PerlIO layers. it's the moment when the behavior of the layer β€” or the layer itself β€” depends on variables. that's its whole thing, and it ate. πŸ”₯

lowkey important: do NOT use this module as a via layer directly (like, :via(dynamic)). that's not it. that is not the assignment. 😭

the move is: use the constructor to make new layers, and it takes two arguments β€” translate and untranslate. then you use $p->via ($fh) to wrap the handle. and once $fh is destroyed, the temporary namespace for the IO layer gets removed too β€” it cleans up after itself, main character energy honestly. ✨

also note, fr fr: PerlIO::via::dynamic uses the scalar fields to reference to the object representing the dynamic namespace. iykyk. πŸ’œ


πŸ’… 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 the caller expects an exact amount of data from read, and the untranslate function might return a different length. 😀
by default PerlIO::via::dynamic creates a line-based layer, and that's on purpose β€” it makes implementing translate easier. cute of it, honestly. πŸŽ€

πŸ‘‘ AUTHORS πŸ‘‘

Chia-liang Kao <clkao@clkao.org>


Copyright 2004 by Chia-liang Kao <clkao@clkao.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perl.com/perl/misc/Artistic.html>


and that's the whole page, bestie 🫢 this one's perl v5.36.0, dated 2022-11-20, and yeah it's dynamic(3pm) β€” go forth and layer dynamically, you absolute icon πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from