summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-29 00:05:47 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-29 00:05:47 -0500
commitc94b01a949eadbc8864eac775c526ed8ffeeb98b (patch)
treead5056ea2aaff8418ca2fa2d72c8df6da5bbe7a3
parentb4043c557cfe277054e1077124d679aa24bda89c (diff)
downloadmoosex-abc-c94b01a949eadbc8864eac775c526ed8ffeeb98b.tar.gz
moosex-abc-c94b01a949eadbc8864eac775c526ed8ffeeb98b.zip
use better logic in the constructor rather than replacing it manually
-rw-r--r--lib/MooseX/ABC/Role/Object.pm12
-rw-r--r--lib/MooseX/ABC/Trait/Class.pm18
2 files changed, 10 insertions, 20 deletions
diff --git a/lib/MooseX/ABC/Role/Object.pm b/lib/MooseX/ABC/Role/Object.pm
index 083c0f5..778a81a 100644
--- a/lib/MooseX/ABC/Role/Object.pm
+++ b/lib/MooseX/ABC/Role/Object.pm
@@ -1,12 +1,14 @@
package MooseX::ABC::Role::Object;
use Moose::Role;
-sub new {
+around new => sub {
+ my $orig = shift;
my $class = shift;
- Class::MOP::class_of($class)->throw_error(
- "$class is abstract, it cannot be instantiated"
- );
-}
+ my $meta = Class::MOP::class_of($class);
+ $meta->throw_error("$class is abstract, it cannot be instantiated")
+ if $meta->has_required_methods;
+ $class->$orig(@_);
+};
no Moose::Role;
1;
diff --git a/lib/MooseX/ABC/Trait/Class.pm b/lib/MooseX/ABC/Trait/Class.pm
index 0b51a75..6f4bf6c 100644
--- a/lib/MooseX/ABC/Trait/Class.pm
+++ b/lib/MooseX/ABC/Trait/Class.pm
@@ -31,18 +31,6 @@ after _superclasses_updated => sub {
}
}
}
-
- return if $self->has_required_methods;
-
- # at this point, the current class didn't have any required methods to
- # start with, and all of the required methods from superclasses have
- # been satisfied, so restore the constructor
-
- my $constructor = $self->find_method_by_name('new');
- if ($constructor->original_package_name eq 'MooseX::ABC::Role::Object') {
- my $moose_constructor = Class::MOP::class_of('Moose::Object')->get_method('new');
- $self->add_method(new => $moose_constructor->clone);
- }
};
around _immutable_options => sub {
@@ -50,11 +38,11 @@ around _immutable_options => sub {
my $self = shift;
my @options = $self->$orig(@_);
my $constructor = $self->find_method_by_name('new');
- if ($constructor->original_package_name eq 'Moose::Object') {
- push @options, replace_constructor => 1;
+ if ($self->has_required_methods) {
+ push @options, inline_constructor => 0;
}
elsif ($constructor->original_package_name eq 'MooseX::ABC::Role::Object') {
- push @options, inline_constructor => 0;
+ push @options, replace_constructor => 1;
}
return @options;
};