or Moose->throw_error("Cannot call init_meta without specifying a for_class");
my $base_class = $args{base_class} || 'Moose::Object';
my $metaclass = $args{metaclass} || 'Moose::Meta::Class';
+ my $meta_name = exists $args{meta_name} ? $args{meta_name} : 'meta';
Moose->throw_error("The Metaclass $metaclass must be a subclass of Moose::Meta::Class.")
unless $metaclass->isa('Moose::Meta::Class');
$meta = $metaclass->initialize($class);
}
- unless ($args{no_meta}) {
+ if (defined $meta_name) {
# also check for inherited non moose 'meta' method?
- my $existing = $meta->get_method('meta');
+ my $existing = $meta->get_method($meta_name);
if ($existing && !$existing->isa('Class::MOP::Method::Meta')) {
Carp::cluck "Moose is overwriting an existing method named "
- . "'meta' with its own version, in class $class. If "
- . "this is actually what you want, you should remove "
- . "the existing method, otherwise, you should pass "
- . "the '-no_meta => 1' option to 'use Moose'.";
+ . "$meta_name in class $class with a method "
+ . "which returns the class's metaclass. If this is "
+ . "actually what you want, you should remove the "
+ . "existing method, otherwise, you should rename or "
+ . "disable this generated method using the "
+ . "'-meta_name' option to 'use Moose'.";
}
- $meta->_add_meta_method;
+ $meta->_add_meta_method($meta_name);
}
# make sure they inherit from Moose::Object
= Moose::Util::resolve_metaclass_alias( 'Class' => $metaclass )
if defined $metaclass && length $metaclass;
- my $no_meta;
- ( $no_meta, @_ ) = _strip_no_meta(@_);
+ my $meta_name;
+ ( $meta_name, @_ ) = _strip_meta_name(@_);
# Normally we could look at $_[0], but in some weird cases
# (involving goto &Moose::import), $_[0] ends as something
$c->init_meta(
for_class => $CALLER,
metaclass => $metaclass,
- no_meta => $no_meta,
+ meta_name => $meta_name,
);
$did_init_meta = 1;
}
return ( $metaclass, @_ );
}
-sub _strip_no_meta {
- my $idx = first_index { $_ eq '-no_meta' } @_;
+sub _strip_meta_name {
+ my $idx = first_index { $_ eq '-meta_name' } @_;
- return ( undef, @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
+ return ( 'meta', @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
- my $no_meta = $_[ $idx + 1 ];
+ my $meta_name = $_[ $idx + 1 ];
splice @_, $idx, 2;
- return ( $no_meta, @_ );
+ return ( $meta_name, @_ );
}
sub _apply_meta_traits {
|| confess "You must pass a HASH ref of methods"
if exists $options{methods};
+ $options{meta_name} = 'meta'
+ unless exists $options{meta_name};
+
my (%initialize_options) = %options;
delete @initialize_options{qw(
package
attributes
methods
- no_meta
+ meta_name
version
authority
)};
$meta->_instantiate_module( $options{version}, $options{authority} );
- $meta->_add_meta_method if !$options{no_meta};
+ $meta->_add_meta_method($options{meta_name})
+ if defined $options{meta_name};
if (exists $options{attributes}) {
foreach my $attribute_name (keys %{$options{attributes}}) {
}
my $metaclass = $args{metaclass} || "Moose::Meta::Role";
+ my $meta_name = exists $args{meta_name} ? $args{meta_name} : 'meta';
Moose->throw_error("The Metaclass $metaclass must be a subclass of Moose::Meta::Role.")
unless $metaclass->isa('Moose::Meta::Role');
$meta = $metaclass->initialize($role);
}
- unless ($args{no_meta}) {
+ if (defined $meta_name) {
# also check for inherited non moose 'meta' method?
- my $existing = $meta->get_method('meta');
+ my $existing = $meta->get_method($meta_name);
if ($existing && !$existing->isa('Class::MOP::Method::Meta')) {
Carp::cluck "Moose::Role is overwriting an existing method named "
- . "'meta' with its own version, in role $role. If "
- . "this is actually what you want, you should remove "
- . "the existing method, otherwise, you should pass "
- . "the '-no_meta => 1' option to 'use Moose::Role'.";
+ . "$meta_name in role $role with a method "
+ . "which returns the class's metaclass. If this is "
+ . "actually what you want, you should remove the "
+ . "existing method, otherwise, you should rename or "
+ . "disable this generated method using the "
+ . "'-meta_name' option to 'use Moose::Role'.";
}
- $meta->_add_meta_method;
+ $meta->_add_meta_method($meta_name);
}
return $meta;