line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Focus::Lens::HashArray::Recurse; |
2
|
5
|
|
|
5
|
|
3585
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
226
|
|
3
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
169
|
|
4
|
5
|
|
|
5
|
|
24
|
use parent qw(Data::Focus::Lens); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
27
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
24
|
|
|
24
|
1
|
17669
|
my ($class, %args) = @_; |
8
|
24
|
|
|
|
|
137
|
my $self = bless { |
9
|
|
|
|
|
|
|
immutable => !!$args{immutable} |
10
|
|
|
|
|
|
|
}, $class; |
11
|
24
|
|
|
|
|
65
|
return $self; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _set_array { |
15
|
703
|
|
|
703
|
|
820
|
my ($self, $whole, @parts) = @_; |
16
|
703
|
100
|
|
|
|
1609
|
return $whole if !@parts; |
17
|
422
|
100
|
|
|
|
635
|
if($self->{immutable}) { |
18
|
210
|
|
|
|
|
508
|
return \@parts; |
19
|
|
|
|
|
|
|
}else { |
20
|
212
|
|
|
|
|
320
|
@$whole = @parts; |
21
|
212
|
|
|
|
|
554
|
return $whole; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _set_hash { |
26
|
843
|
|
|
843
|
|
916
|
my ($self, $whole, $keys, @parts) = @_; |
27
|
843
|
100
|
|
|
|
1884
|
return $whole if !@parts; |
28
|
562
|
100
|
|
|
|
1354
|
my $ret = $self->{immutable} ? {%$whole} : $whole; |
29
|
562
|
|
|
|
|
1676
|
$ret->{$keys->[$_]} = $parts[$_] foreach 0 .. $#$keys; |
30
|
562
|
|
|
|
|
1492
|
return $ret; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub apply_lens { |
34
|
3943
|
|
|
3943
|
1
|
3663
|
my ($self, $app_class, $part_mapper, $data) = @_; |
35
|
3943
|
|
|
|
|
3735
|
my $type = ref($data); |
36
|
3943
|
100
|
|
|
|
6083
|
if($type eq "ARRAY") { |
|
|
100
|
|
|
|
|
|
37
|
783
|
|
|
|
|
940
|
my @fparts = map { $self->apply_lens($app_class, $part_mapper, $_) } @$data; |
|
1573
|
|
|
|
|
1905
|
|
38
|
|
|
|
|
|
|
return $app_class->build(sub { |
39
|
703
|
|
|
703
|
|
970
|
$self->_set_array($data, @_); |
40
|
783
|
|
|
|
|
2608
|
}, @fparts); |
41
|
|
|
|
|
|
|
}elsif($type eq "HASH") { |
42
|
915
|
|
|
|
|
1668
|
my @keys = keys %$data; |
43
|
915
|
|
|
|
|
877
|
my @fparts = map { $self->apply_lens($app_class, $part_mapper, $_) } @{$data}{@keys}; |
|
915
|
|
|
|
|
1195
|
|
|
915
|
|
|
|
|
1167
|
|
44
|
|
|
|
|
|
|
return $app_class->build(sub { |
45
|
843
|
|
|
843
|
|
1265
|
$self->_set_hash($data, \@keys, @_); |
46
|
915
|
|
|
|
|
3224
|
}, @fparts); |
47
|
|
|
|
|
|
|
}else { |
48
|
2245
|
|
|
|
|
3690
|
return $part_mapper->($data); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
__END__ |