perl: grid columns only on sectioned dls
[sheet.git] / perl.plp
index 131291e0ffdf995521700ecb4a3fded5f7a7a053..02d034869ae7f7ee89c0c9aa8cc3ae30f014df75 100644 (file)
--- a/perl.plp
+++ b/perl.plp
@@ -2,7 +2,7 @@
 
 Html({
        title => 'perl version cheat sheet',
-       version => '1.3',
+       version => '1.4',
        keywords => [qw'
                perl version feature features comparison
                sheet cheat overview summary
@@ -17,20 +17,71 @@ Html({
 <p>The most significant features introduced for recent versions of the Perl
 scripting language.
 <:
-my $info = do 'perl.inc.pl' or die $@ // $!;
+my $info = Data('perl');
 
-say "Depending on desired compatibility you'll want to support a minimum of";
-say join(' or ', map {
-       sprintf '<span title="on %s">v%vd</span>', $info->{$_}->{distrosum}, $_
-} v5.8, v5.20), '.';
+use feature 'signatures';
+sub vname ($v) {
+       return sprintf 'v%d%03d', unpack 'C*', $v;
+}
+sub linkversion ($v) {
+       return showlink(sprintf('%vd', $v), '#'.vname($v));
+}
+
+eval {
+       use List::Util 'first';
+       use Time::Piece;
+       use Time::Seconds;
+
+       my $now = Time::Piece->new;
+       if (my $ts = $get{at}) {
+               $now = $now->strptime($ts, '%Y-%m-%d');
+               say "Compatibility details emulated for <em>$ts</em>.";
+       }
+       my $ts = $now->strftime('%F');
+       my @versions = sort grep { $info->{$_}{release} le $ts } keys %{$info};
+
+       # perlpolicy: «We "officially" support the two most recent stable release
+       # series. [...] we will attempt to fix critical issues»
+       $info->{ $versions[-2] }{versum} //= "active core support";
+       $info->{ $versions[-1] }{versum} //= "latest stable release";
+
+       # perlpolicy: «we will attempt to fix critical issues in the two most
+       # recent stable 5.x release series»
+       my $coreeol = ($now - ONE_YEAR * 3)->strftime('%F');
+       my $vcore = first { $info->{$_}{release} ge $coreeol } @versions;
+       print "<p>Core security support is provided for 3 years";
+       print ", so typical users should run at least ", linkversion($_)
+               for $vcore // ();
+       say '.';
+       $info->{$vcore}{versum} //= "official security patches";
+
+       # «We encourage vendors to ship the most recent supported release of Perl
+       # at the time of their code freeze» with debian&ubuntu having 5 years LTS
+       my $vendoreol = ($now - ONE_YEAR * 5)->strftime('%F');
+       my $vdebian = first {
+               $info->{$_}{release} ge $vendoreol && $info->{$_}{distro}{debian}
+       } @versions;
+       say sprintf "Stable distributions such as Debian %s maintain %s+.",
+               $info->{$_}{distro}{debian}, linkversion($_) for $vdebian // ();
+       $info->{$vdebian}{versum} //= "still maintained by common vendors";
+
+       # extended support given at random
+       my $nowcmp = $now->strftime('%F');
+       my $vdino = first { $info->{$_}{support} ge $nowcmp } @versions;
+       say "Enterprise platforms retain versions up to $_."
+               for map { linkversion($_) } $vdino // ();
+       return 1;
+} or Alert('Missing version recommendations', $@);
 say '</p>';
 
 for my $vernum (reverse sort keys %{$info}) {
        my $verrow = $info->{$vernum};
        defined $verrow->{unstable} and next unless exists $get{v};
 
-       say '<div class="section">';
-       say sprintf '<h2>%vd <small>%s</small></h2>', $vernum, $verrow->{release};
+       say sprintf '<div class="section" id="%s">', vname($vernum);
+       my $title = $verrow->{release} // '?';
+       $title .= ": $_" for $verrow->{versum} // ();
+       say sprintf '<h2>%vd <small>%s</small></h2>', $vernum, $title;
        say '<dl>';
        for (@{ $verrow->{new} }) {
                my ($topic, $desc, $attr) = @{$_};
@@ -49,15 +100,18 @@ for my $vernum (reverse sort keys %{$info}) {
                        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;
+                       $desc .= sprintf ' <em class="ex">(%s)</em>', $title if $title;
                }
-               say sprintf '<dt>%s<dd>%s', $topic, $desc || '<br/>';
+               my $ref = defined $attr->{name} && sprintf ' id="%s"', $attr->{name};
+               say sprintf '<dt%s>%s<dd>%s', $ref, $topic, $desc || '<br/>';
        }
        say sprintf '<dt>Unicode</dt><dd>v%s', $_ for $verrow->{unicode} || ();
        say '</dl>';