use base qw(Moo::Object);
use Sub::Defer;
use B 'perlstring';
+use Moo::_Utils qw(_getstash);
sub register_attribute_specs {
my ($self, @new_specs) = @_;
sub construction_string {
my ($self) = @_;
$self->{construction_string}
- or 'bless('
- .$self->accessor_generator->default_construction_string
- .', $class);'
+ ||= $self->_build_construction_string;
+}
+
+sub _build_construction_string {
+ 'bless('
+ .$_[0]->accessor_generator->default_construction_string
+ .', $class);'
}
sub install_delayed {
." }\n";
}
+use Moo;
+Moo->_constructor_maker_for(__PACKAGE__)->register_attribute_specs(
+ attribute_specs => {
+ is => 'ro',
+ reader => 'all_attribute_specs',
+ },
+ accessor_generator => { is => 'ro' },
+ construction_string => { is => 'lazy' },
+ subconstructor_handler => { is => 'ro' },
+ package => { is => 'ro' },
+);
+
1;
--- /dev/null
+use strictures 1;
+use Test::More;
+use Test::Fatal;
+
+BEGIN {
+ package Role::For::Constructor;
+ use Moo::Role;
+ has extra_param => (is => 'ro');
+}
+BEGIN {
+ package Some::Class;
+ use Moo;
+ BEGIN {
+ my $con = Moo->_constructor_maker_for(__PACKAGE__);
+ Moo::Role->apply_roles_to_object($con, 'Role::For::Constructor');
+ }
+}
+
+{
+ package Some::SubClass;
+ use Moo;
+ extends 'Some::Class';
+
+ ::is(::exception {
+ has bar => (is => 'ro');
+ }, undef, 'extending constructor generator works');
+}
+
+done_testing;