From: Dave Rolsky Date: Wed, 14 Jul 2010 16:51:09 +0000 (-0500) Subject: Issue deprecation warning on coerce => 1 without coercion, rather than dying X-Git-Tag: 1.09~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f13091557c5d1326b214b03f83772271340485f9;p=gitmo%2FMoose.git Issue deprecation warning on coerce => 1 without coercion, rather than dying --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 2224b3f..0246259 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -12,6 +12,7 @@ use overload (); our $VERSION = '1.08'; our $AUTHORITY = 'cpan:STEVAN'; +use Moose::Deprecated; use Moose::Meta::Method::Accessor; use Moose::Meta::Method::Delegation; use Moose::Util (); @@ -305,7 +306,12 @@ sub _process_options { unless ( $options->{type_constraint}->has_coercion ) { my $type = $options->{type_constraint}->name; - $class->throw_error("You cannot coerce an attribute ($name) unless its type ($type) has a coercion", data => $options); + + Moose::Deprecated::deprecated( + feature => 'coerce without coercion', + message => + "You cannot coerce an attribute ($name) unless its type ($type) has a coercion" + ); } } diff --git a/t/020_attributes/034_bad_coerce.t b/t/020_attributes/034_bad_coerce.t index da987ab..b85c171 100644 --- a/t/020_attributes/034_bad_coerce.t +++ b/t/020_attributes/034_bad_coerce.t @@ -1,22 +1,24 @@ -#!/usr/bin/perl - 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 $@; +} { package Foo; use Moose; - ::throws_ok{ has foo => ( + ::stderr_like{ has foo => ( is => 'ro', isa => 'Str', coerce => 1, ); - } qr/\QYou cannot coerce an attribute (foo) unless its type (Str) has a coercion/, + } + qr/\QYou cannot coerce an attribute (foo) unless its type (Str) has a coercion/, 'Cannot coerce unless the type has a coercion'; }