return '' unless $attr->has_type_constraint;
- return sprintf <<'EOF', $value, $value, $value, $value, $value, $value
+ return sprintf <<'EOF', $value, $value, $value, $value, $value, $value, $value
defined($type_constraint->(%s))
|| confess "Attribute (" . $attr->name . ") does not pass the type constraint ("
. $attr->type_constraint->name . ") with "
- . (defined(%s) ? (overload::Overloaded(%s) ? overload::StrVal(%s) : %s) : "undef")
+ . (defined(%s) ? (Scalar::Util::blessed(%s) && overload::Overloaded(%s) ? overload::StrVal(%s) : %s) : "undef")
if defined(%s);
EOF
}
: '') .
' (defined($type_constraint->($default)))' .
' || confess "Attribute (" . $attr->name . ") does not pass the type constraint ("' .
- ' . $attr->type_constraint->name . ") with " . (defined($default) ? (overload::Overloaded($default) ? overload::StrVal($default) : $default) : "undef")' .
+ ' . $attr->type_constraint->name . ") with " . (defined($default) ? (Scalar::Util::blessed($default) && overload::Overloaded($default) ? overload::StrVal($default) : $default) : "undef")' .
' if defined($default);' .
' $_[0]->{$attr_name} = $default; ' .
' }' .
use strict;
use warnings;
-use Test::More tests => 12;
+use Test::More tests => 14;
use Test::Exception;
BEGIN {
- use_ok('Moose');
+ use_ok('Moose');
}
{
has 'foo' => (
documentation => q{
- The 'foo' attribute is my favorite
+ The 'foo' attribute is my favorite
attribute in the whole wide world.
}
);
}
-
+
my $foo_attr = Test::Attribute::Inline::Documentation->meta->get_attribute('foo');
-
+
ok($foo_attr->has_documentation, '... the foo has docs');
is($foo_attr->documentation,
q{
- The 'foo' attribute is my favorite
+ The 'foo' attribute is my favorite
attribute in the whole wide world.
},
'... got the foo docs');
has 'bad_lazy_attr' => (
is => 'rw',
isa => 'ArrayRef',
- lazy => 1,
+ lazy => 1,
default => sub { "test" },
);
-
+
has 'good_lazy_attr' => (
is => 'rw',
isa => 'ArrayRef',
- lazy => 1,
+ lazy => 1,
default => sub { [] },
- );
+ );
}
my $test = Test::For::Lazy::TypeConstraint->new;
isa_ok($test, 'Test::For::Lazy::TypeConstraint');
-
+
dies_ok {
$test->bad_lazy_attr;
} '... this does not work';
-
+
lives_ok {
$test->good_lazy_attr;
- } '... this does not work';
+ } '... this does not work';
}
{
has [qw(foo bar baz)] => (
is => 'rw',
);
-
+
}
my $test = Test::Arrayref::Attributes->new;
isa_ok($test, 'Test::Arrayref::Attributes');
can_ok($test, qw(foo bar baz));
-
+
}
{
isa => 'Str',
default => sub { return }
);
-
+
}
dies_ok {
Test::UndefDefault::Attributes->new;
} '... default must return a value which passes the type constraint';
-
+
}
{
is($moose_obj->a_str( 'foobar' ), 'foobar', 'setter took string');
ok($moose_obj, 'this is a *not* a string');
- throws_ok {
- $moose_obj->a_str( $moose_obj )
+ throws_ok {
+ $moose_obj->a_str( $moose_obj )
} qr/Attribute \(a_str\) does not pass the type constraint \(Str\) with OverloadedStr\=HASH\(.*?\)/, '... dies without overloading the string';
}
+{
+ {
+ package OverloadBreaker;
+ use Moose;
+
+ has 'a_num' => ( isa => 'Int' , is => 'rw', default => 7.5 );
+ }
+
+ throws_ok {
+ OverloadBreaker->new;
+ } qr/Attribute \(a_num\) does not pass the type constraint \(Int\) with \'7\.5\'/, '... this doesnt trip overload to break anymore ';
+
+ lives_ok {
+ OverloadBreaker->new(a_num => 5);
+ } '... this works fine though';
+
+}
+