has 'type_constraint' => (is => 'rw', isa => 'Foo');
has 'coercion' => (is => 'rw', isa => 'Foo', coerce => 1);
+ package Bar::Normal;
+ use Moose;
+
+ extends 'Foo::Normal';
+
+ has 'default_w_type_constraint' => (
+ is => 'rw',
+ isa => 'Int',
+ default => 10,
+ );
}
{
# ...
}
- Foo::Immutable->meta->make_immutable(debug => 1);
+ Foo::Immutable->meta->make_immutable(debug => 0);
+
+ package Bar::Immutable;
+ use Moose;
+
+ extends 'Foo::Immutable';
+
+ has 'default_w_type_constraint' => (
+ is => 'rw',
+ isa => 'Int',
+ default => 10,
+ );
+
+ Bar::Immutable->meta->make_immutable(debug => 0);
}
#__END__
my $foo = Foo->new;
-cmpthese(500,
+cmpthese(10_000,
{
'normal' => sub {
Foo::Normal->new(
## -------------------------------------------------
use Moose::Meta::Method::Constructor;
+use Moose::Meta::Method::Destructor;
{
# NOTE:
$IMMUTABLE_METACLASS->make_metaclass_immutable(
$self,
constructor_class => 'Moose::Meta::Method::Constructor',
+ destructor_class => 'Moose::Meta::Method::Destructor',
+ inline_destructor => 1,
+ # NOTE:
+ # no need to do this,
+ # Moose always does it
inline_accessors => 0,
@_,
)
# requires some adaption on the part of
# the author, after all, nothing is free)
my $source = 'sub {';
- $source .= "\n" . 'my $class = shift; ';
+ $source .= "\n" . 'my $class = shift;';
+
+ $source .= "\n" . 'return $class->Moose::Object::' . $self->options->{constructor_name} . '(@_)';
+ $source .= "\n" . ' if $class ne \'' . $self->associated_metaclass->name . '\';';
+
$source .= "\n" . 'my %params = (scalar @_ == 1) ? %{$_[0]} : @_;';
$source .= "\n" . 'my $instance = ' . $self->meta_instance->inline_create_instance('$class');
sub _generate_BUILDALL {
my $self = shift;
my @BUILD_calls;
- foreach my $method ($self->associated_metaclass->find_all_methods_by_name('BUILD')) {
+ foreach my $method (reverse $self->associated_metaclass->find_all_methods_by_name('BUILD')) {
push @BUILD_calls => '$instance->' . $method->{class} . '::BUILD(\%params)';
}
return join "\n" => @BUILD_calls;
use Carp 'confess';
-our $VERSION = '0.06';
+our $VERSION = '0.07';
sub new {
my $class = shift;
}
sub BUILDALL {
+ return unless $_[0]->can('BUILD');
my ($self, $params) = @_;
foreach my $method (reverse $self->meta->find_all_methods_by_name('BUILD')) {
$method->{code}->($self, $params);
}
sub DEMOLISHALL {
- my $self = shift;
+ return unless $_[0]->can('DEMOLISH');
+ my $self = shift;
foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) {
$method->{code}->($self);
}
use Sub::Exporter;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
use Moose ();
subtype $role
=> as 'Role'
=> where { $_->does($role) }
+ => optimize_as { blessed($_[0]) && $_[0]->can('does') && $_[0]->does($role) }
unless find_type_constraint($role);
my $meta;