| 1 | package Data::Focus::Lens::Composite; | ||||||||||
| 2 | 29 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 29 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 29 | ▶ | use parent qw(Data::Focus::Lens); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 20 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 7 | 20 | my ($class, @lenses) = @_; | |||||||||
| 8 | 20 | require Data::Focus; | |||||||||
| 9 | 20 | $_ = Data::Focus->coerce_to_lens($_) for @lenses; | |||||||||
| 10 | 20 | return bless \@lenses, $class; | |||||||||
| 11 | } | ||||||||||
| 12 | |||||||||||
| 13 | ## class method: internal use only. | ||||||||||
| 14 | 106 | ▶ | sub apply_composite_lens { | ||||||||
|
Subroutine
apply_composite_lens: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 15 | 106 | my (undef, $lenses, $applicative_class, $part_mapper, $whole) = @_; | |||||||||
| 16 | 106 | my $top_lens = $lenses->[0]; | |||||||||
| 17 | 106 | ▶ | if(!defined($top_lens)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 44 | return $part_mapper->($whole); | |||||||||
| 19 | } | ||||||||||
| 20 | 62 | foreach my $lens (reverse @{$lenses}[1 .. $#$lenses]) { | |||||||||
| 21 | 87 | my $cur_part_mapper = $part_mapper; | |||||||||
| 22 | 87 | ▶ | $part_mapper = sub { $lens->apply_lens($applicative_class, $cur_part_mapper, shift) }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 23 | } | ||||||||||
| 24 | 62 | return $top_lens->apply_lens($applicative_class, $part_mapper, $whole); | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 21 | ▶ | sub apply_lens { | ||||||||
|
Subroutine
apply_lens: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 28 | 21 | ref($_[0])->apply_composite_lens(@_); | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | 29 | 1; | |||||||||
| 33 | __END__ | ||||||||||