package Parent;
use Moose;
has 'knibbel' => (
is => 'rw',
isa => 'HashRef[Maybe[Value]]',
lazy_build => 1,
);
has 'knabbel' => (
is => 'rw',
isa => 'ArrayRef[Maybe[Value]]',
lazy_build => 1,
);
sub BUILD {
my $self = shift;
my $meta = $self->meta;
print("BUILD called for " . __PACKAGE__ . "\n");
no strict;
foreach my $attribute ($meta->get_attribute_list) {
print("Creating builder for attribute [$attribute]\n");
*{__PACKAGE__ . '::_build_' . $attribute} = sub {
my $self = shift;
my $meta = $self->meta;
my $fropsel = $meta->get_attribute($attribute);
if ($fropsel->type_constraint->name =~ /^ArrayRef/) { return []; }
if ($fropsel->type_constraint->name =~ /^HashRef/) { return {}; }
};
}
use strict;
}
1;
####
package Child;
use Moose;
extends 'Parent';
has 'knuisje' => (
is => 'rw',
isa => 'Str',
lazy_build => 1,
);
sub BUILD {
my $self = shift;
my $meta = $self->meta;
print("BUILD called for " . __PACKAGE__ . "\n");
no strict;
foreach my $attribute ($meta->get_attribute_list) {
print("Creating builder for attribute [$attribute]\n");
*{__PACKAGE__ . '::_build_' . $attribute} = sub {
my $self = shift;
my $meta = $self->meta;
my $fropsel = $meta->get_attribute($attribute);
if ($fropsel->type_constraint->name =~ /^Str/) { return ""; }
};
}
use strict;
}
1;
####
#!/usr/bin/perl -w
use strict;
use Parent;
use Child;
my $child = Child->new();
####
$ ./testchild.pl
BUILD called for Parent
Creating builder for attribute [knuisje]
BUILD called for Child
Creating builder for attribute [knuisje]