return sub {
my $instance = shift;
$container_type_constraint->check($_)
- || confess "Value $_ did not pass container type constraint"
+ || confess "Value " . ($_||'undef') . " did not pass container type constraint"
foreach @_;
push @{$attr->get_value($instance)} => @_;
};
return sub {
my $instance = shift;
$container_type_constraint->check($_)
- || confess "Value $_ did not pass container type constraint"
+ || confess "Value " . ($_||'undef') . " did not pass container type constraint"
foreach @_;
unshift @{$attr->get_value($instance)} => @_;
};
my $container_type_constraint = $attr->container_type_constraint;
return sub {
($container_type_constraint->check($_[2]))
- || confess "Value $_[2] did not pass container type constraint";
+ || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
$attr->get_value($_[0])->[$_[1]] = $_[2]
};
}
use warnings;
use Test::More no_plan => 1;
+use Test::Exception;
BEGIN {
use_ok('MooseX::AttributeHelpers');
ok(!$stuff->has_options, '... no options');
is($stuff->num_options, 0, '... got no options');
-$stuff->add_options(1, 2, 3);
+lives_ok {
+ $stuff->add_options(1, 2, 3);
+} '... set the option okay';
+
is_deeply($stuff->options, [1, 2, 3], '... got options now');
ok($stuff->has_options, '... no options');
is($stuff->get_option_at(1), 2, '... get option at index 1');
is($stuff->get_option_at(2), 3, '... get option at index 2');
-$stuff->set_option_at(1, 100);
+lives_ok {
+ $stuff->set_option_at(1, 100);
+} '... set the option okay';
is($stuff->get_option_at(1), 100, '... get option at index 1');
-$stuff->add_options(10, 15);
+lives_ok {
+ $stuff->add_options(10, 15);
+} '... set the option okay';
+
is_deeply($stuff->options, [1, 100, 3, 10, 15], '... got more options now');
is($stuff->num_options, 5, '... got 5 options');
is($stuff->num_options, 4, '... got 4 options');
is_deeply($stuff->options, [1, 100, 3, 10], '... got diff options now');
-$stuff->insert_options(10, 20);
+lives_ok {
+ $stuff->insert_options(10, 20);
+} '... set the option okay';
is($stuff->num_options, 6, '... got 6 options');
is_deeply($stuff->options, [10, 20, 1, 100, 3, 10], '... got diff options now');
is($stuff->num_options, 5, '... got 5 options');
is($stuff->get_option_at(0), 20, '... get option at index 0');
+## check some errors
+
+dies_ok {
+ $stuff->add_options([]);
+} '... could not add an array ref where an int is expected';
+
+dies_ok {
+ $stuff->insert_options(undef);
+} '... could not add an undef where an int is expected';
+
+dies_ok {
+ $stuff->set_option(5, {});
+} '... could not add a hash ref where an int is expected';
+
## test the meta
my $options = $stuff->meta->get_attribute('options');
use warnings;
use Test::More no_plan => 1;
+use Test::Exception;
BEGIN {
use_ok('MooseX::AttributeHelpers');
is_deeply($stuff->options, {}, '... no options yet');
-$stuff->set_option(foo => 'bar');
+lives_ok {
+ $stuff->set_option(foo => 'bar');
+} '... set the option okay';
ok($stuff->has_options, '... we have options');
is($stuff->num_options, 1, '... we have 1 option(s)');
is_deeply($stuff->options, { foo => 'bar' }, '... got options now');
-$stuff->set_option(bar => 'baz');
+lives_ok {
+ $stuff->set_option(bar => 'baz');
+} '... set the option okay';
is($stuff->num_options, 2, '... we have 2 option(s)');
is_deeply($stuff->options, { foo => 'bar', bar => 'baz' }, '... got more options now');
is($stuff->get_option('foo'), 'bar', '... got the right option');
+## check some errors
+
+dies_ok {
+ $stuff->set_option(bar => {});
+} '... could not add a hash ref where an string is expected';