return $r;
}
+sub _clean_msg {
+ my ($msg) = @_;
+ $msg =~ s/(?:\s+called)?\s+at\s+.*$//s;
+ return $msg;
+}
+
=head2 C<flatten $proto, @args>
Flattens the array C<@args> according to the prototype C<$proto>. When C<@args> is what C<@_> is after calling a subroutine with prototype C<$proto>, C<flatten> returns the list of what C<@_> would have been if there were no prototype.
$call = 'sub ' . $call if $opts{sub};
if ($opts{compile}) {
$call = eval $call;
- croak $@ if $@;
+ croak _clean_msg $@ if $@;
}
return $call;
}
sub recall {
my $wrap = eval { wrap shift };
- croak $@ if $@;
+ croak _clean_msg $@ if $@;
return $wrap->(@_);
}
}
eval { wrap { 'main::dummy' => '\[@%]' }, ref => 'shift' };
-like($@, qr/to\s+shift\s+must\s+be\s+array/, 'invalid eval code croaks');
+like($@, qr/to\s+shift\s+must\s+be\s+array +\([\w ]+\) +at\s+\Q$0\E/, 'invalid eval code croaks');
use strict;
use warnings;
-use Test::More tests => 7 + 20 + (($^V ge v5.10.0) ? 4 : 0);
+use Test::More tests => 8 + 20 + (($^V ge v5.10.0) ? 4 : 0);
use Scalar::Util qw/set_prototype/;
use Sub::Prototype::Util qw/recall/;
like($@, qr!exactly\s+one\s+key/value\s+pair!, 'recall hashref with 2 pairs croaks');
eval { recall 'hlagh' };
like($@, qr/^Undefined\s+subroutine/, 'recall <unknown> croaks');
+eval { recall 'for' };
+like($@, qr/^syntax\s+error\s+at\s+\Q$0\E/, 'invalid eval code croaks');
sub noproto { $_[1], $_[0] }
sub mytrunc ($;$) { $_[1], $_[0] }