From: Evan Carroll Date: Tue, 7 Apr 2009 21:12:26 +0000 (-0500) Subject: Added defined for AH X-Git-Tag: 0.17~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c0dcad02f9924c58c3a7c07a076d057e4f276d93;p=gitmo%2FMooseX-AttributeHelpers.git Added defined for AH --- diff --git a/lib/MooseX/AttributeHelpers/Collection/Hash.pm b/lib/MooseX/AttributeHelpers/Collection/Hash.pm index d8e64eb..a7ae349 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Hash.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Hash.pm @@ -56,7 +56,7 @@ MooseX::AttributeHelpers::Collection::Hash =head1 DESCRIPTION -This module provides an Hash attribute which provides a number of +This module provides a Hash attribute which provides a number of hash-like operations. See L for more details. diff --git a/lib/MooseX/AttributeHelpers/MethodProvider/Hash.pm b/lib/MooseX/AttributeHelpers/MethodProvider/Hash.pm index 0c98f0c..bb08d6c 100644 --- a/lib/MooseX/AttributeHelpers/MethodProvider/Hash.pm +++ b/lib/MooseX/AttributeHelpers/MethodProvider/Hash.pm @@ -97,6 +97,8 @@ L role. =item B +=item B + =item B =item B diff --git a/lib/MooseX/AttributeHelpers/MethodProvider/ImmutableHash.pm b/lib/MooseX/AttributeHelpers/MethodProvider/ImmutableHash.pm index a118f41..36484e0 100644 --- a/lib/MooseX/AttributeHelpers/MethodProvider/ImmutableHash.pm +++ b/lib/MooseX/AttributeHelpers/MethodProvider/ImmutableHash.pm @@ -10,6 +10,11 @@ sub exists : method { return sub { CORE::exists $reader->($_[0])->{$_[1]} ? 1 : 0 }; } +sub defined : method { + my ($attr, $reader, $writer) = @_; + return sub { CORE::defined $reader->($_[0])->{$_[1]} ? 1 : 0 }; +} + sub get : method { my ($attr, $reader, $writer) = @_; return sub { diff --git a/t/003_basic_hash.t b/t/003_basic_hash.t index 7b1b779..b9dfbc0 100644 --- a/t/003_basic_hash.t +++ b/t/003_basic_hash.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 40; +use Test::More tests => 42; use Test::Exception; BEGIN { @@ -28,6 +28,7 @@ BEGIN { 'clear' => 'clear_options', 'delete' => 'delete_option', 'exists' => 'has_option', + 'defined'=> 'is_defined' }, curries => { 'set' => { @@ -47,6 +48,7 @@ can_ok($stuff, $_) for qw[ num_options delete_option clear_options + is_defined has_option ]; @@ -60,6 +62,8 @@ lives_ok { $stuff->set_option(foo => 'bar'); } '... set the option okay'; +ok($stuff->is_defined('foo'), '... foo is defined'); + ok($stuff->has_options, '... we have options'); is($stuff->num_options, 1, '... we have 1 option(s)'); ok($stuff->has_option('foo'), '... we have a foo option'); @@ -134,6 +138,7 @@ is_deeply($options->provides, { 'count' => 'num_options', 'clear' => 'clear_options', 'delete' => 'delete_option', + 'defined'=> 'is_defined', 'exists' => 'has_option', }, '... got the right provies mapping');