our $VERSION = '0.06';
-use Moose;
-use MooseX::Object::StrictConstructor;
+use Class::MOP ();
+use Moose ();
+use Moose::Exporter;
+use MooseX::StrictConstructor::Role::Object;
+use MooseX::StrictConstructor::Role::Metaclass;
+Moose::Exporter->setup_import_methods( also => 'Moose' );
-sub import
+sub init_meta
{
- my $caller = caller();
-
- return if $caller eq 'main';
-
- Moose::init_meta( $caller,
- 'MooseX::Object::StrictConstructor',
- 'MooseX::StrictConstructor::Meta::Class',
- );
-
- Moose->import( { into => $caller } );
-
- return;
+ shift;
+ my %p = @_;
+
+ Moose->init_meta(%p);
+
+ my $caller = $p{for_class};
+
+ my $metameta = $caller->meta()->meta();
+ unless ( $metameta->can('does_role')
+ && $metameta->does_role( 'MooseX::StrictConstructor::Role::Metaclass' ) )
+ {
+ my $new_meta =
+ Moose::Meta::Class->create_anon_class
+ ( superclasses => [ ref $caller->meta() ],
+ roles => [ 'MooseX::StrictConstructor::Role::Metaclass' ],
+ cache => 1,
+ );
+
+ Class::MOP::remove_metaclass_by_name($caller);
+
+ $new_meta->name()->initialize($caller);
+ }
+
+ unless ( $caller->meta()->does_role('MooseX::StrictConstructor::Role::Object') )
+ {
+ my $new_base =
+ Moose::Meta::Class->create_anon_class
+ ( superclasses => [ $caller->meta()->superclasses() ],
+ roles => [ 'MooseX::StrictConstructor::Role::Object' ],
+ cache => 1,
+ );
+
+ $caller->meta()->superclasses( $new_base->name() );
+ }
+
+ return $caller->meta();
}
-
-
1;
__END__
-package MooseX::StrictConstructor::Meta::Class;
+package MooseX::StrictConstructor::Role::Metaclass;
use strict;
use warnings;
use MooseX::StrictConstructor::Meta::Method::Constructor;
-use Moose;
+use Moose::Role;
-extends 'Moose::Meta::Class';
around 'make_immutable' => sub ## no critic RequireArgUnpacking
{
);
};
-no Moose;
+no Moose::Role;
1;