line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
97488
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Catmandu::Util::Path qw(as_path); |
7
|
1
|
|
|
1
|
|
360
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
75
|
|
8
|
1
|
|
|
1
|
|
7
|
use Catmandu::Util qw(is_hash_ref is_array_ref); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
299
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
10
|
1
|
|
|
1
|
|
4
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
11
|
1
|
|
|
1
|
|
605
|
|
|
1
|
|
|
|
|
1
|
|
|
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
|
|
|
|
|
4
|
my $renamer; |
22
|
1
|
|
|
|
|
30
|
$renamer = sub { |
23
|
1
|
|
|
|
|
3
|
my $data = $_[0]; |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
4
|
|
5
|
if (is_hash_ref($data)) { |
26
|
|
|
|
|
|
|
for my $old (keys %$data) { |
27
|
4
|
100
|
|
|
|
14
|
my $new = $old; |
|
|
100
|
|
|
|
|
|
28
|
2
|
|
|
|
|
7
|
my $val = $data->{$old}; |
29
|
2
|
|
|
|
|
4
|
if ($new =~ s/$search/$replace/g) { |
30
|
2
|
|
|
|
|
4
|
delete $data->{$old}; |
31
|
2
|
50
|
|
|
|
33
|
$data->{$new} = $val; |
32
|
2
|
|
|
|
|
31
|
} |
33
|
2
|
|
|
|
|
5
|
$renamer->($val); |
34
|
|
|
|
|
|
|
} |
35
|
2
|
|
|
|
|
7
|
} |
36
|
|
|
|
|
|
|
elsif (is_array_ref($data)) { |
37
|
|
|
|
|
|
|
$renamer->($_) for @$data; |
38
|
|
|
|
|
|
|
} |
39
|
1
|
|
|
|
|
4
|
|
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 |