Revision history for Perl extension Moose
+0.72
+ * Moose::Object
+ * Moose::Meta::Method::Constructor
+ - A mutable class accepted Foo->new(undef) without complaint,
+ while an immutable class would blow up with an unhelpful
+ error. Now, in both cases we throw a helpful error
+ instead. Reported by doy.
+
0.71_01 Sun, February 22, 2009
* Moose::Cookbook
- Hopefully fixed some POD errors in a few recipes that caused
'@type_constraint_bodies' => \@type_constraint_bodies,
},
) or $self->throw_error("Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source );
-
+
$self->{'body'} = $code;
}
return join("\n",
'do {',
$self->_inline_throw_error('"Single parameters to new() must be a HASH ref"', 'data => $_[0]'),
- ' if scalar @_ == 1 && defined $_[0] && ref($_[0]) ne q{HASH};',
+ ' if scalar @_ == 1 && !( defined $_[0] && ref $_[0] eq q{HASH} );',
'(scalar @_ == 1) ? {%{$_[0]}} : {@_};',
'}',
);
sub BUILDARGS {
my $class = shift;
- if (scalar @_ == 1) {
- if (defined $_[0]) {
- (ref($_[0]) eq 'HASH')
- || $class->meta->throw_error("Single parameters to new() must be a HASH ref", data => $_[0]);
- return {%{$_[0]}};
- }
- else {
- return {}; # FIXME this is compat behavior, but is it correct?
+ if ( scalar @_ == 1 ) {
+ unless ( defined $_[0] && ref $_[0] eq 'HASH' ) {
+ $class->meta->throw_error(
+ "Single parameters to new() must be a HASH ref",
+ data => $_[0] );
}
- }
+ return { %{ $_[0] } };
+ }
else {
return {@_};
}
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More tests => 3;
use Test::Exception;
# This tests the error handling in Moose::Object only
throws_ok { Foo->new('bad') } qr/^\QSingle parameters to new() must be a HASH ref/,
'A single non-hashref arg to a constructor throws an error';
+throws_ok { Foo->new(undef) } qr/^\QSingle parameters to new() must be a HASH ref/,
+ 'A single non-hashref arg to a constructor throws an error';
throws_ok { Foo->does() } qr/^\QYou much supply a role name to does()/,
'Cannot call does() without a role name';
+++ /dev/null
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-
-use Test::More tests => 1;
-use Test::Exception;
-
-{
- package Foo;
- use Moose;
- has 'foo' => ( is => 'ro' );
-}
-
-lives_ok {
- Foo->new(undef);
-} '... passing in undef just gets ignored';
-
-
-
-
}
{
local $@;
- my $obj = eval { $pkg->new ( undef ); };
+ my $obj = eval { $pkg->new ( notanattr => 1 ); };
::like( $@, qr/is required/, "... $pkg undef" );
::is( $obj, undef, "... the object is undef" );
}
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More tests => 3;
use Test::Exception;
'Non-ref provided to immutable constructor gives useful error message';
throws_ok { Foo->new(\$scalar) } qr/\QSingle parameters to new() must be a HASH ref/,
'Scalar ref provided to immutable constructor gives useful error message';
+throws_ok { Foo->new(undef) } qr/\QSingle parameters to new() must be a HASH ref/,
+ 'undef provided to immutable constructor gives useful error message';