line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mouse::Meta::Method::Delegation; |
2
|
6
|
|
|
6
|
|
22
|
use Mouse::Util qw(:meta); # enables strict and warnings |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
32
|
|
3
|
6
|
|
|
6
|
|
22
|
use Scalar::Util; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
1881
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub _generate_delegation{ |
6
|
21
|
|
|
21
|
|
29
|
my (undef, $attr, $handle_name, $method_to_call) = @_; |
7
|
|
|
|
|
|
|
|
8
|
21
|
|
|
|
|
16
|
my @curried_args; |
9
|
21
|
100
|
|
|
|
44
|
if(ref($method_to_call) eq 'ARRAY'){ |
10
|
2
|
|
|
|
|
2
|
($method_to_call, @curried_args) = @{$method_to_call}; |
|
2
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# If it has a reader, we must use it to make method modifiers work |
14
|
21
|
|
66
|
|
|
44
|
my $reader = $attr->get_read_method() || $attr->get_read_method_ref(); |
15
|
|
|
|
|
|
|
|
16
|
21
|
|
|
|
|
25
|
my $can_be_optimized = $attr->{_mouse_cache_method_delegation_can_be_optimized}; |
17
|
|
|
|
|
|
|
|
18
|
21
|
100
|
|
|
|
36
|
if(!defined $can_be_optimized){ |
19
|
13
|
|
|
|
|
23
|
my $tc = $attr->type_constraint; |
20
|
|
|
|
|
|
|
$attr->{_mouse_cache_method_delegation_can_be_optimized} = |
21
|
13
|
|
66
|
|
|
60
|
(defined($tc) && $tc->is_a_type_of('Object')) |
22
|
|
|
|
|
|
|
&& ($attr->is_required || $attr->has_default || $attr->has_builder) |
23
|
|
|
|
|
|
|
&& ($attr->is_lazy || !$attr->has_clearer); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
21
|
100
|
|
|
|
34
|
if($can_be_optimized){ |
27
|
|
|
|
|
|
|
# need not check the attribute value |
28
|
|
|
|
|
|
|
return sub { |
29
|
2
|
|
|
2
|
|
370
|
return shift()->$reader()->$method_to_call(@curried_args, @_); |
|
|
|
|
1
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
1
|
|
|
|
30
|
5
|
|
|
|
|
49
|
}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
|
|
|
|
|
|
# need to check the attribute value |
34
|
|
|
|
|
|
|
return sub { |
35
|
19
|
|
|
19
|
|
10361
|
my $instance = shift; |
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
0
|
|
|
|
36
|
19
|
|
|
|
|
61
|
my $proxy = $instance->$reader(); |
37
|
|
|
|
|
|
|
|
38
|
19
|
100
|
66
|
|
|
147
|
my $error = !defined($proxy) ? ' is not defined' |
|
|
100
|
|
|
|
|
|
39
|
|
|
|
|
|
|
: ref($proxy) && !Scalar::Util::blessed($proxy) ? qq{ is not an object (got '$proxy')} |
40
|
|
|
|
|
|
|
: undef; |
41
|
19
|
100
|
|
|
|
40
|
if ($error) { |
42
|
4
|
|
|
|
|
10
|
$instance->meta->throw_error( |
43
|
|
|
|
|
|
|
"Cannot delegate $handle_name to $method_to_call because " |
44
|
|
|
|
|
|
|
. "the value of " |
45
|
|
|
|
|
|
|
. $attr->name |
46
|
|
|
|
|
|
|
. $error |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
} |
49
|
15
|
|
|
|
|
56
|
$proxy->$method_to_call(@curried_args, @_); |
50
|
16
|
|
|
|
|
159
|
}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
__END__ |