Skip Menu |
 

This queue is for tickets about the Safe-Isa CPAN distribution.

Report information
The Basics
Id: 107931
Status: resolved
Priority: 0/
Queue: Safe-Isa

People
Owner: Nobody in particular
Requestors: ether [...] cpan.org
Cc: DBOOK [...] cpan.org
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: conditional ->can() dispatch
Download (untitled) / with headers
text/plain 160b
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
Download (untitled) / with headers
text/plain 409b
On Thu Oct 22 18:11:27 2015, ETHER wrote: Show quoted text
> 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 }
Download (untitled) / with headers
text/plain 724b
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.
Added in 1.000007, fixed in 1.000008.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.