From 51f11b41aef336cca76b88b3fab9e02a7980ff14 Mon Sep 17 00:00:00 2001 From: doy Date: Mon, 20 Apr 2009 01:42:03 -0500 Subject: rewrite the _make_immutable_transformer wrapper to be more sane --- lib/MooseX/NonMoose/Meta/Role/Class.pm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'lib/MooseX/NonMoose') diff --git a/lib/MooseX/NonMoose/Meta/Role/Class.pm b/lib/MooseX/NonMoose/Meta/Role/Class.pm index e8524a2..9ce56db 100644 --- a/lib/MooseX/NonMoose/Meta/Role/Class.pm +++ b/lib/MooseX/NonMoose/Meta/Role/Class.pm @@ -10,11 +10,24 @@ has replace_constructor => ( around _make_immutable_transformer => sub { my $orig = shift; my $self = shift; + + # do nothing if extends was never called + return $self->$orig(@_) if !$self->replace_constructor; + + # do nothing if extends was called, but we then added a method modifier to + # the constructor (this will warn, but that's okay) + return $self->$orig(@_) + if $self->get_method('new')->isa('Class::MOP::Method::Wrapped'); + + # do nothing if we explicitly ask for the constructor to not be inlined my %args = @_; return $self->$orig(@_) if exists $args{inline_constructor} && !$args{inline_constructor}; - $args{replace_constructor} = 1 if $self->replace_constructor; - $self->$orig(%args); + + # otherwise, explicitly ask for the constructor to be replaced (to suppress + # the warning message), since this is the expected usage, and shouldn't + # cause a warning + return $self->$orig(replace_constructor => 1, @_); }; around superclasses => sub { -- cgit v1.2.3-54-g00ecf