From 7d20f0f1160c15c1b52ba92dc86441766040c6ec Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Tue, 30 May 2023 16:39:40 +0200 Subject: [PATCH] perl: move feature attributes formatting Clean up into function for later reuse. --- perl.plp | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/perl.plp b/perl.plp index 57a7dc8..de4637d 100644 --- a/perl.plp +++ b/perl.plp @@ -85,31 +85,7 @@ for my $vernum (reverse sort keys %{$info}) { say '
'; for (@{ $verrow->{new} }) { my ($topic, $desc, $attr) = @{$_}; - if ($attr) { - my $title; - if (defined $attr->{experimental}) { - $title = 'experimental'; - } - if ($attr->{dropped}) { - next unless exists $get{v}; - $title = sprintf 'removed in %vd', $attr->{dropped}; - } - elsif ($attr->{stable}) { - $title .= sprintf ' until %vd', $attr->{stable}; - } - if ($attr->{experimental}) { - $title = sprintf '%s', - $attr->{experimental}, $title; - $attr->{name} //= $attr->{experimental}; - } - if ($attr->{feature}) { - my $prefix = sprintf 'feature', - $attr->{feature}; - $title = join ', ', $prefix, $title // (); - $attr->{name} //= $attr->{feature}; - } - $desc .= sprintf ' (%s)', $title if $title; - } + $desc .= featattrs($attr); my $ref = defined $attr->{name} && sprintf ' id="%s"', $attr->{name}; say sprintf '%s
%s', $ref, $topic, $desc || '
'; } @@ -127,3 +103,29 @@ for my $vernum (reverse sort keys %{$info}) { say "\n"; } +sub featattrs ($attr) { + my $title; + if (defined $attr->{experimental}) { + $title = 'experimental'; + } + if ($attr->{dropped}) { + next unless exists $get{v}; + $title = sprintf 'removed in %vd', $attr->{dropped}; + } + elsif ($attr->{stable}) { + $title .= sprintf ' until %vd', $attr->{stable}; + } + if ($attr->{experimental}) { + $title = sprintf '%s', + $attr->{experimental}, $title; + $attr->{name} //= $attr->{experimental}; + } + if ($attr->{feature}) { + my $prefix = sprintf 'feature', + $attr->{feature}; + $title = join ', ', $prefix, $title // (); + $attr->{name} //= $attr->{feature}; + } + return sprintf ' (%s)', $title if $title; + return ''; +} -- 2.30.0