+my ($canihas, $usage);
+given ($get{usage} // 'wm') {
+ when (!$_) {
+ # none
+ }
+ when (!/^\w+$/) {
+ printf "<p>Invalid browser usage data request: <em>%s</em>",
+ 'identifier must be alphanumeric name or <q>0</q>';
+ }
+ $canihas = do "browser-usage-$_.inc.pl" or do {
+ printf "<p>Browser usage data not found: <em>%s</em>", $! || $@;
+ break;
+ };
+ $usage = $_;
+ my $ref = $canihas->{-source} || 'unknown';
+ $ref = sprintf '<a href="%s">%s</a>', $_, $ref for $canihas->{-url} || ();
+ $ref .= " $_" for $canihas->{-date} || ();
+ print "\nwith $ref browser usage statistics";
+}
+if ($usage) {
+ # first() does not work inside given >:(
+ while (my ($browser, $row) = each %$canihas) {
+ my $verlist = $versions{$browser} or next;
+ my %supported = map { $_ => 1 } @$verlist;
+ $row->{$_} //= undef for @$verlist; # ensure stable keys during iteration
+ while (my ($version, $usage) = each %$row) {
+ next if defined $supported{$version};
+ my $next = first { paddedver($_) ge paddedver($version) } @$verlist
+ or warn("No fallback found for $browser v$version; $usage% ignored"), next;
+ $row->{$next} += $usage;
+ $row->{$version} = 0; # balance browser total
+ }
+ }
+}
+:>.
+</p>
+
+<:
+$canihas ||= {
+ map {
+ $_ => +{
+ map {
+ my $zero = $#$_ - 2; # baseline index
+ ($_->[$zero - 2] => .5), # past
+ ($_->[$zero - 1] => 10 ), # previous
+ ($_->[$zero + 2] => 0 ), # future
+ ($_->[$zero + 1] => .5), # next
+ ($_->[$zero ] => 30 ), # current
+ } $caniuse->{agents}->{$_}->{versions}
+ }
+ } @browsers
+}; # fallback hash based on release semantics
+my $usagemax = (max(map { ref $_ eq 'HASH' && sum(values %$_) } values %$canihas) // 1) / 100;
+
+my $usagepct = 1; # score multiplier for 0..100 result
+# normalise usage percentage to only include shown browsers
+$usagepct = 100 / featurescore({ # yes for every possible version
+ map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions
+});