Add Moose::Meta::Method::Delegation and use it for delegation methods
[gitmo/Moose.git] / lib / Moose / Meta / Method / Delegation.pm
1
2 package Moose::Meta::Method::Delegation;
3
4 use strict;
5 use warnings;
6
7 use Carp         'confess';
8 use Scalar::Util 'blessed', 'weaken';
9
10 our $VERSION   = '0.57';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
13
14 use base 'Moose::Meta::Method';
15
16
17 sub new {
18     my $class   = shift;
19     my %options = @_;
20
21     (exists $options{attribute})
22         || confess "You must supply an attribute to construct with";
23
24     (blessed($options{attribute}) && $options{attribute}->isa('Class::MOP::Attribute'))
25         || confess "You must supply an attribute which is a 'Class::MOP::Attribute' instance";
26
27     ($options{package_name} && $options{name})
28         || confess "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT";
29
30     my $self = $class->_new(\%options);
31
32     weaken($self->{'attribute'});
33
34     return $self;
35 }
36
37 1;