line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
93424
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
1
|
|
|
1
|
|
6
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
686
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
9
|
1
|
|
|
1
|
|
5
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
10
|
1
|
|
|
1
|
|
598
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
14
|
|
|
|
|
|
|
has spec => (fix_arg => 1); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my ($self) = @_; |
17
|
|
|
|
|
|
|
my $spec = $self->spec; |
18
|
3
|
|
|
3
|
|
30
|
as_path($self->path)->updater( |
19
|
3
|
|
|
|
|
7
|
if_string => sub {sprintf($spec, $_[0])}, |
20
|
|
|
|
|
|
|
if_array_ref => sub {sprintf($spec, @{$_[0]})}, |
21
|
1
|
|
|
1
|
|
18
|
if_hash_ref => sub {sprintf($spec, %{$_[0]})}, |
22
|
1
|
|
|
1
|
|
2
|
); |
|
1
|
|
|
|
|
19
|
|
23
|
1
|
|
|
1
|
|
2
|
} |
|
1
|
|
|
|
|
22
|
|
24
|
3
|
|
|
|
|
8
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=pod |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 NAME |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Catmandu::Fix::format - replace the value with a formatted (sprintf-like) version |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SYNOPSIS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# e.g. number: 41 |
37
|
|
|
|
|
|
|
format(number,"%-10.10d") # number => "0000000041" |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# e.g. numbers: |
40
|
|
|
|
|
|
|
# - 41 |
41
|
|
|
|
|
|
|
# - 15 |
42
|
|
|
|
|
|
|
format(number,"%-10.10d %-5.5d") # numbers => "0000000041 00015" |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# e.g. hash: |
45
|
|
|
|
|
|
|
# name: Albert |
46
|
|
|
|
|
|
|
format(name,"%-10s: %s") # hash: "name : Albert" |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# e.g. array: |
49
|
|
|
|
|
|
|
# - 1 |
50
|
|
|
|
|
|
|
format(array,"%d %d %d") # Fails! The array contains only one value, but you request 3 values |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Test first if the array contains 3 values |
53
|
|
|
|
|
|
|
if exists(array.2) |
54
|
|
|
|
|
|
|
format(array,"%d %d %d") |
55
|
|
|
|
|
|
|
end |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Create a string formatted by the usual printf conventions of the C library function sprintf. |
60
|
|
|
|
|
|
|
See L<http://perldoc.perl.org/functions/sprintf.html> for a complete description. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SEE ALSO |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
L<Catmandu::Fix> , L<sprintf> |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |