As to your final question, if $self->{lib} contains a Data::Container object, then the method will return the result of the get_list method on that object.
You could rewrite your get_list method to behave appropriately in scalar context with:
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 wantarr +ay; # 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; }
The important thing to learn from this is wantarray, thought you might also like to know that return with no expression returns an empty list in list context and undef in scalar context.
In reply to Re^3: A new user question on OO Perl
by chromatic
in thread A new user question on OO Perl
by noobee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |