1 package MooseX::AttributeHelpers::MethodProvider::Collection::List;
2 use MooseX::AttributeHelpers::MethodProvider;
5 our $AUTHORITY = 'cpan:STEVAN';
7 add_method_provider 'Collection::List' => (
11 my ($attr, $reader, $writer) = @_;
12 return sub { scalar @{$reader->($_[0])} };
15 # Deprecated. Does the opposite of its name.
17 my ($attr, $reader, $writer) = @_;
18 return sub { scalar @{$reader->($_[0])} ? 1 : 0 };
22 my ($attr, $reader, $writer) = @_;
23 return sub { @{ $reader->($_[0]) } == 0 };
27 my ($attr, $reader, $writer) = @_;
28 return sub { @{ $reader->($_[0]) } > 0 };
32 my ($attr, $reader, $writer) = @_;
34 my ($instance, $predicate) = @_;
35 foreach my $val (@{$reader->($instance)}) {
36 return $val if $predicate->($val);
43 my ($attr, $reader, $writer) = @_;
45 my ($instance, $f) = @_;
46 CORE::map { $f->($_) } @{$reader->($instance)}
51 my ($attr, $reader, $writer) = @_;
53 my ($instance, $predicate) = @_;
54 CORE::grep { $predicate->($_) } @{$reader->($instance)}
68 MooseX::AttributeHelpers::MethodProvider::List
72 This is a role which provides the method generators for
73 L<MooseX::AttributeHelpers::Collection::List>.
75 =head1 PROVIDED METHODS
81 Returns the number of items in the list.
85 DEPRECATED. This was a misleading name for what it does (returns a boolean
86 indicating whether the list is NOT empty), but we're keeping it for backwards
87 compatibility. Do not use it in new code. Use is_empty or has_items instead,
88 depending on what you meant.
92 Returns a boolean which is true if and only if the list has no items in it.
96 Returns a boolean which is true if and only if the list has at least one item.
98 =item B<find($predicate)>
100 Returns the first item in the list that satisfies $predicate.
114 All complex software has bugs lurking in it, and this module is no
115 exception. If you find a bug please either email me, or add the bug
120 Stevan Little E<lt>stevan@iinteractive.comE<gt>
122 =head1 COPYRIGHT AND LICENSE
124 Copyright 2007-2008 by Infinity Interactive, Inc.
126 L<http://www.iinteractive.com>
128 This library is free software; you can redistribute it and/or modify
129 it under the same terms as Perl itself.