2 package Class::MOP::Method;
8 use Scalar::Util 'blessed';
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 'package_name' => $params{package_name},
48 'name' => $params{name},
49 } => blessed($class) || $class;
54 sub body { (shift)->{'body'} }
56 # TODO - add associated_class
62 $self->{'package_name'} ||= (Class::MOP::get_code_info($self->body))[0];
67 $self->{'name'} ||= (Class::MOP::get_code_info($self->body))[1];
70 sub fully_qualified_name {
72 $code->package_name . '::' . $code->name;
76 # the Class::MOP bootstrap
77 # will create this for us
89 Class::MOP::Method - Method Meta Object
93 The Method Protocol is very small, since methods in Perl 5 are just
94 subroutines within the particular package. We provide a very basic
95 introspection interface.
105 This will return a B<Class::MOP::Class> instance which is related
114 =item B<wrap ($code, %params)>
116 This is the basic constructor, it returns a B<Class::MOP::Method>
117 instance which wraps the given C<$code> reference. You can also
118 set the C<package_name> and C<name> attributes using the C<%params>.
119 If these are not set, then thier accessors will attempt to figure
120 it out using the C<Class::MOP::get_code_info> function.
122 =item B<clone (%params)>
124 This will make a copy of the object, allowing you to override
125 any values by stuffing them in C<%params>.
135 This returns the actual CODE reference of the particular instance.
139 This returns the name of the CODE reference.
141 =item B<package_name>
143 This returns the package name that the CODE reference is attached to.
145 =item B<fully_qualified_name>
147 This returns the fully qualified name of the CODE reference.
153 Stevan Little E<lt>stevan@iinteractive.comE<gt>
155 =head1 COPYRIGHT AND LICENSE
157 Copyright 2006-2008 by Infinity Interactive, Inc.
159 L<http://www.iinteractive.com>
161 This library is free software; you can redistribute it and/or modify
162 it under the same terms as Perl itself.