perl: move feature attributes formatting
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 30 May 2023 14:39:40 +0000 (16:39 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 30 May 2023 17:47:59 +0000 (19:47 +0200)
Clean up into function for later reuse.

perl.plp

index 57a7dc84da6ef4cbabd0e5f619fc8e033d72d64b..de4637d01eacf6b20ccf19bb734a01b49d1e3cfc 100644 (file)
--- a/perl.plp
+++ b/perl.plp
@@ -85,31 +85,7 @@ for my $vernum (reverse sort keys %{$info}) {
        say '<dl>';
        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 '<span title="experimental::%s">%s</span>',
-                                       $attr->{experimental}, $title;
-                               $attr->{name} //= $attr->{experimental};
-                       }
-                       if ($attr->{feature}) {
-                               my $prefix = sprintf '<span title="%s">feature</span>',
-                                       $attr->{feature};
-                               $title = join ', ', $prefix, $title // ();
-                               $attr->{name} //= $attr->{feature};
-                       }
-                       $desc .= sprintf ' <em class="ex">(%s)</em>', $title if $title;
-               }
+               $desc .= featattrs($attr);
                my $ref = defined $attr->{name} && sprintf ' id="%s"', $attr->{name};
                say sprintf '<dt%s>%s<dd>%s', $ref, $topic, $desc || '<br/>';
        }
@@ -127,3 +103,29 @@ for my $vernum (reverse sort keys %{$info}) {
        say "</div>\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 '<span title="experimental::%s">%s</span>',
+                       $attr->{experimental}, $title;
+               $attr->{name} //= $attr->{experimental};
+       }
+       if ($attr->{feature}) {
+               my $prefix = sprintf '<span title="%s">feature</span>',
+                       $attr->{feature};
+               $title = join ', ', $prefix, $title // ();
+               $attr->{name} //= $attr->{feature};
+       }
+       return sprintf ' <em class="ex">(%s)</em>', $title if $title;
+       return '';
+}