line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Focus::Lens::HashArray::All; |
2
|
5
|
|
|
5
|
|
2180
|
use strict; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
135
|
|
3
|
5
|
|
|
5
|
|
15
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
105
|
|
4
|
5
|
|
|
5
|
|
14
|
use parent qw(Data::Focus::Lens); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
15
|
|
5
|
5
|
|
|
5
|
|
204
|
use Carp; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
1575
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
20
|
|
|
20
|
1
|
14250
|
my ($class, %args) = @_; |
9
|
20
|
|
|
|
|
133
|
return bless { |
10
|
|
|
|
|
|
|
immutable => !!$args{immutable} |
11
|
|
|
|
|
|
|
}, $class; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _set_array { |
15
|
561
|
|
|
561
|
|
619
|
my ($self, $whole, @parts) = @_; |
16
|
561
|
100
|
|
|
|
1176
|
return $whole if !@parts; |
17
|
281
|
100
|
|
|
|
406
|
if($self->{immutable}) { |
18
|
140
|
|
|
|
|
455
|
return \@parts; |
19
|
|
|
|
|
|
|
}else { |
20
|
141
|
|
|
|
|
182
|
@$whole = @parts; |
21
|
141
|
|
|
|
|
321
|
return $whole; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _set_hash { |
26
|
561
|
|
|
561
|
|
530
|
my ($self, $whole, $keys, @parts) = @_; |
27
|
561
|
100
|
|
|
|
1202
|
return $whole if !@parts; |
28
|
281
|
100
|
|
|
|
701
|
my $ret = $self->{immutable} ? {%$whole} : $whole; |
29
|
281
|
|
|
|
|
875
|
$ret->{$keys->[$_]} = $parts[$_] foreach 0 .. $#$keys; |
30
|
281
|
|
|
|
|
730
|
return $ret; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub apply_lens { |
34
|
2372
|
|
|
2372
|
1
|
2338
|
my ($self, $app_class, $part_mapper, $whole) = @_; |
35
|
2372
|
|
|
|
|
2279
|
my $type = ref($whole); |
36
|
2372
|
100
|
|
|
|
3325
|
if($type eq "ARRAY") { |
|
|
100
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return $app_class->build(sub { |
38
|
561
|
|
|
561
|
|
716
|
$self->_set_array($whole, @_) |
39
|
594
|
|
|
|
|
1447
|
}, map { $part_mapper->($_) } @$whole); |
|
1191
|
|
|
|
|
1695
|
|
40
|
|
|
|
|
|
|
}elsif($type eq "HASH") { |
41
|
594
|
|
|
|
|
950
|
my @keys = keys %$whole; |
42
|
|
|
|
|
|
|
return $app_class->build(sub { |
43
|
561
|
|
|
561
|
|
823
|
$self->_set_hash($whole, \@keys, @_) |
44
|
594
|
|
|
|
|
1301
|
}, map { $part_mapper->($_) } @{$whole}{@keys}); |
|
598
|
|
|
|
|
919
|
|
|
594
|
|
|
|
|
1040
|
|
45
|
|
|
|
|
|
|
}else { |
46
|
1184
|
|
|
|
|
1984
|
return $app_class->pure($whole); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
__END__ |