# the author, after all, nothing is free)
my $source = 'sub {';
$source .= "\n" . 'my $_instance = shift;';
+
+ $source .= "\n" . q{Carp::cluck 'Calling new() on an instance is deprecated,'
+ . ' please use (blessed $obj)->new' if blessed $_instance;};
+
$source .= "\n" . 'my $class = Scalar::Util::blessed($_instance) || $_instance;';
$source .= "\n" . 'return $class->Moose::Object::new(@_)';
sub new {
my $class = shift;
-
+
Carp::cluck 'Calling new() on an instance is deprecated,'
. ' please use (blessed $obj)->new' if blessed $class;
-
+
my $params = $class->BUILDARGS(@_);
- # We want to support passing $self->new, but initialize
- # takes only an unblessed class name
my $real_class = Scalar::Util::blessed($class) || $class;
my $self = Class::MOP::Class->initialize($real_class)->new_object($params);
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+BEGIN {
+ eval "use Test::Output;";
+ plan skip_all => "Test::Output is required for this test" if $@;
+ plan tests => 2;
+}
+
+{
+ package Foo;
+ use Moose;
+}
+
+{
+ my $foo = Foo->new();
+ stderr_like { $foo->new() }
+ qr/\QCalling new() on an instance is deprecated/,
+ '$object->new() is deprecated';
+
+ Foo->meta->make_immutable, redo
+ if Foo->meta->is_mutable;
+}