On Wed Feb 19 20:54:54 2014, PEVANS wrote:
Show quoted text> I think that looks good enough. I'll sprinkle some testing of that
> nature around the place...
$ perl -Mblib -MFuture -E 'Future->new->then( [] )->on_done(sub{})'
Expected $code to be callable in ->then at -e line 1.
--
Paul Evans
=== modified file 'lib/Future.pm'
--- lib/Future.pm 2014-02-20 00:58:50 +0000
+++ lib/Future.pm 2014-02-20 02:13:52 +0000
@@ -12,9 +12,12 @@
our $VERSION = '0.23';
use Carp qw(); # don't import croak
-use Scalar::Util qw( weaken blessed );
+use Scalar::Util qw( weaken blessed reftype );
use B qw( svref_2object );
+# we are not overloaded, but we want to check if other objects are
+require overload;
+
our @CARP_NOT = qw( Future::Utils );
use constant DEBUG => $ENV{PERL_FUTURE_DEBUG};
@@ -204,6 +207,12 @@
sprintf "%s(%s line %d)", $cv->GV->NAME, $cop->file, $cop->line;
}
+sub _callable
+{
+ my ( $cb ) = @_;
+ reftype($cb) eq 'CODE' or overload::Method($cb, '&{}')
+}
+
sub new
{
my $proto = shift;
@@ -854,6 +863,9 @@
my $func = (caller 1)[3];
$func =~ s/^.*:://;
+ $flags & (CB_SEQ_IMDONE|CB_SEQ_IMFAIL) or _callable( $code ) or
+ Carp::croak "Expected \$code to be callable in ->$func";
+
if( !defined wantarray ) {
Carp::carp "Calling ->$func in void context";
}
@@ -938,6 +950,11 @@
return $self->_sequence( $done_code, CB_SEQ_ONDONE|CB_RESULT );
}
+ !$done_code or _callable( $done_code ) or
+ Carp::croak "Expected \$done_code to be callable";
+ !$fail_code or _callable( $fail_code ) or
+ Carp::croak "Expected \$fail_code to be callable";
+
# Complex
return $self->_sequence( sub {
my $self = shift;