line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Command::Runner::Format; |
2
|
12
|
|
|
12
|
|
84
|
use strict; |
|
12
|
|
|
|
|
29
|
|
|
12
|
|
|
|
|
361
|
|
3
|
12
|
|
|
12
|
|
60
|
use warnings; |
|
12
|
|
|
|
|
30
|
|
|
12
|
|
|
|
|
383
|
|
4
|
|
|
|
|
|
|
|
5
|
12
|
|
|
12
|
|
4443
|
use Command::Runner::Quote 'quote'; |
|
12
|
|
|
|
|
30
|
|
|
12
|
|
|
|
|
645
|
|
6
|
|
|
|
|
|
|
|
7
|
12
|
|
|
12
|
|
79
|
use Exporter 'import'; |
|
12
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
2296
|
|
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
|
9
|
|
|
9
|
0
|
46
|
my ($format, @args) = @_; |
22
|
9
|
|
|
|
|
36
|
my $i = 0; |
23
|
9
|
|
|
|
|
187
|
$format =~ s{$regex}{ |
24
|
22
|
50
|
|
|
|
940
|
$6 eq '%' ? '%' : _replace($args[$i++], $1, $6) |
25
|
|
|
|
|
|
|
}ge; |
26
|
9
|
|
|
|
|
499
|
$format; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _replace { |
30
|
22
|
|
|
22
|
|
117
|
my ($arg, $all, $char) = @_; |
31
|
22
|
50
|
|
|
|
82
|
if ($char eq 'q') { |
32
|
22
|
|
|
|
|
107
|
return quote $arg; |
33
|
|
|
|
|
|
|
} else { |
34
|
0
|
|
|
|
|
|
return sprintf $all, $arg; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |