sub count : method {
my ($attr, $reader, $writer) = @_;
- return sub {
- scalar @{$reader->($_[0])}
- };
+ return sub { scalar @{$reader->($_[0])} };
}
+# Deprecated. The author was thinking backwardsly when this was written.
sub empty : method {
my ($attr, $reader, $writer) = @_;
- return sub {
- scalar @{$reader->($_[0])} ? 1 : 0
- };
+ return sub { scalar @{$reader->($_[0])} ? 1 : 0 };
+}
+
+sub is_empty : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub { @{ $reader->($_[0]) } == 0 };
+}
+
+sub has_items : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub { @{ $reader->($_[0]) } > 0 };
}
sub find : method {
This is a role which provides the method generators for
L<MooseX::AttributeHelpers::Collection::List>.
-=head1 METHODS
+=head1 PROVIDED METHODS
=over 4
-=item B<meta>
+=item B<count>
-=back
+Returns the number of items in the list.
-=head1 PROVIDED METHODS
+=item B<empty>
-=over 4
+DEPRECATED. This was a misleading name for what it does (returns a boolean
+indicating whether the list is NOT empty), but we're keeping it for backwards
+compatibility. Do not use it in new code. Use is_empty or has_items instead,
+depending on what you meant.
-=item B<count>
+=item B<is_empty>
-=item B<empty>
+Returns a boolean which is true if and only if the list has no items in it.
+
+=item B<has_items>
-=item B<find>
+Returns a boolean which is true if and only if the list has at least one item.
+
+=item B<find($predicate)>
+
+Returns the first item in the list that satisfies $predicate.
=item B<grep>
+L<perlfunc/grep>
+
=item B<map>
+L<perlfunc/map>
+
=back
=head1 BUGS