10 'cat \Klog/' => '/var/log/apache2/',
13 my $filename = 'barcat';
14 open my $input, '<', $filename
15 or die "Cannot read documentation from $filename script\n";
18 while (readline $input) {
19 # find code snippets in the appropriate section
20 /^=head1 EXAMPLES/ ... /^=head1/ or next;
24 # compose an identifier from significant parts
26 s/^\h+//; # indentation
27 s/\\\n\s*//g; # line continuations
28 s/^[(\h]+//; # subshell
29 s/^echo\ .*?\|\s*//; # preceding input
30 s/\|.*//; # subsequent pipes
31 s/^cat\ //; # local file
32 s/^curl\ // and do { # remote url
33 s/\ -.+//g; # download options
34 s{//[^/\s]+/\K\S*(?=/)}{}; # subdirectories
35 s{^https?://}{}; # http protocol
39 # prepare shell command to execute
41 while (my ($subcmd, $args) = each %CMDARGS) {
42 $subcmd .= " \\K", $args .= ' ' unless $subcmd =~ m/\\K/;
43 $cmd =~ s/\b$subcmd/$args/;
45 $cmd =~ s/'/'\\''/g, $cmd = " bash -c 'set -o pipefail\n$cmd'";
47 # run and report unexpected results
51 }, $name) or diag($cmd);