=head1 Version 0.89
-L<Moose::AttributeHelpers> has been moved into the Moose core from
+L<Moose::Meta::Attribute::Native> has been moved into the Moose core from
L<MooseX::AttributeHelpers>. Major changes include:
=over
not every piece of functionality has been ported (currying with a
CODEREF is not supported).
+=item C<empty> now means empty, not non-empty
+
+Previously, the C<empty> method provided by Arrays and Hashes returned true if
+the attribute was B<not> empty (no elements). Now it returns true if the
+attribute B<is> empty.
+
=back
-See L<Moose::AttributeHelpers> for the new documentation.
+See L<Moose::Meta::Attribute::Native> for the new documentation.
C<< use Moose -metaclass => 'Foo' >> now does alias resolution, just like
C<-traits> (and the C<metaclass> and C<traits> options to C<has>).
sub empty : method {
my ( $attr, $reader, $writer ) = @_;
return sub {
- scalar @{ $reader->( $_[0] ) } ? 1 : 0;
+ scalar @{ $reader->( $_[0] ) } ? 0 : 1;
};
}
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 };
}
get_option => 'get',
join_options => 'join',
count_options => 'count',
- do_i_have_options => 'empty',
+ has_no_options => 'empty',
sorted_options => 'sort',
}
);
=item B<empty>
-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<find>
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',
}
);
=item B<count>
-Returns the number of elements in the list.
+Returns the number of elements in the hash.
=item B<empty>
-If the list is populated, returns true. Otherwise, returns false.
+If the hash is populated, returns false. Otherwise, returns true.
=item B<exists>
-Returns true if the given key is present in the hash
+Returns true if the given key is present in the hash.
=item B<defined>
-Returns true if the value of a given key is defined
+Returns true if the value of a given key is defined.
=item B<get>
=item B<kv>
-Returns the key, value pairs in the hash as array references
+Returns the key, value pairs in the hash as array references.
=item B<elements>
-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<delete>
-Removes the element with the given key
+Removes the element with the given key.
=item B<clear>
'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',
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' );
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 {
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' );
'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',
handles => {
'set_option' => 'set',
'get_option' => 'get',
- 'has_options' => 'empty',
+ 'has_no_options' => 'empty',
'num_options' => 'count',
'clear_options' => 'clear',
'delete_option' => 'delete',
can_ok( $stuff, $_ ) for qw[
set_option
get_option
- has_options
+ has_no_options
num_options
delete_option
clear_options
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' );
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' );
{
'set_option' => 'set',
'get_option' => 'get',
- 'has_options' => 'empty',
+ 'has_no_options' => 'empty',
'num_options' => 'count',
'clear_options' => 'clear',
'delete_option' => 'delete',
default => sub { [] },
handles => {
'num_options' => 'count',
- 'has_options' => 'empty',
+ 'has_no_options' => 'empty',
'map_options', => 'map',
'filter_options' => 'grep',
'find_option' => 'find',
can_ok( $stuff, $_ ) for qw[
_options
num_options
- has_options
+ has_no_options
map_options
filter_options
find_option
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' );
$options->handles,
{
'num_options' => 'count',
- 'has_options' => 'empty',
+ 'has_no_options' => 'empty',
'map_options', => 'map',
'filter_options' => 'grep',
'find_option' => 'find',