browser: drop downloading feature from mkcaniuse
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 12 Feb 2015 05:16:13 +0000 (06:16 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 13 Feb 2015 16:46:33 +0000 (17:46 +0100)
tools/mkcaniuse

index 3def627ea48bc091ad421f3290e413197e26a43c..d0cb8278c0b7c6b251d720c425ebad626d8d0739 100755 (executable)
@@ -5,42 +5,10 @@ use warnings;
 
 use Data::Dump 'pp';
 use JSON;
+use File::stat;
+use Time::Piece;
 
-if (@ARGV) {
-       require Time::Piece;
-       require LWP::UserAgent;
-       require File::stat;
-
-       my $target = 'browser-support.inc.pl';
-       my $source = 'http://caniuse.com/data.json';
-
-       my $ua = LWP::UserAgent->new;
-       $ua->agent('sheet.shiar.nl/browser');
-       $ua->default_header('If-Modified-Since' => scalar gmtime $_->mtime)
-               for File::stat::stat($target);
-
-       my $res = $ua->get($source) or die "No data from $source\n";
-       !$res->is_error or die $res->status_line;
-       say $res->status_line;
-
-       exit 0 if $res->code == 304;  # unmodified
-
-       my $data = decode_json($res->decoded_content) or die "Parse error: $!";
-       my $updated = eval {
-               s/ GMT$//,
-               return Time::Piece->strptime($_) for $res->header('Last-Modified')
-       };
-       $data->{-date} = $_->datetime for $updated || ();
-
-       my $suffix = $updated && $updated->ymd || time;
-       open my $save, '>', (my $download = "browser-support-$suffix.inc.pl");
-       print {$save} pp($data);
-       close $save;
-
-       symlink $download, "$target.new" and rename "$target.new", $target
-               or die "New data at $download not linked: $!";
-       exit 0;
-}
+our $VERSION = '1.01';
 
 local $/;  # slurp
 my $source = readline;
@@ -69,6 +37,9 @@ my $data = from_json($source, {
        allow_singlequote => 1,
        allow_barekey => 1,
 });
+my $update = eval { stat(${^LAST_FH} // $ARGV)->mtime }
+       or warn "Could not determine input time\n";
+$data->{-date} = Time::Piece->new($update)->datetime;
 
 print pp($data);
 
@@ -80,8 +51,5 @@ mkcaniuse - Turn Javascript data into an equivalent Perl structure
 
 =head1 SYNOPSIS
 
-       curl http://caniuse.com/data.json |
-       tools/mkcaniuse.pl > browser-support.inc.pl
-
-       tools/mkcaniuse.pl auto
+       tools/mkcaniuse data.json >browser-support.inc.pl