Moose
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
t/exceptions/class-mop-method-accessor.t view on Meta::CPAN
$exception->option,
"clearer",
"can't call get_meta_instance on an undefined value");
}
{
{
package Foo::ReadOnlyAccessor;
use Moose;
has 'foo' => (
is => 'ro',
isa => 'Int',
);
}
my $foo = Foo::ReadOnlyAccessor->new;
my $exception = exception {
$foo->foo(120);
};
like(
$exception,
qr/Cannot assign a value to a read-only accessor/,
"foo is read only");
isa_ok(
$exception,
"Moose::Exception::CannotAssignValueToReadOnlyAccessor",
"foo is read only");
is(
$exception->class_name,
"Foo::ReadOnlyAccessor",
"foo is read only");
is(
$exception->attribute_name,
"foo",
"foo is read only");
is(
$exception->value,
120,
"foo is read only");
}
{
{
package Point;
use metaclass;
Point->meta->add_attribute('x' => (
reader => 'x',
init_arg => 'x'
));
sub new {
my $class = shift;
bless $class->meta->new_object(@_) => $class;
}
}
my $point = Point->new();
my $exception = exception {
$point->x(120);
};
like(
$exception,
qr/Cannot assign a value to a read-only accessor/,
"x is read only");
isa_ok(
$exception,
"Moose::Exception::CannotAssignValueToReadOnlyAccessor",
"x is read only");
is(
$exception->class_name,
"Point",
"x is read only");
is(
$exception->attribute_name,
"x",
"x is read only");
is(
$exception->value,
120,
"x is read only");
}
done_testing;
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.399 second using v1.00-cache-2.02-grep-82fe00e-cpan-b63e86051f13 )