2 package Class::MOP::Method;
8 use Scalar::Util 'weaken';
10 our $VERSION = '0.65';
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Class::MOP::Object';
16 # if poked in the right way,
17 # they should act like CODE refs.
18 use overload '&{}' => sub { $_[0]->body }, fallback => 1;
20 our $UPGRADE_ERROR_TEXT = q{
21 ---------------------------------------------------------
22 NOTE: this error is likely not an error, but a regression
23 caused by the latest upgrade to Moose/Class::MOP. Consider
24 upgrading any MooseX::* modules to their latest versions
25 before spending too much time chasing this one down.
26 ---------------------------------------------------------
32 my ( $class, @args ) = @_;
34 unshift @args, 'body' if @args % 2 == 1;
37 my $code = $params{body};
39 ('CODE' eq ref($code))
40 || confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")";
42 ($params{package_name} && $params{name})
43 || confess "You must supply the package_name and name parameters $UPGRADE_ERROR_TEXT";
47 'associated_metaclass' => $params{associated_metaclass},
48 'package_name' => $params{package_name},
49 'name' => $params{name},
50 } => ref($class) || $class;
52 weaken($self->{associated_metaclass}) if $self->{associated_metaclass};
59 sub body { (shift)->{'body'} }
61 sub associated_metaclass { shift->{'associated_metaclass'} }
64 my ( $self, $class ) = @_;
65 $self->{associated_metaclass} = $class;
66 weaken($self->{associated_metaclass});
69 sub detach_from_class {
71 delete $self->{associated_metaclass};
76 $self->{'package_name'} ||= (Class::MOP::get_code_info($self->body))[0];
81 $self->{'name'} ||= (Class::MOP::get_code_info($self->body))[1];
84 sub fully_qualified_name {
86 $code->package_name . '::' . $code->name;
90 # the Class::MOP bootstrap
91 # will create this for us
103 Class::MOP::Method - Method Meta Object
107 The Method Protocol is very small, since methods in Perl 5 are just
108 subroutines within the particular package. We provide a very basic
109 introspection interface.
119 This will return a B<Class::MOP::Class> instance which is related
128 =item B<wrap ($code, %params)>
130 This is the basic constructor, it returns a B<Class::MOP::Method>
131 instance which wraps the given C<$code> reference. You can also
132 set the C<package_name> and C<name> attributes using the C<%params>.
133 If these are not set, then thier accessors will attempt to figure
134 it out using the C<Class::MOP::get_code_info> function.
136 =item B<clone (%params)>
138 This will make a copy of the object, allowing you to override
139 any values by stuffing them in C<%params>.
149 This returns the actual CODE reference of the particular instance.
153 This returns the name of the CODE reference.
155 =item B<associated_metaclass>
157 The metaclass of the method
159 =item B<package_name>
161 This returns the package name that the CODE reference is attached to.
163 =item B<fully_qualified_name>
165 This returns the fully qualified name of the CODE reference.
173 =item B<attach_to_class>
175 Sets the associated metaclass
177 =item B<detach_from_class>
179 Disassociates the method from the metaclass
185 Stevan Little E<lt>stevan@iinteractive.comE<gt>
187 =head1 COPYRIGHT AND LICENSE
189 Copyright 2006-2008 by Infinity Interactive, Inc.
191 L<http://www.iinteractive.com>
193 This library is free software; you can redistribute it and/or modify
194 it under the same terms as Perl itself.