line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Focus::Lens::Composite; |
2
|
29
|
|
|
29
|
|
189
|
use strict; |
|
29
|
|
|
|
|
49
|
|
|
29
|
|
|
|
|
790
|
|
3
|
29
|
|
|
29
|
|
103
|
use warnings; |
|
29
|
|
|
|
|
34
|
|
|
29
|
|
|
|
|
613
|
|
4
|
29
|
|
|
29
|
|
11469
|
use parent qw(Data::Focus::Lens); |
|
29
|
|
|
|
|
6669
|
|
|
29
|
|
|
|
|
110
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
20
|
|
|
20
|
1
|
3689
|
my ($class, @lenses) = @_; |
8
|
20
|
|
|
|
|
61
|
require Data::Focus; |
9
|
20
|
|
|
|
|
53
|
$_ = Data::Focus->coerce_to_lens($_) for @lenses; |
10
|
20
|
|
|
|
|
111
|
return bless \@lenses, $class; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
## class method: internal use only. |
14
|
|
|
|
|
|
|
sub apply_composite_lens { |
15
|
106
|
|
|
106
|
0
|
150
|
my (undef, $lenses, $applicative_class, $part_mapper, $whole) = @_; |
16
|
106
|
|
|
|
|
219
|
my $top_lens = $lenses->[0]; |
17
|
106
|
100
|
|
|
|
204
|
if(!defined($top_lens)) { |
18
|
44
|
|
|
|
|
69
|
return $part_mapper->($whole); |
19
|
|
|
|
|
|
|
} |
20
|
62
|
|
|
|
|
94
|
foreach my $lens (reverse @{$lenses}[1 .. $#$lenses]) { |
|
62
|
|
|
|
|
98
|
|
21
|
87
|
|
|
|
|
78
|
my $cur_part_mapper = $part_mapper; |
22
|
87
|
|
|
121
|
|
253
|
$part_mapper = sub { $lens->apply_lens($applicative_class, $cur_part_mapper, shift) }; |
|
121
|
|
|
|
|
252
|
|
23
|
|
|
|
|
|
|
} |
24
|
62
|
|
|
|
|
152
|
return $top_lens->apply_lens($applicative_class, $part_mapper, $whole); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub apply_lens { |
28
|
21
|
|
|
21
|
1
|
59
|
ref($_[0])->apply_composite_lens(@_); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
1; |
33
|
|
|
|
|
|
|
__END__ |