From: Stevan Little Date: Tue, 17 Jul 2007 02:53:43 +0000 (+0000) Subject: foo X-Git-Tag: 0.18_01~69 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=158d8e2026314d8863d02a2a8bac6f8d66215e66;p=gitmo%2FMooseX-AttributeHelpers.git foo --- diff --git a/lib/MooseX/AttributeHelpers/Collection/Hash.pm b/lib/MooseX/AttributeHelpers/Collection/Hash.pm index 1e6ac2a..566972c 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Hash.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Hash.pm @@ -49,7 +49,7 @@ has '+method_constructors' => ( 'empty' => sub { my $attr = shift; return sub { scalar keys %{$attr->get_value($_[0])} ? 1 : 0 }; - } + }, 'delete' => sub { my $attr = shift; return sub { delete $attr->get_value($_[0])->{$_[1]} }; diff --git a/t/003_basic_hash.t b/t/003_basic_hash.t index 164de56..bf71ea9 100644 --- a/t/003_basic_hash.t +++ b/t/003_basic_hash.t @@ -20,10 +20,11 @@ BEGIN { isa => 'HashRef[Str]', default => sub { {} }, provides => { - 'set' => 'set_option', - 'get' => 'get_option', - 'empty' => 'has_options', - 'count' => 'num_options', + 'set' => 'set_option', + 'get' => 'get_option', + 'empty' => 'has_options', + 'count' => 'num_options', + 'delete' => 'delete_option', } ); } @@ -36,6 +37,7 @@ can_ok($stuff, $_) for qw[ get_option has_options num_options + delete_option ]; ok(!$stuff->has_options, '... we have no options'); @@ -61,6 +63,13 @@ is_deeply($stuff->options, { foo => 'bar', bar => 'baz' }, '... got more options is($stuff->get_option('foo'), 'bar', '... got the right option'); lives_ok { + $stuff->delete_option('bar'); +} '... deleted the option okay'; + +is($stuff->num_options, 1, '... we have 1 option(s)'); +is_deeply($stuff->options, { foo => 'bar' }, '... got more options now'); + +lives_ok { Stuff->new(options => { foo => 'BAR' }); } '... good constructor params';