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