Benchmark-DKbench
view release on metacpan or search on metacpan
data/t/attributes/attribute_writer_generation.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Scalar::Util 'isweak';
{
package Foo;
use Moose;
eval {
has 'foo' => (
reader => 'get_foo',
writer => 'set_foo',
);
};
::ok(!$@, '... created the writer method okay');
eval {
has 'foo_required' => (
reader => 'get_foo_required',
writer => 'set_foo_required',
required => 1,
);
};
::ok(!$@, '... created the required writer method okay');
eval {
has 'foo_int' => (
reader => 'get_foo_int',
writer => 'set_foo_int',
isa => 'Int',
);
};
::ok(!$@, '... created the writer method with type constraint okay');
eval {
has 'foo_weak' => (
reader => 'get_foo_weak',
writer => 'set_foo_weak',
weak_ref => 1
);
};
::ok(!$@, '... created the writer method with weak_ref okay');
}
{
my $foo = Foo->new(foo_required => 'required');
isa_ok($foo, 'Foo');
# regular writer
can_ok($foo, 'set_foo');
is($foo->get_foo(), undef, '... got an unset value');
is( exception {
$foo->set_foo(100);
}, undef, '... set_foo wrote successfully' );
is($foo->get_foo(), 100, '... got the correct set value');
ok(!isweak($foo->{foo}), '... it is not a weak reference');
# required writer
( run in 1.241 second using v1.01-cache-2.11-cpan-54e63673c56 )