{{$NEXT}}
+ [DEPRECATIONS]
+
+ * The non-arrayref forms of enum and duck_type have been deprecated. See
+ Moose::Manual::Delta for details. (doy)
+
[ENHANCEMENTS]
* The super() subroutine now carps if you pass it arguments. These arguments
use warnings;
use Package::DeprecationManager 0.07 -deprecations => {
+ 'non-arrayref form of enum' => '2.0700',
+ 'non-arrayref form of duck_type' => '2.0700',
'optimized type constraint sub ref' => '2.0000',
'default is for Native Trait' => '1.14',
'default default for Native Trait' => '1.14',
it documented here, or think we missed an important feature, please
send us a patch.
+=head1 2.0700
+
+=over 4
+
+=item The non-arrayref forms of C<enum> and C<duck_type> have been deprecated
+
+Originally, C<enum> could be called like this:
+
+ enum('MyType' => qw(foo bar baz))
+
+This was confusing, however (since it was different from the syntax for
+anonymous enum types), and it makes error checking more difficult (since you
+can't tell just by looking whether C<enum('Foo', 'Bar', 'Baz')> was intended to
+be a type named C<Foo> with elements of C<Bar> and C<Baz>, or if this was
+actually a mistake where someone got the syntax for an anonymous enum type
+wrong. This all also applies to C<duck_type>.
+
+Calling C<enum> and C<duck_type> with a list of arguments as described above
+has been undocumented since version 0.93, and is now deprecated. You should
+replace
+
+ enum MyType => qw(foo bar baz);
+
+in your code with
+
+ enum MyType => [qw(foo bar baz)];
+
+=back
+
=head1 2.0600
=over 4
use List::MoreUtils qw( all any );
use Scalar::Util qw( blessed reftype );
use Moose::Exporter;
+use Moose::Deprecated;
## --------------------------------------------------------
# Prototyped subs must be predeclared because we have a
sub duck_type {
my ( $type_name, @methods ) = @_;
if ( ref $type_name eq 'ARRAY' && !@methods ) {
- @methods = @$type_name;
+ @methods = ($type_name);
$type_name = undef;
}
if ( @methods == 1 && ref $methods[0] eq 'ARRAY' ) {
@methods = @{ $methods[0] };
}
+ else {
+ Moose::Deprecated::deprecated(
+ feature => 'non-arrayref form of duck_type',
+ message => "Passing a list of values to duck_type is deprecated. "
+ . "The method names should be wrapped in an arrayref.",
+ );
+ }
register_type_constraint(
create_duck_type_constraint(
@values == 0
|| __PACKAGE__->_throw_error("enum called with an array reference and additional arguments. Did you mean to parenthesize the enum call's parameters?");
- @values = @$type_name;
+ @values = ($type_name);
$type_name = undef;
}
if ( @values == 1 && ref $values[0] eq 'ARRAY' ) {
@values = @{ $values[0] };
}
+ else {
+ Moose::Deprecated::deprecated(
+ feature => 'non-arrayref form of enum',
+ message => "Passing a list of values to enum is deprecated. "
+ . "Enum values should be wrapped in an arrayref.",
+ );
+ }
register_type_constraint(
create_enum_type_constraint(
=> as 'Str'
=> where { DateTime::Format::MySQL->parse_datetime($_) };
- enum 'Status' => qw(draft posted pending archive);
+ enum 'Status' => [qw(draft posted pending archive)];
has 'headline' => (is => 'rw', isa => 'Headline');
has 'summary' => (is => 'rw', isa => 'Summary');
use Moose;
use Moose::Util::TypeConstraints;
- my $ducktype = duck_type 'DuckType' => qw(walk quack);
+ my $ducktype = duck_type 'DuckType' => [qw(walk quack)];
has duck => (
isa => $ducktype,
use Moose;
use Moose::Util::TypeConstraints;
- duck_type 'DuckType' => qw(quack);
+ duck_type 'DuckType' => [qw(quack)];
duck_type 'SwanType' => [qw(honk)];
has duck => (
use Moose::Util::TypeConstraints;
-enum Letter => 'a'..'z', 'A'..'Z';
-enum Language => 'Perl 5', 'Perl 6', 'PASM', 'PIR'; # any others? ;)
+enum Letter => ['a'..'z', 'A'..'Z'];
+enum Language => ['Perl 5', 'Perl 6', 'PASM', 'PIR']; # any others? ;)
enum Metacharacter => ['*', '+', '?', '.', '|', '(', ')', '[', ']', '\\'];
my @valid_letters = ('a'..'z', 'A'..'Z');
# checking against enum types
-enum RGB => qw[ red green blue ];
-enum CMYK => qw[ cyan magenta yellow black ];
+enum RGB => [qw[ red green blue ]];
+enum CMYK => [qw[ cyan magenta yellow black ]];
sub is_acceptable_color {
match_on_type shift,
{
my @methods = qw( quack flap );
- duck_type 'Duck' => @methods;
+ duck_type 'Duck' => \@methods;
test_constraint(
'Duck', {
{
my @allowed = qw( bar baz quux );
- enum 'Enumerated' => @allowed;
+ enum 'Enumerated' => \@allowed;
test_constraint(
'Enumerated', {
{
- enum 'Enum1' => 'a', 'b';
- enum 'Enum2' => 'x', 'y';
+ enum 'Enum1' => ['a', 'b'];
+ enum 'Enum2' => ['x', 'y'];
subtype 'EnumUnion', as 'Enum1 | Enum2';