2 package Class::MOP::Method::Meta;
8 use Scalar::Util 'blessed';
10 our $VERSION = '1.10';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
14 use constant DEBUG_NO_META => $ENV{DEBUG_NO_META} ? 1 : 0;
16 use base 'Class::MOP::Method';
18 sub _is_caller_mop_internal {
21 return $caller =~ /^(?:Class::MOP|metaclass)(?:::|$)/;
24 sub _generate_meta_method {
25 my $method_self = shift;
26 my $metaclass = shift;
28 # this will be compiled out if the env var wasn't set
30 confess "'meta' method called by MOP internals"
31 # it's okay to call meta methods on metaclasses, since we
32 # explicitly ask for them
33 if !$_[0]->isa('Class::MOP::Object')
34 && !$_[0]->isa('Class::MOP::Mixin')
35 # it's okay if the test itself calls ->meta, we only care about
36 # if the mop internals call ->meta
37 && $method_self->_is_caller_mop_internal(scalar caller);
39 # we must re-initialize so that it
40 # works as expected in subclasses,
41 # since metaclass instances are
42 # singletons, this is not really a
44 $metaclass->initialize(blessed($_[0]) || $_[0])
49 my ($class, @args) = @_;
51 unshift @args, 'body' if @args % 2 == 1;
53 confess "Overriding the body of meta methods is not allowed"
56 my $metaclass_class = $params{associated_metaclass}->meta;
57 $params{body} = $class->_generate_meta_method($metaclass_class);
58 return $class->SUPER::wrap(%params);
61 sub _make_compatible_with {
65 # XXX: this is pretty gross. the issue here is that CMOP::Method::Meta
66 # objects are subclasses of CMOP::Method, but when we get to moose, they'll
67 # need to be compatible with Moose::Meta::Method, which isn't possible. the
68 # right solution here is to make ::Meta into a role that gets applied to
69 # whatever the method_metaclass happens to be and get rid of
70 # _meta_method_metaclass entirely, but that's not going to happen until
71 # we ditch cmop and get roles into the bootstrapping, so. i'm not
72 # maintaining the previous behavior of turning them into instances of the
73 # new method_metaclass because that's equally broken, and at least this way
74 # any issues will at least be detectable and potentially fixable. -doy
75 return $self unless $other->_is_compatible_with($self->_real_ref_name);
77 return $self->SUPER::_make_compatible_with(@_);
88 Class::MOP::Method::Meta - Method Meta Object for C<meta> methods
92 This is a L<Class::MOP::Method> subclass which represents C<meta>
93 methods installed into classes by Class::MOP.
99 =item B<< Class::MOP::Method::Wrapped->wrap($metamethod, %options) >>
101 This is the constructor. It accepts a L<Class::MOP::Method> object and
102 a hash of options. The options accepted are identical to the ones
103 accepted by L<Class::MOP::Method>, except that C<body> cannot be passed
104 (it will be generated automatically).
110 Jesse Luehrs E<lt>doy at tozt dot netE<gt>
112 =head1 COPYRIGHT AND LICENSE
114 Copyright 2006-2010 by Infinity Interactive, Inc.
116 L<http://www.iinteractive.com>
118 This library is free software; you can redistribute it and/or modify
119 it under the same terms as Perl itself.