2 package Class::MOP::Method::Meta;
8 use Scalar::Util 'blessed';
10 our $AUTHORITY = 'cpan:STEVAN';
12 use constant DEBUG_NO_META => $ENV{DEBUG_NO_META} ? 1 : 0;
14 use base 'Class::MOP::Method';
16 sub _is_caller_mop_internal {
19 return $caller =~ /^(?:Class::MOP|metaclass)(?:::|$)/;
22 sub _generate_meta_method {
23 my $method_self = shift;
24 my $metaclass = shift;
26 # this will be compiled out if the env var wasn't set
28 confess "'meta' method called by MOP internals"
29 # it's okay to call meta methods on metaclasses, since we
30 # explicitly ask for them
31 if !$_[0]->isa('Class::MOP::Object')
32 && !$_[0]->isa('Class::MOP::Mixin')
33 # it's okay if the test itself calls ->meta, we only care about
34 # if the mop internals call ->meta
35 && $method_self->_is_caller_mop_internal(scalar caller);
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);
59 sub _make_compatible_with {
63 # XXX: this is pretty gross. the issue here is that CMOP::Method::Meta
64 # objects are subclasses of CMOP::Method, but when we get to moose, they'll
65 # need to be compatible with Moose::Meta::Method, which isn't possible. the
66 # right solution here is to make ::Meta into a role that gets applied to
67 # whatever the method_metaclass happens to be and get rid of
68 # _meta_method_metaclass entirely, but that's not going to happen until
69 # we ditch cmop and get roles into the bootstrapping, so. i'm not
70 # maintaining the previous behavior of turning them into instances of the
71 # new method_metaclass because that's equally broken, and at least this way
72 # any issues will at least be detectable and potentially fixable. -doy
73 return $self unless $other->_is_compatible_with($self->_real_ref_name);
75 return $self->SUPER::_make_compatible_with(@_);
80 # ABSTRACT: Method Meta Object for C<meta> methods
88 This is a L<Class::MOP::Method> subclass which represents C<meta>
89 methods installed into classes by Class::MOP.
95 =item B<< Class::MOP::Method::Wrapped->wrap($metamethod, %options) >>
97 This is the constructor. It accepts a L<Class::MOP::Method> object and
98 a hash of options. The options accepted are identical to the ones
99 accepted by L<Class::MOP::Method>, except that C<body> cannot be passed
100 (it will be generated automatically).