sub get_list { my ( $self, @capwords ) = @_; # return nothing in void context return unless defined wantarray; # return nothing if there are no items return unless $self->{items}; # return filtered list in list context return grep { $_->is( @capwords ) } @{ $self->{items} } if wantarray; # return the first filtered element in scalar context for my $item ( @{ $self->{items} } ) { return $item if $item->is( @capwords ); } # explicitly return nothing if there's no filtered list return; }