1 package MooseX::AttributeHelpers::MethodProvider::List;
5 our $AUTHORITY = 'cpan:STEVAN';
8 my ($attr, $reader, $writer) = @_;
9 return sub { scalar @{$reader->($_[0])} };
12 # Deprecated. The author was thinking backwardsly when this was written.
14 my ($attr, $reader, $writer) = @_;
15 return sub { scalar @{$reader->($_[0])} ? 1 : 0 };
18 sub is_empty : method {
19 my ($attr, $reader, $writer) = @_;
20 return sub { @{ $reader->($_[0]) } == 0 };
23 sub has_items : method {
24 my ($attr, $reader, $writer) = @_;
25 return sub { @{ $reader->($_[0]) } > 0 };
29 my ($attr, $reader, $writer) = @_;
31 my ($instance, $predicate) = @_;
32 foreach my $val (@{$reader->($instance)}) {
33 return $val if $predicate->($val);
40 my ($attr, $reader, $writer) = @_;
42 my ($instance, $f) = @_;
43 CORE::map { $f->($_) } @{$reader->($instance)}
48 my ($attr, $reader, $writer) = @_;
50 my ($instance, $predicate) = @_;
51 CORE::grep { $predicate->($_) } @{$reader->($instance)}
63 MooseX::AttributeHelpers::MethodProvider::List
67 This is a role which provides the method generators for
68 L<MooseX::AttributeHelpers::Collection::List>.
70 =head1 PROVIDED METHODS
76 Returns the number of items in the list.
80 DEPRECATED. This was a misleading name for what it does (returns a boolean
81 indicating whether the list is NOT empty), but we're keeping it for backwards
82 compatibility. Do not use it in new code. Use is_empty or has_items instead,
83 depending on what you meant.
87 Returns a boolean which is true if and only if the list has no items in it.
91 Returns a boolean which is true if and only if the list has at least one item.
93 =item B<find($predicate)>
95 Returns the first item in the list that satisfies $predicate.
109 All complex software has bugs lurking in it, and this module is no
110 exception. If you find a bug please either email me, or add the bug
115 Stevan Little E<lt>stevan@iinteractive.comE<gt>
117 =head1 COPYRIGHT AND LICENSE
119 Copyright 2007-2008 by Infinity Interactive, Inc.
121 L<http://www.iinteractive.com>
123 This library is free software; you can redistribute it and/or modify
124 it under the same terms as Perl itself.