-package MooseX::StrictConstructor::Meta::Method::Constructor;
+package MooseX::StrictConstructor::Role::Constructor;
use strict;
use warnings;
use Carp ();
-use Moose;
-extends 'Moose::Meta::Method::Constructor';
+use Moose::Role;
-override '_generate_BUILDALL' => sub
+around '_generate_BUILDALL' => sub
{
+ my $orig = shift;
my $self = shift;
- my $source = super();
+ my $source = $self->$orig();
$source .= ";\n" if $source;
my @attrs =
return $source;
};
-no Moose;
-
+no Moose::Role;
1;
use Moose::Role;
+has 'constructor_class' =>
+ ( is => 'ro',
+ isa => 'ClassName',
+ lazy_build => 1,
+ );
+sub _build_constructor_class
+{
+ return
+ Moose::Meta::Class->create_anon_class
+ ( superclasses => [ 'Moose::Meta::Method::Constructor' ],
+ roles => [ 'MooseX::StrictConstructor::Role::Constructor' ],
+ cache => 1,
+ )->name();
+}
+
+# If Moose::Meta::Class had a constructor_class attribute, this
+# wrapper would not be necessary.
around 'make_immutable' => sub
{
my $orig = shift;
return
$self->$orig
- ( constructor_class => 'MooseX::StrictConstructor::Meta::Method::Constructor',
+ ( constructor_class => $self->constructor_class(),
@_,
);
};