};
}
+sub contains : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub {
+ my ($instance, $item) = @_;
+ return scalar (defined $item ?
+ CORE::grep {defined && $_ eq $item} @{$reader->($instance)}
+ : CORE::grep {!defined} @{$reader->($instance)}
+ );
+ };
+}
+
sub join : method {
my ($attr, $reader, $writer) = @_;
return sub {
default => sub { [] },
auto_deref => 1,
provides => {
- map => 'map_options',
- grep => 'filter_options',
- find => 'find_option',
- first => 'first_option',
- last => 'last_option',
- get => 'get_option',
- join => 'join_options',
- count => 'count_options',
- empty => 'do_i_have_options',
+ map => 'map_options',
+ grep => 'filter_options',
+ find => 'find_option',
+ first => 'first_option',
+ last => 'last_option',
+ get => 'get_option',
+ join => 'join_options',
+ count => 'count_options',
+ empty => 'do_i_have_options',
+ contains => 'options_contains',
}
);
my $option = $stuff->get_option(1);
print "$option\n"; # prints "bar"
+=item B<contains>
+Returns a true value if the list contains the passed value, otherwise returns
+a false value. The return value is actually the number of times the passed
+value appears in the list (0, or more).
+
+ my $found = $stuff->contains( 'apple' );
+ print "Found apple in the list\n" if $found;
+
+Note that this works even when looking for the undefined value.
+
=item B<join>
Joins every element of the list using the separator given as argument.