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