Actually implement associated_attribute for delegation methods, and
[gitmo/Moose.git] / lib / Moose / Meta / Method / Delegation.pm
CommitLineData
a05f85c1 1
2package Moose::Meta::Method::Delegation;
3
4use strict;
5use warnings;
6
7use Carp 'confess';
8use Scalar::Util 'blessed', 'weaken';
9
10our $VERSION = '0.57';
11$VERSION = eval $VERSION;
12our $AUTHORITY = 'cpan:STEVAN';
13
14use base 'Moose::Meta::Method';
15
16
17sub new {
18 my $class = shift;
19 my %options = @_;
20
21 (exists $options{attribute})
22 || confess "You must supply an attribute to construct with";
23
01cd78f8 24 (blessed($options{attribute}) && $options{attribute}->isa('Moose::Meta::Attribute'))
25 || confess "You must supply an attribute which is a 'Moose::Meta::Attribute' instance";
a05f85c1 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
01cd78f8 37sub _new {
38 my $class = shift;
39 my $options = @_ == 1 ? $_[0] : {@_};
40
41 return bless $options, $class;
42}
43
44sub associated_attribute { (shift)->{'attribute'} }
45
a05f85c1 461;
01cd78f8 47
48__END__
49
50=pod
51
52=head1 NAME
53
54Moose::Meta::Method::Delegation - A Moose Method metaclass for delegation methods
55
56=head1 DESCRIPTION
57
58This is a subclass of L<Moose::Meta::Method> for delegation
59methods.
60
61=head1 METHODS
62
63=over 4
64
65=item B<new (%options)>
66
67This creates the method based on the criteria in C<%options>,
68these options are:
69
70=over 4
71
72=item I<attribute>
73
74This must be an instance of C<Moose::Meta::Attribute> which this
75accessor is being generated for. This paramter is B<required>.
76
77=back
78
79=item B<associated_attribute>
80
81Returns the attribute associated with this method.
82
83=back
84
85=head1 BUGS
86
87All complex software has bugs lurking in it, and this module is no
88exception. If you find a bug please either email me, or add the bug
89to cpan-RT.
90
91=head1 AUTHOR
92
93Dave Rolsky E<lt>autarch@urth.orgE<gt>
94
95=head1 COPYRIGHT AND LICENSE
96
97Copyright 2008 by Infinity Interactive, Inc.
98
99L<http://www.iinteractive.com>
100
101This library is free software; you can redistribute it and/or modify
102it under the same terms as Perl itself.
103
104=cut