2 package Class::MOP::Method::Meta;
8 use Scalar::Util 'blessed';
10 our $VERSION = '1.08';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
14 use constant DEBUG_NO_META => $ENV{DEBUG_NO_META};
16 use base 'Class::MOP::Method';
18 sub _generate_meta_method {
19 my $method_self = shift;
20 my $metaclass = shift;
22 # this will be compiled out if the env var wasn't set
25 # it's okay if we installed a meta method in a subclass of a class
26 # with a legitimate meta method (we'll still die if we install a
27 # meta method in a subclass of a class we installed a meta method
28 # in, since this function is itself defined in Class::MOP)
29 #if (my $meta = try { $self->SUPER::meta }) {
30 #return $meta if $meta->isa('Class::MOP::Class');
32 # it's okay if the test itself calls ->meta, we only care about if
33 # the mop internals call ->meta
34 confess "'meta' method called by MOP internals"
35 if caller =~ /^(?:Class::MOP|metaclass)(?:::|$)/;
37 # we must re-initialize so that it
38 # works as expected in subclasses,
39 # since metaclass instances are
40 # singletons, this is not really a
42 $metaclass->initialize(blessed($_[0]) || $_[0])
47 my ($class, @args) = @_;
49 unshift @args, 'body' if @args % 2 == 1;
51 confess "Overriding the body of meta methods is not allowed"
54 my $metaclass_class = $params{associated_metaclass}->meta;
55 $params{body} = $class->_generate_meta_method($metaclass_class);
56 return $class->SUPER::wrap(%params);
67 Class::MOP::Method::Meta - Method Meta Object for C<meta> methods
71 This is a L<Class::MOP::Method> subclass which represents C<meta>
72 methods installed into classes by Class::MOP.
78 =item B<< Class::MOP::Method::Wrapped->wrap($metamethod, %options) >>
80 This is the constructor. It accepts a L<Class::MOP::Method> object and
81 a hash of options. The options accepted are identical to the ones
82 accepted by L<Class::MOP::Method>, except that C<body> cannot be passed
83 (it will be generated automatically).
89 Jesse Luehrs E<lt>doy at tozt dot netE<gt>
91 =head1 COPYRIGHT AND LICENSE
93 Copyright 2006-2010 by Infinity Interactive, Inc.
95 L<http://www.iinteractive.com>
97 This library is free software; you can redistribute it and/or modify
98 it under the same terms as Perl itself.