2 package Class::MOP::Method;
8 use Scalar::Util 'blessed';
10 our $VERSION = '0.63';
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, $code, %params ) = @_;
34 ('CODE' eq ref($code))
35 || confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")";
37 ($params{package_name} && $params{name})
38 || confess "You must supply the package_name and name parameters $UPGRADE_ERROR_TEXT";
42 '$!package_name' => $params{package_name},
43 '$!name' => $params{name},
44 } => blessed($class) || $class;
49 sub body { (shift)->{'&!body'} }
51 # TODO - add associated_class
57 $self->{'$!package_name'} ||= (Class::MOP::get_code_info($self->body))[0];
62 $self->{'$!name'} ||= (Class::MOP::get_code_info($self->body))[1];
65 sub fully_qualified_name {
67 $code->package_name . '::' . $code->name;
71 # the Class::MOP bootstrap
72 # will create this for us
84 Class::MOP::Method - Method Meta Object
88 The Method Protocol is very small, since methods in Perl 5 are just
89 subroutines within the particular package. We provide a very basic
90 introspection interface.
100 This will return a B<Class::MOP::Class> instance which is related
109 =item B<wrap ($code, %params)>
111 This is the basic constructor, it returns a B<Class::MOP::Method>
112 instance which wraps the given C<$code> reference. You can also
113 set the C<package_name> and C<name> attributes using the C<%params>.
114 If these are not set, then thier accessors will attempt to figure
115 it out using the C<Class::MOP::get_code_info> function.
117 =item B<clone (%params)>
119 This will make a copy of the object, allowing you to override
120 any values by stuffing them in C<%params>.
130 This returns the actual CODE reference of the particular instance.
134 This returns the name of the CODE reference.
136 =item B<package_name>
138 This returns the package name that the CODE reference is attached to.
140 =item B<fully_qualified_name>
142 This returns the fully qualified name of the CODE reference.
148 Stevan Little E<lt>stevan@iinteractive.comE<gt>
150 =head1 COPYRIGHT AND LICENSE
152 Copyright 2006-2008 by Infinity Interactive, Inc.
154 L<http://www.iinteractive.com>
156 This library is free software; you can redistribute it and/or modify
157 it under the same terms as Perl itself.