$class->add_attribute(
options => (
traits => \@traits,
- is => 'ro',
+ is => 'rw',
isa => 'HashRef[Str]',
default => sub { {} },
handles => \%handles,
is( $obj->quantity, 4, 'reader part of curried accessor works' );
+ is(
+ $obj->option_accessor('quantity'), 4,
+ 'accessor as reader'
+ );
+
is_deeply(
$obj->options, { quantity => 4 },
'... returns what we expect'
);
+ $obj->option_accessor( size => 42 );
+
+ is_deeply(
+ $obj->options, { quantity => 4, size => 42 },
+ 'accessor as writer'
+ );
+
is( exception {
$class->new( options => { foo => 'BAR' } );
}, undef, '... good constructor params' );
$class->new( options => { foo => [] } );
}, undef, '... bad constructor params' );
+ $obj->options( {} );
+
is_deeply(
[ $obj->set_option( oink => "blah", xxy => "flop" ) ],
[ 'blah', 'flop' ],
is_deeply(
[ sort $obj->keys ],
- [ 'oink', 'quantity', 'xxy' ],
+ [ 'oink', 'xxy' ],
'keys returns expected keys'
);
is_deeply(
[ sort $obj->values ],
- [ 4, 'blah', 'flop' ],
+ [ 'blah', 'flop' ],
'values returns expected values'
);
\@key_value,
[
sort { $a->[0] cmp $b->[0] }[ 'xxy', 'flop' ],
- [ 'quantity', 4 ],
[ 'oink', 'blah' ]
],
'... got the right key value pairs'
is_deeply(
\%options_elements, {
'oink' => 'blah',
- 'quantity' => 4,
'xxy' => 'flop'
},
'... got the right hash elements'