Benchmark-DKbench
view release on metacpan or search on metacpan
data/t/attributes/attribute_inherited_slot_specs.t view on Meta::CPAN
use Moose;
use Moose::Util::TypeConstraints;
extends 'Foo';
::is( ::exception {
has '+bar' => (default => 'Bar::bar');
}, undef, '... we can change the default attribute option' );
::is( ::exception {
has '+baz' => (isa => 'ArrayRef');
}, undef, '... we can add change the isa as long as it is a subtype' );
::is( ::exception {
has '+foo' => (coerce => 1);
}, undef, '... we can change/add coerce as an attribute option' );
::is( ::exception {
has '+gorch' => (required => 1);
}, undef, '... we can change/add required as an attribute option' );
::is( ::exception {
has '+gloum' => (lazy => 1);
}, undef, '... we can change/add lazy as an attribute option' );
::is( ::exception {
has '+fleem' => (lazy_build => 1);
}, undef, '... we can add lazy_build as an attribute option' );
::is( ::exception {
has '+bunch_of_stuff' => (isa => 'ArrayRef[Int]');
}, undef, '... extend an attribute with parameterized type' );
::is( ::exception {
has '+one_last_one' => (isa => subtype('Ref', where { blessed $_ eq 'CODE' }));
}, undef, '... extend an attribute with anon-subtype' );
::is( ::exception {
has '+one_last_one' => (isa => 'Value');
}, undef, '... now can extend an attribute with a non-subtype' );
::is( ::exception {
has '+fleem' => (weak_ref => 1);
}, undef, '... now allowed to add the weak_ref option via inheritance' );
::is( ::exception {
has '+bling' => (handles => ['hello']);
}, undef, '... we can add the handles attribute option' );
# this one will *not* work here ....
::isnt( ::exception {
has '+blang' => (handles => ['hello']);
}, undef, '... we can not alter the handles attribute option' );
::is( ::exception {
has '+fail' => (isa => 'Ref');
}, undef, '... can now create an attribute with an improper subtype relation' );
::isnt( ::exception {
has '+other_fail' => (trigger => sub {});
}, undef, '... cannot create an attribute with an illegal option' );
::like( ::exception {
has '+does_not_exist' => (isa => 'Str');
}, qr/in Bar/, '... cannot extend a non-existing attribute' );
}
my $foo = Foo->new;
isa_ok($foo, 'Foo');
is($foo->foo, undef, '... got the right undef default value');
is( exception { $foo->foo('FooString') }, undef, '... assigned foo correctly' );
is($foo->foo, 'FooString', '... got the right value for foo');
isnt( exception { $foo->foo([]) }, undef, '... foo is not coercing (as expected)' );
is($foo->bar, 'Foo::bar', '... got the right default value');
isnt( exception { $foo->bar(10) }, undef, '... Foo::bar is a read/only attr' );
is($foo->baz, undef, '... got the right undef default value');
{
my $hash_ref = {};
is( exception { $foo->baz($hash_ref) }, undef, '... Foo::baz accepts hash refs' );
is($foo->baz, $hash_ref, '... got the right value assigned to baz');
my $array_ref = [];
is( exception { $foo->baz($array_ref) }, undef, '... Foo::baz accepts an array ref' );
is($foo->baz, $array_ref, '... got the right value assigned to baz');
my $scalar_ref = \(my $var);
is( exception { $foo->baz($scalar_ref) }, undef, '... Foo::baz accepts scalar ref' );
is($foo->baz, $scalar_ref, '... got the right value assigned to baz');
is( exception { $foo->bunch_of_stuff([qw[one two three]]) }, undef, '... Foo::bunch_of_stuff accepts an array of strings' );
is( exception { $foo->one_last_one(sub { 'Hello World'}) }, undef, '... Foo::one_last_one accepts a code ref' );
my $code_ref = sub { 1 };
is( exception { $foo->baz($code_ref) }, undef, '... Foo::baz accepts a code ref' );
is($foo->baz, $code_ref, '... got the right value assigned to baz');
}
isnt( exception {
Bar->new;
}, undef, '... cannot create Bar without required gorch param' );
my $bar = Bar->new(gorch => 'Bar::gorch');
isa_ok($bar, 'Bar');
isa_ok($bar, 'Foo');
is($bar->foo, undef, '... got the right undef default value');
is( exception { $bar->foo('FooString') }, undef, '... assigned foo correctly' );
is($bar->foo, 'FooString', '... got the right value for foo');
is( exception { $bar->foo([]) }, undef, '... assigned foo correctly' );
is($bar->foo, 'FooArrayRef', '... got the right value for foo');
is($bar->gorch, 'Bar::gorch', '... got the right default value');
is($bar->bar, 'Bar::bar', '... got the right default value');
isnt( exception { $bar->bar(10) }, undef, '... Bar::bar is a read/only attr' );
is($bar->baz, undef, '... got the right undef default value');
( run in 1.149 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )