1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
use strict;
use warnings;
use Test::Most;
{
package TestOptions;
use Moose;
use MooseX::Has::Options;
use namespace::autoclean;
has 'plain_attribute' =>
(
qw(:ro :required),
isa => 'Str',
);
has 'attribute_with_options' =>
(
qw(:ro :lazy_build),
isa => 'Str'
);
sub _build_attribute_with_options
{
return 'SomeRandomValue';
}
}
my $to = TestOptions->new( plain_attribute => 'Plain');
is( $to->plain_attribute, 'Plain', 'accessing' );
is( $to->attribute_with_options, 'SomeRandomValue', 'lazy' );
dies_ok { $to->plain_attribute('Something') } 'read only';
dies_ok { my $to_required = TestOptions->new } 'required';
dies_ok { my $to_str = TestOptions->new( plain_attribute => [] ) } 'constraint';
done_testing();
|