my $self = shift;
my ($new_value) = @_;
- my $attr_name = $self->associated_attribute->name;
+ my $attr_name = quotemeta($self->associated_attribute->name);
+ my $type_name = quotemeta($self->_tc_member_type->name);
my $check
= $self->_tc_member_type->can_be_inlined
'"A new member value for ' . $attr_name
. ' does not pass its type constraint because: "' . ' . '
. 'do { local $_ = $new_val; $member_message->($new_val) }',
- 'data => $new_val',
+ 'class => "Moose::Exception::TypeConstraint",' .
+ 'attribute_name => \'' . $attr_name . '\',' .
+ 'type_name => \'' . $type_name . '\',' .
+ 'value => ' . $new_value
) . ';',
'}',
'}',
use Test::Fatal;
use Moose::Util::TypeConstraints;
+# no attribute
+my $exception = exception { find_type_constraint('Int')->assert_valid("eek") };
+isa_ok($exception, 'Moose::Exception::TypeConstraint');
+is($exception->message, q{Validation failed for 'Int' with value "eek"}, 'exception->message');
+is($exception->value, "eek", 'exception->value');
+is($exception->type_name, "Int", 'exception->type_name');
+is($exception->attribute_name, undef, 'exception->attribute_name');
+
BEGIN {
package Foo;
use Moose;
is => 'rw',
isa => 'Int',
);
+
+ has items => (
+ traits => ['Array'],
+ is => 'ro',
+ isa => 'ArrayRef[Int]',
+ handles => {
+ add_item => 'push',
+ },
+ );
}
-my $exception = exception { Foo->new(count => "test") };
+# constructor
+$exception = exception { Foo->new(count => "test") };
isa_ok($exception, 'Moose::Exception::TypeConstraint');
is($exception->message, q{Attribute (count) does not pass the type constraint because: Validation failed for 'Int' with value "test"}, 'exception->message');
is($exception->value, "test", 'exception->value');
is($exception->type_name, "Int", 'exception->type_name');
is($exception->attribute_name, "count", 'exception->attribute_name');
+# setter
my $value = [];
$exception = exception { Foo->new->count($value) };
isa_ok($exception, 'Moose::Exception::TypeConstraint');
is($exception->type_name, "Int", 'exception->type_name');
is($exception->attribute_name, "count", 'exception->attribute_name');
-$exception = exception { find_type_constraint('Int')->assert_valid("eek") };
+# native array push
+$value = {};
+$exception = exception { Foo->new->add_item($value) };
isa_ok($exception, 'Moose::Exception::TypeConstraint');
-is($exception->message, q{Validation failed for 'Int' with value "eek"}, 'exception->message');
-is($exception->value, "eek", 'exception->value');
+is($exception->message, q[A new member value for items does not pass its type constraint because: Validation failed for 'Int' with value { }], 'exception->message');
+is($exception->value, $value, 'exception->value');
is($exception->type_name, "Int", 'exception->type_name');
-is($exception->attribute_name, undef, 'exception->attribute_name');
+is($exception->attribute_name, "items", 'exception->attribute_name');
done_testing;