line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
88016
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Catmandu::Util::Path qw(as_path); |
7
|
1
|
|
|
1
|
|
361
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
8
|
1
|
|
|
1
|
|
6
|
use Catmandu::Util qw(is_hash_ref is_array_ref); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
305
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
10
|
1
|
|
|
1
|
|
5
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
11
|
1
|
|
|
1
|
|
603
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
13
|
|
|
|
|
|
|
has search => (fix_arg => 1); |
14
|
|
|
|
|
|
|
has replace => (fix_arg => 1); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my ($self) = @_; |
19
|
|
|
|
|
|
|
my $search = $self->search; |
20
|
1
|
|
|
1
|
|
11
|
my $replace = $self->replace; |
21
|
1
|
|
|
|
|
3
|
my $renamer; |
22
|
1
|
|
|
|
|
30
|
$renamer = sub { |
23
|
1
|
|
|
|
|
3
|
my $data = $_[0]; |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
4
|
|
7
|
if (is_hash_ref($data)) { |
26
|
|
|
|
|
|
|
for my $old (keys %$data) { |
27
|
4
|
100
|
|
|
|
13
|
my $new = $old; |
|
|
100
|
|
|
|
|
|
28
|
2
|
|
|
|
|
6
|
my $val = $data->{$old}; |
29
|
2
|
|
|
|
|
12
|
if ($new =~ s/$search/$replace/g) { |
30
|
2
|
|
|
|
|
4
|
delete $data->{$old}; |
31
|
2
|
50
|
|
|
|
29
|
$data->{$new} = $val; |
32
|
2
|
|
|
|
|
5
|
} |
33
|
2
|
|
|
|
|
5
|
$renamer->($val); |
34
|
|
|
|
|
|
|
} |
35
|
2
|
|
|
|
|
6
|
} |
36
|
|
|
|
|
|
|
elsif (is_array_ref($data)) { |
37
|
|
|
|
|
|
|
$renamer->($_) for @$data; |
38
|
|
|
|
|
|
|
} |
39
|
1
|
|
|
|
|
5
|
|
40
|
|
|
|
|
|
|
$data; |
41
|
|
|
|
|
|
|
}; |
42
|
4
|
|
|
|
|
25
|
|
43
|
1
|
|
|
|
|
6
|
as_path($self->path)->updater($renamer); |
44
|
|
|
|
|
|
|
} |
45
|
1
|
|
|
|
|
6
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=pod |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Catmandu::Fix::rename - rename fields with a regex |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SYNOPSIS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# dotted => {'ns.foo' => 'val', list => {'ns.bar' => 'val'}} |
58
|
|
|
|
|
|
|
rename(dotted, '\.', '-') |
59
|
|
|
|
|
|
|
# dotted => {'ns-foo' => 'val', list => {'ns-bar' => 'val'}} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SEE ALSO |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
L<Catmandu::Fix> |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |