6 use Test::More tests => 14;
15 package Test::Attribute::Inline::Documentation;
20 The 'foo' attribute is my favorite
21 attribute in the whole wide world.
26 my $foo_attr = Test::Attribute::Inline::Documentation->meta->get_attribute('foo');
28 ok($foo_attr->has_documentation, '... the foo has docs');
29 is($foo_attr->documentation,
31 The 'foo' attribute is my favorite
32 attribute in the whole wide world.
34 '... got the foo docs');
39 package Test::For::Lazy::TypeConstraint;
41 use Moose::Util::TypeConstraints;
43 has 'bad_lazy_attr' => (
47 default => sub { "test" },
50 has 'good_lazy_attr' => (
54 default => sub { [] },
59 my $test = Test::For::Lazy::TypeConstraint->new;
60 isa_ok($test, 'Test::For::Lazy::TypeConstraint');
64 } '... this does not work';
67 $test->good_lazy_attr;
68 } '... this does not work';
73 package Test::Arrayref::Attributes;
76 has [qw(foo bar baz)] => (
82 my $test = Test::Arrayref::Attributes->new;
83 isa_ok($test, 'Test::Arrayref::Attributes');
84 can_ok($test, qw(foo bar baz));
90 package Test::UndefDefault::Attributes;
96 default => sub { return }
102 Test::UndefDefault::Attributes->new;
103 } '... default must return a value which passes the type constraint';
109 package OverloadedStr;
111 use overload '""' => sub { 'this is *not* a string' };
113 has 'a_str' => ( isa => 'Str' , is => 'rw' );
116 my $moose_obj = OverloadedStr->new;
118 is($moose_obj->a_str( 'foobar' ), 'foobar', 'setter took string');
119 ok($moose_obj, 'this is a *not* a string');
122 $moose_obj->a_str( $moose_obj )
123 } qr/Attribute \(a_str\) does not pass the type constraint \(Str\) with OverloadedStr\=HASH\(.*?\)/, '... dies without overloading the string';
129 package OverloadBreaker;
132 has 'a_num' => ( isa => 'Int' , is => 'rw', default => 7.5 );
136 OverloadBreaker->new;
137 } qr/Attribute \(a_num\) does not pass the type constraint \(Int\) with \'7\.5\'/, '... this doesnt trip overload to break anymore ';
140 OverloadBreaker->new(a_num => 5);
141 } '... this works fine though';