+ # 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;
+
+ # compose an identifier from significant parts
+ do {
+ s/^\h+//; # indentation
+ s/\\\n\s*//g; # line continuations
+ s/^[(\h]+//; # subshell
+ s/^echo\ .*?\|\s*//; # preceding input
+ s/'(\S+)[^']*'/$1/g; # quoted arguments
+ s/\h*\|.*//; # subsequent pipes
+ s/^cat\ (?:\S+\/)?//; # local file
+ } for my $name = $cmd;