+ my $cmd = $_;
+ my $ref = "$filename line $.";
+
+ # store curl downloads
+ $cmd =~ s{\bcurl (\S*)([^|]*)}{
+ my ($url, $params) = ($1, $2);
+ my $cache = 'sample/data/';
+ -w $cache or skip($url, 2);
+ my $ext = (
+ $cmd =~ /\bxml/ ? 'xml' :
+ $cmd =~ / jq / ? 'json' :
+ $cmd =~ /[=.]csv\b/ ? 'csv' :
+ 'txt'
+ );
+ my ($domain, $path) = $url =~ m{//([^/]+) .*/ ([^/]*) \z}x;
+ $path =~ s/\.$ext\z//;
+ $cache .= join '.', $path =~ tr/./_/r, $domain, $ext;
+ my $cached = -e $cache;
+ SKIP: {
+ # download to file
+ skip($url, 1) if $cached;
+ $cached = defined runres("curl -sSf $url$params -o $cache");
+ ok($cached, $url) or diag("download at $ref: $@");
+ }
+ $cached or skip($url, 1);
+ "cat $cache"
+ }e;