| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Command::Runner::Format; | 
| 2 | 10 |  |  | 10 |  | 71 | use strict; | 
|  | 10 |  |  |  |  | 15 |  | 
|  | 10 |  |  |  |  | 287 |  | 
| 3 | 10 |  |  | 10 |  | 52 | use warnings; | 
|  | 10 |  |  |  |  | 18 |  | 
|  | 10 |  |  |  |  | 354 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 10 |  |  | 10 |  | 3311 | use Command::Runner::Quote 'quote'; | 
|  | 10 |  |  |  |  | 26 |  | 
|  | 10 |  |  |  |  | 584 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 10 |  |  | 10 |  | 63 | use Exporter 'import'; | 
|  | 10 |  |  |  |  | 21 |  | 
|  | 10 |  |  |  |  | 2262 |  | 
| 8 |  |  |  |  |  |  | our @EXPORT_OK = qw(commandf); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | # taken from String::Format | 
| 11 |  |  |  |  |  |  | my $regex = qr/ | 
| 12 |  |  |  |  |  |  | (%             # leading '%'                    $1 | 
| 13 |  |  |  |  |  |  | (-)?          # left-align, rather than right  $2 | 
| 14 |  |  |  |  |  |  | (\d*)?        # (optional) minimum field width $3 | 
| 15 |  |  |  |  |  |  | (?:\.(\d*))?  # (optional) maximum field width $4 | 
| 16 |  |  |  |  |  |  | (\{.*?\})?    # (optional) stuff inside        $5 | 
| 17 |  |  |  |  |  |  | (\S)          # actual format character        $6 | 
| 18 |  |  |  |  |  |  | )/x; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub commandf { | 
| 21 | 0 | 0 |  | 0 | 0 |  | if (!$ENV{PERL_COMMAND_RUNNER_SUPPRESS_WARNINGS}) { | 
| 22 | 0 |  |  |  |  |  | warn "Command::Runner::Format::commandf is deprecated; will be removed in the future version of Command-Runner distribution"; | 
| 23 |  |  |  |  |  |  | } | 
| 24 | 0 |  |  |  |  |  | my ($format, @args) = @_; | 
| 25 | 0 |  |  |  |  |  | my $i = 0; | 
| 26 | 0 |  |  |  |  |  | $format =~ s{$regex}{ | 
| 27 | 0 | 0 |  |  |  |  | $6 eq '%' ? '%' : _replace($args[$i++], $1, $6) | 
| 28 |  |  |  |  |  |  | }ge; | 
| 29 | 0 |  |  |  |  |  | $format; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | sub _replace { | 
| 33 | 0 |  |  | 0 |  |  | my ($arg, $all, $char) = @_; | 
| 34 | 0 | 0 |  |  |  |  | if ($char eq 'q') { | 
| 35 | 0 |  |  |  |  |  | return quote $arg; | 
| 36 |  |  |  |  |  |  | } else { | 
| 37 | 0 |  |  |  |  |  | return sprintf $all, $arg; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | 1; |