],
);
-# This exists for backwards compat
sub init_meta {
- my ( $class, $base_class, $metaclass ) = @_;
-
- __PACKAGE__->_init_meta( for_class => $class,
- object_base_class => $base_class,
- metaclass_class => $metaclass,
- );
-}
-
-# This may be used in some older MooseX extensions.
-sub _get_caller {
- goto &Moose::Exporter::_get_caller;
-}
+ # This used to be called as a function. This hack preserves
+ # backwards compatibility.
+ if ( $_[0] ne __PACKAGE__ ) {
+ return __PACKAGE__->init_meta(
+ for_class => $_[0],
+ base_class => $_[1],
+ metaclass => $_[2],
+ );
+ }
-sub _init_meta {
shift;
my %args = @_;
my $class = $args{for_class}
- or confess "Cannot call _init_meta without specifying a for_class";
- my $base_class = $args{object_base_class} || 'Moose::Object';
- my $metaclass = $args{metaclass_class} || 'Moose::Meta::Class';
+ or confess "Cannot call init_meta without specifying a for_class";
+ my $base_class = $args{base_class} || 'Moose::Object';
+ my $metaclass = $args{metaclass} || 'Moose::Meta::Class';
confess
"The Metaclass $metaclass must be a subclass of Moose::Meta::Class."
$meta->superclasses($base_class)
unless $meta->superclasses();
+
return $meta;
}
+# This may be used in some older MooseX extensions.
+sub _get_caller {
+ goto &Moose::Exporter::_get_caller;
+}
+
## make 'em all immutable
$_->meta->make_immutable(
}
);
- my $import = $class->_make_import_sub(
- $exporter,
- $args{init_meta_args},
- );
+ my $import = $class->_make_import_sub($exporter);
my $unimport = $class->_make_unimport_sub( [ keys %{$exports} ] );
sub _make_import_sub {
my $class = shift;
my $exporter = shift;
- my $init_meta_args = shift;
return sub {
return;
}
- if ( $class->can('_init_meta') ) {
- $class->_init_meta(
+ if ( $class->can('init_meta') ) {
+ $class->init_meta(
for_class => $CALLER,
- %{ $init_meta_args || {} }
);
}
}
{
+ package My::Metaclass;
+ use Moose;
+ BEGIN { extends 'Moose::Meta::Class' }
+
+ package My::Object;
+ use Moose;
+ BEGIN { extends 'Moose::Object' }
+
+ package HasInitMeta;
+
+ use Moose ();
+
+ sub init_meta {
+ shift;
+ return Moose->init_meta( @_,
+ metaclass => 'My::Metaclass',
+ base_class => 'My::Object',
+ );
+ }
+
+ BEGIN { Moose::Exporter->build_import_methods( also => 'Moose' ); }
+}
+
+{
+ package NewMeta;
+
+ BEGIN { HasInitMeta->import() }
+}
+
+{
+ isa_ok( NewMeta->meta(), 'My::Metaclass' );
+ isa_ok( NewMeta->new(), 'My::Object' );
+}
+
+{
package MooseX::CircularAlso;
use Moose ();