line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Command::Runner::Format; |
2
|
13
|
|
|
13
|
|
103
|
use strict; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
426
|
|
3
|
13
|
|
|
13
|
|
73
|
use warnings; |
|
13
|
|
|
|
|
22
|
|
|
13
|
|
|
|
|
463
|
|
4
|
|
|
|
|
|
|
|
5
|
13
|
|
|
13
|
|
5065
|
use Command::Runner::Quote 'quote'; |
|
13
|
|
|
|
|
34
|
|
|
13
|
|
|
|
|
718
|
|
6
|
|
|
|
|
|
|
|
7
|
13
|
|
|
13
|
|
97
|
use Exporter 'import'; |
|
13
|
|
|
|
|
21
|
|
|
13
|
|
|
|
|
2697
|
|
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
|
11
|
|
|
11
|
0
|
69
|
my ($format, @args) = @_; |
22
|
11
|
|
|
|
|
49
|
my $i = 0; |
23
|
11
|
|
|
|
|
275
|
$format =~ s{$regex}{ |
24
|
26
|
50
|
|
|
|
1174
|
$6 eq '%' ? '%' : _replace($args[$i++], $1, $6) |
25
|
|
|
|
|
|
|
}ge; |
26
|
11
|
|
|
|
|
535
|
$format; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _replace { |
30
|
26
|
|
|
26
|
|
137
|
my ($arg, $all, $char) = @_; |
31
|
26
|
50
|
|
|
|
82
|
if ($char eq 'q') { |
32
|
26
|
|
|
|
|
196
|
return quote $arg; |
33
|
|
|
|
|
|
|
} else { |
34
|
0
|
|
|
|
|
|
return sprintf $all, $arg; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |