Checking in changes prior to tagging of version 0.40_04. Changelog diff is:
[gitmo/Mouse.git] / lib / Mouse / Meta / Method / Delegation.pm
1 package Mouse::Meta::Method::Delegation;
2 use Mouse::Util; # enables strict and warnings
3 use Scalar::Util qw(blessed);
4
5 sub _generate_delegation{
6     my (undef, $attribute, $metaclass, $reader, $handle_name, $method_to_call) = @_;
7
8     return sub {
9         my $instance = shift;
10         my $proxy    = $instance->$reader();
11
12         my $error = !defined($proxy)                ? ' is not defined'
13                   : ref($proxy) && !blessed($proxy) ? qq{ is not an object (got '$proxy')}
14                                                     : undef;
15         if ($error) {
16             $instance->meta->throw_error(
17                 "Cannot delegate $handle_name to $method_to_call because "
18                     . "the value of "
19                     . $attribute->name
20                     . $error
21              );
22         }
23         $proxy->$method_to_call(@_);
24     };
25 }
26
27
28 1;
29 __END__
30
31 =head1 NAME
32
33 Mouse::Meta::Method::Delegation - A Mouse method generator for delegation methods
34
35 =head1 VERSION
36
37 This document describes Mouse version 0.40_04
38
39 =head1 SEE ALSO
40
41 L<Moose::Meta::Method::Delegation>
42
43 =cut