line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Focus::Lens::Accessor; |
2
|
4
|
|
|
4
|
|
1792
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
108
|
|
3
|
4
|
|
|
4
|
|
14
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
85
|
|
4
|
4
|
|
|
4
|
|
15
|
use parent qw(Data::Focus::Lens); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
16
|
|
5
|
4
|
|
|
4
|
|
1007
|
use Data::Focus::LensMaker (); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
56
|
|
6
|
4
|
|
|
4
|
|
14
|
use Carp; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
787
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @CARP_NOT = qw(Data::Focus::Lens Data::Focus); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
17
|
|
|
17
|
1
|
15251
|
my ($class, %args) = @_; |
12
|
17
|
50
|
|
|
|
51
|
croak "method is mandatory" if !defined($args{method}); |
13
|
17
|
|
|
|
|
64
|
my $self = bless { |
14
|
|
|
|
|
|
|
method => $args{method} |
15
|
|
|
|
|
|
|
}, $class; |
16
|
17
|
|
|
|
|
80
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _getter { |
20
|
847
|
|
|
847
|
|
720
|
my ($self, $target) = @_; |
21
|
847
|
|
|
|
|
1058
|
my $method = $self->{method}; |
22
|
847
|
100
|
|
|
|
709
|
if(!eval { $target->can($method) }) { |
|
847
|
|
|
|
|
3685
|
|
23
|
618
|
|
|
|
|
1684
|
return (); |
24
|
|
|
|
|
|
|
} |
25
|
229
|
|
|
|
|
336
|
my $v = $target->$method; |
26
|
228
|
|
|
|
|
1057
|
return $v; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _setter { |
30
|
777
|
|
|
777
|
|
725
|
my ($self, $target, $v) = @_; |
31
|
777
|
100
|
|
|
|
1592
|
return $target if @_ <= 2; |
32
|
201
|
|
|
|
|
190
|
my $method = $self->{method}; |
33
|
201
|
|
|
|
|
276
|
$target->$method($v); |
34
|
201
|
|
|
|
|
885
|
return $target; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Data::Focus::LensMaker::make_lens_from_accessors(\&_getter, \&_setter); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
__END__ |