2 package Class::MOP::Method;
8 use Scalar::Util 'reftype', 'blessed';
10 our $VERSION = '0.07';
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;
23 my ( $class, $code, %params ) = @_;
25 ('CODE' eq (reftype($code) || ''))
26 || confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")";
30 '$!package_name' => $params{package_name},
31 '$!name' => $params{name},
32 } => blessed($class) || $class;
37 sub body { (shift)->{'&!body'} }
39 # TODO - add associated_class
45 $self->{'$!package_name'} ||= (Class::MOP::get_code_info($self->body))[0];
50 $self->{'$!name'} ||= (Class::MOP::get_code_info($self->body))[1];
53 sub fully_qualified_name {
55 $code->package_name . '::' . $code->name;
59 # the Class::MOP bootstrap
60 # will create this for us
72 Class::MOP::Method - Method Meta Object
76 The Method Protocol is very small, since methods in Perl 5 are just
77 subroutines within the particular package. We provide a very basic
78 introspection interface.
88 This will return a B<Class::MOP::Class> instance which is related
97 =item B<wrap ($code, %params)>
99 This is the basic constructor, it returns a B<Class::MOP::Method>
100 instance which wraps the given C<$code> reference. You can also
101 set the C<package_name> and C<name> attributes using the C<%params>.
102 If these are not set, then thier accessors will attempt to figure
103 it out using the C<Class::MOP::get_code_info> function.
105 =item B<clone (%params)>
107 This will make a copy of the object, allowing you to override
108 any values by stuffing them in C<%params>.
118 This returns the actual CODE reference of the particular instance.
122 This returns the name of the CODE reference.
124 =item B<package_name>
126 This returns the package name that the CODE reference is attached to.
128 =item B<fully_qualified_name>
130 This returns the fully qualified name of the CODE reference.
136 Stevan Little E<lt>stevan@iinteractive.comE<gt>
138 =head1 COPYRIGHT AND LICENSE
140 Copyright 2006-2008 by Infinity Interactive, Inc.
142 L<http://www.iinteractive.com>
144 This library is free software; you can redistribute it and/or modify
145 it under the same terms as Perl itself.