2 package Class::MOP::Method::Meta;
8 use Scalar::Util 'blessed';
10 use constant DEBUG_NO_META => $ENV{DEBUG_NO_META} ? 1 : 0;
12 use base 'Class::MOP::Method';
14 sub _is_caller_mop_internal {
17 return $caller =~ /^(?:Class::MOP|metaclass)(?:::|$)/;
20 sub _generate_meta_method {
21 my $method_self = shift;
22 my $metaclass = shift;
24 # this will be compiled out if the env var wasn't set
26 confess "'meta' method called by MOP internals"
27 # it's okay to call meta methods on metaclasses, since we
28 # explicitly ask for them
29 if !$_[0]->isa('Class::MOP::Object')
30 && !$_[0]->isa('Class::MOP::Mixin')
31 # it's okay if the test itself calls ->meta, we only care about
32 # if the mop internals call ->meta
33 && $method_self->_is_caller_mop_internal(scalar caller);
35 # we must re-initialize so that it
36 # works as expected in subclasses,
37 # since metaclass instances are
38 # singletons, this is not really a
40 $metaclass->initialize(blessed($_[0]) || $_[0])
45 my ($class, @args) = @_;
47 unshift @args, 'body' if @args % 2 == 1;
49 confess "Overriding the body of meta methods is not allowed"
52 my $metaclass_class = $params{associated_metaclass}->meta;
53 $params{body} = $class->_generate_meta_method($metaclass_class);
54 return $class->SUPER::wrap(%params);
57 sub _make_compatible_with {
61 # XXX: this is pretty gross. the issue here is that CMOP::Method::Meta
62 # objects are subclasses of CMOP::Method, but when we get to moose, they'll
63 # need to be compatible with Moose::Meta::Method, which isn't possible. the
64 # right solution here is to make ::Meta into a role that gets applied to
65 # whatever the method_metaclass happens to be and get rid of
66 # _meta_method_metaclass entirely, but that's not going to happen until
67 # we ditch cmop and get roles into the bootstrapping, so. i'm not
68 # maintaining the previous behavior of turning them into instances of the
69 # new method_metaclass because that's equally broken, and at least this way
70 # any issues will at least be detectable and potentially fixable. -doy
71 return $self unless $other->_is_compatible_with($self->_real_ref_name);
73 return $self->SUPER::_make_compatible_with(@_);
78 # ABSTRACT: Method Meta Object for C<meta> methods
86 This is a L<Class::MOP::Method> subclass which represents C<meta>
87 methods installed into classes by Class::MOP.
93 =item B<< Class::MOP::Method::Wrapped->wrap($metamethod, %options) >>
95 This is the constructor. It accepts a L<Class::MOP::Method> object and
96 a hash of options. The options accepted are identical to the ones
97 accepted by L<Class::MOP::Method>, except that C<body> cannot be passed
98 (it will be generated automatically).