$self->$orig(@_),
'if (@_ % 2) {',
$self->_inline_throw_error(
- '"You must pass an even number of arguments to set"',
+ sprintf(
+ '"You must pass an even number of arguments to %s"',
+ $self->delegate_to_method,
+ ),
) . ';',
'}',
);
'for (@keys_idx) {',
'if (!defined($_[$_])) {',
$self->_inline_throw_error(
- '"Hash keys passed to set must be defined"',
+ sprintf(
+ '"Hash keys passed to %s must be defined"',
+ $self->delegate_to_method,
+ ),
) . ';',
'}',
'}',
);
}, undef, '... set the option okay' );
+ like(
+ exception { $obj->set_option( foo => 'bar', 'baz' ) },
+ qr/You must pass an even number of arguments to set/,
+ 'exception with odd number of arguments'
+ );
+
+ like(
+ exception { $obj->set_option( undef, 'bar' ) },
+ qr/Hash keys passed to set must be defined/,
+ 'exception when using undef as a key'
+ );
+
ok( $obj->is_defined('foo'), '... foo is defined' );
ok( !$obj->has_no_options, '... we have options' );
'error when calling accessor with no arguments'
);
+ like(
+ exception { $obj->option_accessor( undef, 'bar' ) },
+ qr/Hash keys passed to accessor must be defined/,
+ 'exception when using undef as a key'
+ );
+
is_deeply(
$obj->options, { quantity => 4, size => 42 },
'accessor as writer'