line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Focus::Lens::HashArray::Recurse; |
2
|
5
|
|
|
5
|
|
2129
|
use strict; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
139
|
|
3
|
5
|
|
|
5
|
|
16
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
115
|
|
4
|
5
|
|
|
5
|
|
17
|
use parent qw(Data::Focus::Lens); |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
20
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
24
|
|
|
24
|
1
|
12786
|
my ($class, %args) = @_; |
8
|
24
|
|
|
|
|
117
|
my $self = bless { |
9
|
|
|
|
|
|
|
immutable => !!$args{immutable} |
10
|
|
|
|
|
|
|
}, $class; |
11
|
24
|
|
|
|
|
60
|
return $self; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _set_array { |
15
|
703
|
|
|
703
|
|
748
|
my ($self, $whole, @parts) = @_; |
16
|
703
|
100
|
|
|
|
1334
|
return $whole if !@parts; |
17
|
422
|
100
|
|
|
|
571
|
if($self->{immutable}) { |
18
|
210
|
|
|
|
|
490
|
return \@parts; |
19
|
|
|
|
|
|
|
}else { |
20
|
212
|
|
|
|
|
351
|
@$whole = @parts; |
21
|
212
|
|
|
|
|
515
|
return $whole; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _set_hash { |
26
|
843
|
|
|
843
|
|
989
|
my ($self, $whole, $keys, @parts) = @_; |
27
|
843
|
100
|
|
|
|
1628
|
return $whole if !@parts; |
28
|
562
|
100
|
|
|
|
1207
|
my $ret = $self->{immutable} ? {%$whole} : $whole; |
29
|
562
|
|
|
|
|
1531
|
$ret->{$keys->[$_]} = $parts[$_] foreach 0 .. $#$keys; |
30
|
562
|
|
|
|
|
1372
|
return $ret; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub apply_lens { |
34
|
3943
|
|
|
3943
|
1
|
3538
|
my ($self, $app_class, $part_mapper, $data) = @_; |
35
|
3943
|
|
|
|
|
3154
|
my $type = ref($data); |
36
|
3943
|
100
|
|
|
|
5101
|
if($type eq "ARRAY") { |
|
|
100
|
|
|
|
|
|
37
|
783
|
|
|
|
|
753
|
my @fparts = map { $self->apply_lens($app_class, $part_mapper, $_) } @$data; |
|
1573
|
|
|
|
|
1666
|
|
38
|
|
|
|
|
|
|
return $app_class->build(sub { |
39
|
703
|
|
|
703
|
|
877
|
$self->_set_array($data, @_); |
40
|
783
|
|
|
|
|
2114
|
}, @fparts); |
41
|
|
|
|
|
|
|
}elsif($type eq "HASH") { |
42
|
915
|
|
|
|
|
1544
|
my @keys = keys %$data; |
43
|
915
|
|
|
|
|
762
|
my @fparts = map { $self->apply_lens($app_class, $part_mapper, $_) } @{$data}{@keys}; |
|
915
|
|
|
|
|
1022
|
|
|
915
|
|
|
|
|
986
|
|
44
|
|
|
|
|
|
|
return $app_class->build(sub { |
45
|
843
|
|
|
843
|
|
1150
|
$self->_set_hash($data, \@keys, @_); |
46
|
915
|
|
|
|
|
2891
|
}, @fparts); |
47
|
|
|
|
|
|
|
}else { |
48
|
2245
|
|
|
|
|
3296
|
return $part_mapper->($data); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
__END__ |