]> git.vpit.fr Git - perl/modules/Sub-Prototype-Util.git/commitdiff
Fix some croak backtraces
authorVincent Pit <vince@profvince.com>
Mon, 3 Nov 2008 09:54:07 +0000 (10:54 +0100)
committerVincent Pit <vince@profvince.com>
Mon, 3 Nov 2008 09:54:07 +0000 (10:54 +0100)
lib/Sub/Prototype/Util.pm
t/11-wrap.t
t/12-recall.t

index d549a1cc992e8ea86ceac04a35f89d11a7207098..20525ece0971b354170d655b1ce89b344100467c 100644 (file)
@@ -57,6 +57,12 @@ sub _check_ref {
  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.
@@ -223,7 +229,7 @@ sub wrap {
  $call = 'sub ' . $call if $opts{sub};
  if ($opts{compile}) {
   $call = eval $call;
-  croak $@ if $@;
+  croak _clean_msg $@ if $@;
  }
  return $call;
 }
@@ -242,7 +248,7 @@ If you plan to recall several times, consider using L</wrap> instead.
 
 sub recall {
  my $wrap = eval { wrap shift };
- croak $@ if $@;
+ croak _clean_msg $@ if $@;
  return $wrap->(@_);
 }
 
index 47fd20ecbc587f536cf2fb8e17b5dbac7b2b0dac..7e013235733bd79b42ad8110beee09d77f3f2a3f 100644 (file)
@@ -132,4 +132,4 @@ if ($^V ge v5.10.0) {
 }
 
 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');
index 916e7c5820c07c2829d7411f18821b3153243c5e..8420cebd93f2be5289d4bceb7d7be901b9abe502 100644 (file)
@@ -3,7 +3,7 @@
 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/;
@@ -22,6 +22,8 @@ eval { recall { 'foo' => undef, 'bar' => undef } };
 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] }