+ - useful and detailed errors for default checker in attrib generation
+
0.091011 - 2012-06-27
- re-add #web-simple as development IRC
- don't assume Scalar::Util is imported into the current package
use base qw(Moo::Object);
use Sub::Quote;
use B 'perlstring';
+use Scalar::Util 'blessed';
BEGIN {
our $CAN_HAZ_XS =
!$ENV{MOO_XS_DISABLE}
}
if (exists $spec->{default}) {
my $default = $spec->{default};
- # default can be either a coderef or an overloaded object
- die "Invalid default $default" unless ref $default
- and ( ref $default eq 'CODE' or eval { \&$default } );
+ my $invalid = "Invalid default '" . overload::StrVal($default)
+ . "' for $into->$name - not a coderef";
+ die "$invalid or code-convertible object"
+ unless ref $default and (ref $default eq 'CODE' or blessed($default));
+ die "$invalid and could not be converted to a coderef: $@"
+ if !eval { \&$default };
}
my %methods;
perigrin - Chris Prather (cpan:PERIGRIN) <chris@prather.org>
+Mithaldu - Christian Walde (cpan:MITHALDU) <walde.christian@googlemail.com>
+
=head1 COPYRIGHT
Copyright (c) 2010-2011 the Moo L</AUTHOR> and L</CONTRIBUTORS>
qr/Invalid default/, 'default - arrayref rejected'
);
+like(
+ exception { $gen->generate_method('Foo' => 'five' => { is => 'ro', default => Foo->new }) },
+ qr/Invalid default/, 'default - non-code-convertible object rejected'
+);
+
is(
exception { $gen->generate_method('Foo' => 'six' => { is => 'ro', default => sub { 5 } }) },
undef, 'default - coderef accepted'