| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Fix::move_field; |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
106210
|
use Catmandu::Sane; |
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
35
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
36
|
use Moo; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
29
|
|
|
8
|
5
|
|
|
5
|
|
3688
|
use Catmandu::Util::Path qw(as_path); |
|
|
5
|
|
|
|
|
14
|
|
|
|
5
|
|
|
|
|
303
|
|
|
9
|
5
|
|
|
5
|
|
40
|
use Clone qw(clone); |
|
|
5
|
|
|
|
|
21
|
|
|
|
5
|
|
|
|
|
351
|
|
|
10
|
5
|
|
|
5
|
|
40
|
use namespace::clean; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
24
|
|
|
11
|
5
|
|
|
5
|
|
3432
|
use Catmandu::Fix::Has; |
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
34
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has old_path => (fix_arg => 1); |
|
16
|
|
|
|
|
|
|
has new_path => (fix_arg => 1); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_fixer { |
|
19
|
8
|
|
|
8
|
|
82
|
my ($self) = @_; |
|
20
|
8
|
|
|
|
|
40
|
my $old_path = as_path($self->old_path); |
|
21
|
8
|
|
|
|
|
2456
|
my $new_path = as_path($self->new_path); |
|
22
|
8
|
|
|
|
|
154
|
my $getter = $old_path->getter; |
|
23
|
8
|
|
|
|
|
40
|
my $deleter = $old_path->deleter; |
|
24
|
8
|
|
|
|
|
178
|
my $creator = $new_path->creator; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub { |
|
27
|
10
|
|
|
10
|
|
19
|
my $data = $_[0]; |
|
28
|
10
|
|
|
|
|
23
|
my $values = [map {clone($_)} @{$getter->($data)}]; |
|
|
10
|
|
|
|
|
80
|
|
|
|
10
|
|
|
|
|
169
|
|
|
29
|
10
|
|
|
|
|
196
|
$deleter->($data); |
|
30
|
10
|
|
|
|
|
29
|
while (@$values) { |
|
31
|
10
|
|
|
|
|
220
|
$data = $creator->($data, shift @$values); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
10
|
|
|
|
|
171
|
$data; |
|
34
|
8
|
|
|
|
|
115
|
}; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=pod |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Catmandu::Fix::move_field - move a field to another place in the data structure |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Move single fields |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Move 'foo.bar' to 'bar.foo' |
|
52
|
|
|
|
|
|
|
move_field(foo.bar, bar.foo) |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Move multipe fields |
|
55
|
|
|
|
|
|
|
# Data: |
|
56
|
|
|
|
|
|
|
# a: |
|
57
|
|
|
|
|
|
|
# b: test1 |
|
58
|
|
|
|
|
|
|
# c: test2 |
|
59
|
|
|
|
|
|
|
move_field(a,z) # -> Move all the 'a' to 'z' |
|
60
|
|
|
|
|
|
|
# z: |
|
61
|
|
|
|
|
|
|
# b: test1 |
|
62
|
|
|
|
|
|
|
# c: test2 |
|
63
|
|
|
|
|
|
|
# Data: |
|
64
|
|
|
|
|
|
|
# a: |
|
65
|
|
|
|
|
|
|
# b: test1 |
|
66
|
|
|
|
|
|
|
# c: test2 |
|
67
|
|
|
|
|
|
|
move_field(a,.) # -> Move the fields 'b' and 'c' to the root |
|
68
|
|
|
|
|
|
|
# b: test1 |
|
69
|
|
|
|
|
|
|
# c: test2 |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
L<Catmandu::Fix> |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |