From: Mischa POSLAWSKY Date: Tue, 30 May 2023 14:48:05 +0000 (+0200) Subject: perl: code example as feature attribute X-Git-Tag: v1.14~14 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/651e4bfa3cc349373e8f9adfd068ff6a6476b153 perl: code example as feature attribute --- diff --git a/perl.inc.pl b/perl.inc.pl index 49e8eef..ba330ba 100644 --- a/perl.inc.pl +++ b/perl.inc.pl @@ -59,7 +59,7 @@ use utf8; v5.8 => { new => [ [q"no utf8", 'full unicode support, utf8 pragma only for script encoding', {name => 'utf8_data'}], - [q"binmode $fh, ':perlio'", 'file handle behaviour altered by PerlIO layers', {name => 'perlio'}], + [q"use open", 'file handle behaviour altered by PerlIO layers', {name => 'perlio', eg => 'binmode $fh, ":bytes"'}], [q"open $fh, '-|', @cmd", 'open list to fork a command without spawning a shell'], [q"open $fh, '>', \$var", 'perl scalars as virtual files'], [q"printf '%1$s', @args", 'syntax to use parameters out of order'], diff --git a/perl.plp b/perl.plp index de4637d..49694fc 100644 --- a/perl.plp +++ b/perl.plp @@ -91,9 +91,9 @@ for my $vernum (reverse sort keys %{$info}) { } if (my $mods = $verrow->{modules}) { for (@{$mods}) { - my ($name, $desc, $eg) = @{$_}; + my ($name, $desc, $attr) = @{$_}; my $ref = lc $name =~ s/::/_/gr; - $desc .= sprintf ' {%s}', Entity($_) for $eg // (); + $desc .= featattrs($attr); printf '
use %s', $ref, $name; say '
', $desc; } @@ -104,6 +104,8 @@ for my $vernum (reverse sort keys %{$info}) { } sub featattrs ($attr) { + $attr or return ''; + ref $attr or $attr = {eg => $attr}; my $title; if (defined $attr->{experimental}) { $title = 'experimental'; @@ -126,6 +128,11 @@ sub featattrs ($attr) { $title = join ', ', $prefix, $title // (); $attr->{name} //= $attr->{feature}; } - return sprintf ' (%s)', $title if $title; - return ''; + $title = $title ? sprintf ' (%s)', $title : ''; + + if (my $eg = $attr->{eg}) { + my $pre = sprintf ' {%s}', Entity($eg); + $title = $pre . $title; + } + return $title; }