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') . ")";
28 ($params{package_name} && $params{name})
29 || confess "You must supply the package_name and name parameters";
33 '$!package_name' => $params{package_name},
34 '$!name' => $params{name},
35 } => blessed($class) || $class;
40 sub body { (shift)->{'&!body'} }
42 # TODO - add associated_class
48 $self->{'$!package_name'} ||= (Class::MOP::get_code_info($self->body))[0];
53 $self->{'$!name'} ||= (Class::MOP::get_code_info($self->body))[1];
56 sub fully_qualified_name {
58 $code->package_name . '::' . $code->name;
62 # the Class::MOP bootstrap
63 # will create this for us
75 Class::MOP::Method - Method Meta Object
79 The Method Protocol is very small, since methods in Perl 5 are just
80 subroutines within the particular package. We provide a very basic
81 introspection interface.
91 This will return a B<Class::MOP::Class> instance which is related
100 =item B<wrap ($code, %params)>
102 This is the basic constructor, it returns a B<Class::MOP::Method>
103 instance which wraps the given C<$code> reference. You can also
104 set the C<package_name> and C<name> attributes using the C<%params>.
105 If these are not set, then thier accessors will attempt to figure
106 it out using the C<Class::MOP::get_code_info> function.
108 =item B<clone (%params)>
110 This will make a copy of the object, allowing you to override
111 any values by stuffing them in C<%params>.
121 This returns the actual CODE reference of the particular instance.
125 This returns the name of the CODE reference.
127 =item B<package_name>
129 This returns the package name that the CODE reference is attached to.
131 =item B<fully_qualified_name>
133 This returns the fully qualified name of the CODE reference.
139 Stevan Little E<lt>stevan@iinteractive.comE<gt>
141 =head1 COPYRIGHT AND LICENSE
143 Copyright 2006-2008 by Infinity Interactive, Inc.
145 L<http://www.iinteractive.com>
147 This library is free software; you can redistribute it and/or modify
148 it under the same terms as Perl itself.