use strict;
use warnings;
-use Test::More tests => 80;
+use Test::More tests => 85;
use Test::Exception;
BEGIN {
has 'blang' => (is => 'ro', isa => 'Thing', handles => ['goodbye']);
has 'bunch_of_stuff' => (is => 'rw', isa => 'ArrayRef');
+
+ has 'one_last_one' => (is => 'rw', isa => 'Ref');
# this one will work here ....
has 'fail' => (isa => 'CodeRef');
package Bar;
use Moose;
+ use Moose::Util::TypeConstraints;
extends 'Foo';
} '... extend an attribute with parameterized type';
::lives_ok {
+ has '+one_last_one' => (isa => subtype('Ref', where { blessed $_ eq 'CODE' }));
+ } '... extend an attribute with anon-subtype';
+
+ ::lives_ok {
+ has '+one_last_one' => (isa => 'Value');
+ } '... now can extend an attribute with a non-subtype';
+
+ ::lives_ok {
+ has '+foo' => ( metaclass => 'DoNotSerialize' );
+ } 'Can add metaclass attribute option';
+
+ ::lives_ok {
+ has '+foo' => ( traits => [ 'DoNotSerialize' ] );
+ } 'Can add traits attribute option';
+
+ ::lives_ok {
has '+bling' => (handles => ['hello']);
} '... we can add the handles attribute option';
::dies_ok {
has '+blang' => (handles => ['hello']);
} '... we can not alter the handles attribute option';
- ::dies_ok {
+ ::lives_ok {
has '+fail' => (isa => 'Ref');
- } '... cannot create an attribute with an improper subtype relation';
+ } '... can now create an attribute with an improper subtype relation';
::dies_ok {
has '+other_fail' => (trigger => sub {});
} '... cannot create an attribute with an illegal option';
::dies_ok {
has '+other_fail' => (weak_ref => 1);
- } '... cannot create an attribute with an illegal option';
-
+ } '... cannot create an attribute with an illegal option';
}
my $foo = Foo->new;
lives_ok { $foo->bunch_of_stuff([qw[one two three]]) } '... Foo::bunch_of_stuff accepts an array of strings';
+ lives_ok { $foo->one_last_one(sub { 'Hello World'}) } '... Foo::one_last_one accepts a code ref';
+
my $code_ref = sub { 1 };
lives_ok { $foo->baz($code_ref) } '... Foo::baz accepts a code ref';
is($foo->baz, $code_ref, '... got the right value assigned to baz');
ok(Bar->meta->has_attribute('bling'), '... Bar has a bling attr');
ok(Bar->meta->has_attribute('bunch_of_stuff'), '... Bar does have a bunch_of_stuff attr');
ok(!Bar->meta->has_attribute('blang'), '... Bar has a blang attr');
-ok(!Bar->meta->has_attribute('fail'), '... Bar does not have a fail attr');
-ok(!Bar->meta->has_attribute('other_fail'), '... Bar does not have a fail attr');
+ok(Bar->meta->has_attribute('fail'), '... Bar has a fail attr');
+ok(!Bar->meta->has_attribute('other_fail'), '... Bar does not have an other_fail attr');
isnt(Foo->meta->get_attribute('foo'),
Bar->meta->get_attribute('foo'),