On Thu Oct 22 18:18:26 2015, DBOOK wrote:
Show quoted text> On Thu Oct 22 18:11:27 2015, ETHER wrote:
> > Possible new API? (from #p5p, 2015-10-22)
> >
> > $obj->$_call_if_can('method_name')
> > which would be equivalent to $obj->can('method_name') ? $obj-
> > > method_name : undef
>
>
> Perhaps:
> $obj->$_can('method_name') ? $obj->method_name(@args) : undef
> or to avoid the second method call (?)
> if (my $method = $obj->$_can('method_name')) { $obj->$method(@args) }
> else { undef }
There's a problem with context though; it should return () not undef in case $method is expected to return list context, but then there may be gotchas if using this in a hash constructor or list and $method is expected to return scalar context.