From: Hans Dieter Pearcey Date: Sat, 15 Aug 2009 22:13:45 +0000 (-0700) Subject: reverse the meaning of 'empty' X-Git-Tag: 0.89_02~66 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=af44c00c180f0262a59e60070e0dbde797b663ab;p=gitmo%2FMoose.git reverse the meaning of 'empty' --- diff --git a/lib/Moose/Manual/Delta.pod b/lib/Moose/Manual/Delta.pod index b02c716..f6f5a8e 100644 --- a/lib/Moose/Manual/Delta.pod +++ b/lib/Moose/Manual/Delta.pod @@ -18,7 +18,7 @@ send us a patch. =head1 Version 0.89 -L has been moved into the Moose core from +L has been moved into the Moose core from L. Major changes include: =over @@ -40,9 +40,15 @@ generalized to apply to all cases of C<< handles => HASHREF >>, though not every piece of functionality has been ported (currying with a CODEREF is not supported). +=item C now means empty, not non-empty + +Previously, the C method provided by Arrays and Hashes returned true if +the attribute was B empty (no elements). Now it returns true if the +attribute B empty. + =back -See L for the new documentation. +See L for the new documentation. C<< use Moose -metaclass => 'Foo' >> now does alias resolution, just like C<-traits> (and the C and C options to C). diff --git a/lib/Moose/Meta/Attribute/Native/MethodProvider/Array.pm b/lib/Moose/Meta/Attribute/Native/MethodProvider/Array.pm index 9cf0ee6..54800c9 100644 --- a/lib/Moose/Meta/Attribute/Native/MethodProvider/Array.pm +++ b/lib/Moose/Meta/Attribute/Native/MethodProvider/Array.pm @@ -15,7 +15,7 @@ sub count : method { sub empty : method { my ( $attr, $reader, $writer ) = @_; return sub { - scalar @{ $reader->( $_[0] ) } ? 1 : 0; + scalar @{ $reader->( $_[0] ) } ? 0 : 1; }; } diff --git a/lib/Moose/Meta/Attribute/Native/MethodProvider/Hash.pm b/lib/Moose/Meta/Attribute/Native/MethodProvider/Hash.pm index e3e1fd2..bf3afb3 100644 --- a/lib/Moose/Meta/Attribute/Native/MethodProvider/Hash.pm +++ b/lib/Moose/Meta/Attribute/Native/MethodProvider/Hash.pm @@ -61,7 +61,7 @@ sub count : method { sub empty : method { my ( $attr, $reader, $writer ) = @_; - return sub { scalar CORE::keys %{ $reader->( $_[0] ) } ? 1 : 0 }; + return sub { scalar CORE::keys %{ $reader->( $_[0] ) } ? 0 : 1 }; } diff --git a/lib/Moose/Meta/Attribute/Native/Trait/Array.pm b/lib/Moose/Meta/Attribute/Native/Trait/Array.pm index 2709328..10903fc 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait/Array.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait/Array.pm @@ -51,7 +51,7 @@ Moose::Meta::Attribute::Native::Trait::Array get_option => 'get', join_options => 'join', count_options => 'count', - do_i_have_options => 'empty', + has_no_options => 'empty', sorted_options => 'sort', } ); @@ -83,9 +83,9 @@ Returns the number of elements in the array. =item B -If the array is populated, returns true. Otherwise, returns false. +If the array is populated, returns false. Otherwise, returns true. - $stuff->do_i_have_options ? print "Good boy.\n" : die "No options!\n" ; + $stuff->has_no_options ? die "No options!\n" : print "Good boy.\n"; =item B diff --git a/lib/Moose/Meta/Attribute/Native/Trait/Hash.pm b/lib/Moose/Meta/Attribute/Native/Trait/Hash.pm index 8903aa3..8e4abbe 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait/Hash.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait/Hash.pm @@ -42,11 +42,11 @@ Moose::Meta::Attribute::Native::Trait::Hash isa => 'HashRef[Str]', default => sub { {} }, handles => { - set_option => 'set', - get_option => 'get', - has_options => 'empty', - num_options => 'count', - delete_option => 'delete', + set_option => 'set', + get_option => 'get', + has_no_options => 'empty', + num_options => 'count', + delete_option => 'delete', } ); @@ -64,19 +64,19 @@ L. =item B -Returns the number of elements in the list. +Returns the number of elements in the hash. =item B -If the list is populated, returns true. Otherwise, returns false. +If the hash is populated, returns false. Otherwise, returns true. =item B -Returns true if the given key is present in the hash +Returns true if the given key is present in the hash. =item B -Returns true if the value of a given key is defined +Returns true if the value of a given key is defined. =item B @@ -92,15 +92,15 @@ Returns the list of values in the hash. =item B -Returns the key, value pairs in the hash as array references +Returns the key, value pairs in the hash as array references. =item B -Returns the key, value pairs in the hash as a flattened list +Returns the key, value pairs in the hash as a flattened list.. =item B -Removes the element with the given key +Removes the element with the given key. =item B diff --git a/t/070_native_traits/202_trait_array.t b/t/070_native_traits/202_trait_array.t index 3d41983..4d6b755 100644 --- a/t/070_native_traits/202_trait_array.t +++ b/t/070_native_traits/202_trait_array.t @@ -27,7 +27,7 @@ my $sort; 'get_option_at' => 'get', 'set_option_at' => 'set', 'num_options' => 'count', - 'has_options' => 'empty', + 'has_no_options' => 'empty', 'clear_options' => 'clear', 'splice_options' => 'splice', 'sort_options_in_place' => 'sort_in_place', @@ -54,14 +54,14 @@ can_ok( $stuff, $_ ) for qw[ set_option_at num_options clear_options - has_options + has_no_options sort_options_in_place option_accessor ]; is_deeply( $stuff->options, [ 10, 12 ], '... got options' ); -ok( $stuff->has_options, '... we have options' ); +ok( !$stuff->has_no_options, '... we have options' ); is( $stuff->num_options, 2, '... got 2 options' ); is( $stuff->remove_last_option, 12, '... removed the last option' ); @@ -69,7 +69,7 @@ is( $stuff->remove_first_option, 10, '... removed the last option' ); is_deeply( $stuff->options, [], '... no options anymore' ); -ok( !$stuff->has_options, '... no options' ); +ok( $stuff->has_no_options, '... no options' ); is( $stuff->num_options, 0, '... got no options' ); lives_ok { @@ -79,7 +79,7 @@ lives_ok { is_deeply( $stuff->options, [ 1, 2, 3 ], '... got options now' ); -ok( $stuff->has_options, '... no options' ); +ok( !$stuff->has_no_options, '... has options' ); is( $stuff->num_options, 3, '... got 3 options' ); is( $stuff->get_option_at(0), 1, '... get option at index 0' ); @@ -255,7 +255,7 @@ is_deeply( 'get_option_at' => 'get', 'set_option_at' => 'set', 'num_options' => 'count', - 'has_options' => 'empty', + 'has_no_options' => 'empty', 'clear_options' => 'clear', 'splice_options' => 'splice', 'sort_options_in_place' => 'sort_in_place', diff --git a/t/070_native_traits/203_trait_hash.t b/t/070_native_traits/203_trait_hash.t index 392a27d..2ea8001 100644 --- a/t/070_native_traits/203_trait_hash.t +++ b/t/070_native_traits/203_trait_hash.t @@ -19,7 +19,7 @@ use Test::Moose 'does_ok'; handles => { 'set_option' => 'set', 'get_option' => 'get', - 'has_options' => 'empty', + 'has_no_options' => 'empty', 'num_options' => 'count', 'clear_options' => 'clear', 'delete_option' => 'delete', @@ -39,7 +39,7 @@ isa_ok( $stuff, 'Stuff' ); can_ok( $stuff, $_ ) for qw[ set_option get_option - has_options + has_no_options num_options delete_option clear_options @@ -49,7 +49,7 @@ can_ok( $stuff, $_ ) for qw[ option_accessor ]; -ok( !$stuff->has_options, '... we have no options' ); +ok( $stuff->has_no_options, '... we have no options' ); is( $stuff->num_options, 0, '... we have no options' ); is_deeply( $stuff->options, {}, '... no options yet' ); @@ -62,7 +62,7 @@ lives_ok { ok( $stuff->is_defined('foo'), '... foo is defined' ); -ok( $stuff->has_options, '... we have options' ); +ok( !$stuff->has_no_options, '... we have options' ); is( $stuff->num_options, 1, '... we have 1 option(s)' ); ok( $stuff->has_option('foo'), '... we have a foo option' ); is_deeply( $stuff->options, { foo => 'bar' }, '... got options now' ); @@ -148,7 +148,7 @@ is_deeply( { 'set_option' => 'set', 'get_option' => 'get', - 'has_options' => 'empty', + 'has_no_options' => 'empty', 'num_options' => 'count', 'clear_options' => 'clear', 'delete_option' => 'delete', diff --git a/t/070_native_traits/205_trait_list.t b/t/070_native_traits/205_trait_list.t index e2a0359..989ef15 100644 --- a/t/070_native_traits/205_trait_list.t +++ b/t/070_native_traits/205_trait_list.t @@ -22,7 +22,7 @@ my $up; default => sub { [] }, handles => { 'num_options' => 'count', - 'has_options' => 'empty', + 'has_no_options' => 'empty', 'map_options', => 'map', 'filter_options' => 'grep', 'find_option' => 'find', @@ -47,7 +47,7 @@ isa_ok( $stuff, 'Stuff' ); can_ok( $stuff, $_ ) for qw[ _options num_options - has_options + has_no_options map_options filter_options find_option @@ -59,7 +59,7 @@ can_ok( $stuff, $_ ) for qw[ is_deeply( $stuff->_options, [ 1 .. 10 ], '... got options' ); -ok( $stuff->has_options, '... we have options' ); +ok( !$stuff->has_no_options, '... we have options' ); is( $stuff->num_options, 10, '... got 2 options' ); cmp_ok( $stuff->get_option_at(0), '==', 1, '... get option 0' ); cmp_ok( $stuff->get_first_option, '==', 1, '... get first' ); @@ -117,7 +117,7 @@ is_deeply( $options->handles, { 'num_options' => 'count', - 'has_options' => 'empty', + 'has_no_options' => 'empty', 'map_options', => 'map', 'filter_options' => 'grep', 'find_option' => 'find',