1 package Mouse::Meta::Method::Delegation;
2 use Mouse::Util qw(:meta); # enables strict and warnings
5 sub _generate_delegation{
6 my (undef, $attr, $handle_name, $method_to_call, @curried_args) = @_;
8 my $reader = $attr->get_read_method_ref();
10 my $can_be_optimized = $attr->{_method_delegation_can_be_optimized};
12 if(!defined $can_be_optimized){
13 my $tc = $attr->type_constraint;
15 $attr->{_method_delegation_can_be_optimized} =
16 (defined($tc) && $tc->is_a_type_of('Object'))
17 && ($attr->is_required || $attr->has_default || $attr->has_builder)
18 && ($attr->is_lazy || !$attr->has_clearer);
21 if($can_be_optimized){
22 # need not check the attribute value
24 return shift()->$reader()->$method_to_call(@curried_args, @_);
28 # need to check the attribute value
31 my $proxy = $instance->$reader();
33 my $error = !defined($proxy) ? ' is not defined'
34 : ref($proxy) && !Scalar::Util::blessed($proxy) ? qq{ is not an object (got '$proxy')}
37 $instance->meta->throw_error(
38 "Cannot delegate $handle_name to $method_to_call because "
44 $proxy->$method_to_call(@curried_args, @_);
55 Mouse::Meta::Method::Delegation - A Mouse method generator for delegation methods
59 This document describes Mouse version 0.50_02
63 L<Moose::Meta::Method::Delegation>