});
}
+sub init_meta {
+ # 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],
+ );
+ }
+
+ shift;
+ my %args = @_;
+
+ my $class = $args{for_class}
+ or Carp::croak(
+ "Cannot call init_meta without specifying a for_class");
+ my $base_class = $args{base_class} || 'Mouse::Object';
+ my $metaclass = $args{metaclass} || 'Mouse::Meta::Class';
+
+ Carp::croak("The Metaclass $metaclass must be a subclass of Mouse::Meta::Class.")
+ unless $metaclass->isa('Mouse::Meta::Class');
+
+ # make a subtype for each Mouse class
+ class_type($class)
+ unless find_type_constraint($class);
+
+ my $meta = $metaclass->initialize($class);
+ $meta->superclasses($base_class)
+ unless $meta->superclasses;
+
+ {
+ no strict 'refs';
+ no warnings 'redefine';
+ *{$class.'::meta'} = sub { $meta };
+ }
+
+ return $meta;
+}
+
sub import {
my $class = shift;
return;
}
- my $meta = Mouse::Meta::Class->initialize($caller);
- $meta->superclasses('Mouse::Object')
- unless $meta->superclasses;
-
- # make a subtype for each Mouse class
- class_type($caller) unless find_type_constraint($caller);
-
- no strict 'refs';
- no warnings 'redefine';
- *{$caller.'::meta'} = sub { $meta };
+ Mouse->init_meta(
+ for_class => $caller,
+ );
if (@_) {
__PACKAGE__->export_to_level( $level+1, $class, @_);
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+
+use Mouse ();
+
+
+{ package Foo; }
+
+my $meta = Mouse::init_meta('Foo');
+
+ok( Foo->isa('Mouse::Object'), '... Foo isa Mouse::Object');
+isa_ok( $meta, 'Mouse::Meta::Class' );
+isa_ok( Foo->meta, 'Mouse::Meta::Class' );
+
+is($meta, Foo->meta, '... our metas are the same');