browser: support new caniuse data
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 5 Dec 2010 16:33:08 +0000 (17:33 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 6 Dec 2010 00:04:46 +0000 (01:04 +0100)
browser.plp
tools/convert-caniuse.pl

index 75605fd..ea23d0a 100644 (file)
@@ -109,6 +109,7 @@ sub featurescore {
        if (my $row = shift) {
                if ($canihas) {
                        while (my ($browser, $versions) = each %$row) {
+                               ref $versions eq 'HASH' or next;
                                while (my ($version, $_) = each %$versions) {
                                        $rank += $canihas->{$browser}->{$version} * $statspts->{$_};
                                }
@@ -151,7 +152,7 @@ for my $id (sort {
                $row->{description}, $row->{notes};
        printf 'Resources: %s.', join(', ',
                map { qq(<a href="$_->{url}">$_->{title}</a>) } @$_
-       ) for $row->{links} // ();
+       ) for grep { @$_ } $row->{links} // ();
        print '</div>';
        for ($row->{status}) {
                my $cell = $_ // '-';
@@ -163,11 +164,15 @@ for my $id (sort {
                my ($prev, @span);
                for my $ver (@{ $versions{$browser} }, undef) {
                        unless (!defined $prev
-                       or $data->{$browser}->{$prev} ~~ $data->{$browser}->{$ver}) {
+                       or ref $data->{$browser} eq 'HASH'
+                       && $data->{$browser}->{$prev} ~~ $data->{$browser}->{$ver}) {
                                my $usage = sum(map { $canihas->{$browser}->{$_} } @span);
                                printf '<td class="%s" colspan="%d" title="%.1f%%">%s',
                                        join(' ',
-                                               X => $CSTATS{ $data->{$browser}->{$prev} },
+                                               X => $CSTATS{
+                                                       ref $data->{$browser} ne 'HASH' ? 'u' :
+                                                               $data->{$browser}->{$prev} // 'u'
+                                               },
                                                !$usage ? ('p0') : ('p',
                                                        sprintf('p%01d', $usage / 10),
                                                        sprintf('p%02d', $usage),
index 7006b18..467b9ba 100755 (executable)
@@ -12,14 +12,14 @@ my $source = readline;
 
 for ($source) { # cleanup
        # convert seperate variables to hash keys
-       s/\A/{/;
-       s/^caniuse\.(\w+) /"$1":/gm;
+       s/\A/{\n/;
+       s/^caniuse\.(\w+) *= */"$1":/gm;
        s/;$/,/gm;
        s/,\s*\Z/\n}/;
        # fractions not supported by barekey
-       s/(?<=[,{]) (\d*\.\d) (?=:')/"$1"/gx;
+       s/(?<=[,{\n]) (\d*\.\d) (?=:['"])/"$1"/gx;
        # escapes not supported in singlequote
-       s{'((?:[^\\']+|\\.)*)'}{
+       s{: *\K'((?:[^\\']+|\\.)*)'}{
                my $_ = $1;
                s/"/\\"/g;
                s/\\'/'/g;