]> git.vpit.fr Git - perl/modules/Sub-Prototype-Util.git/blobdiff - lib/Sub/Prototype/Util.pm
Make sure the POD headings are linkable
[perl/modules/Sub-Prototype-Util.git] / lib / Sub / Prototype / Util.pm
index 6bf77901c8a042635d0d89c858b22419b6ed3a35..a981d27498ac393d4d383c8c39d2af27e8190c49 100644 (file)
@@ -14,13 +14,13 @@ Sub::Prototype::Util - Prototype-related utility routines.
 
 =head1 VERSION
 
-Version 0.09
+Version 0.10
 
 =cut
 
 use vars qw<$VERSION>;
 
-$VERSION = '0.09';
+$VERSION = '0.10';
 
 =head1 SYNOPSIS
 
@@ -72,7 +72,9 @@ sub _clean_msg {
  $msg;
 }
 
-=head2 C<flatten $proto, @args>
+=head2 C<flatten>
+
+    my @flattened = 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.
@@ -118,7 +120,10 @@ sub flatten {
  return @args;
 }
 
-=head2 C<wrap $name, %opts>
+=head2 C<wrap>
+
+    my $wrapper = wrap($name, %opts);
+    my $wrapper = wrap({ $name => $proto }, %opts);
 
 Generates a wrapper that calls the function C<$name> with a prototyped argument list.
 That is, the wrapper's arguments should be what C<@_> is when you define a subroutine with the same prototype as C<$name>.
@@ -132,7 +137,7 @@ In this case, C<$name> must be a hash reference that holds exactly one key / val
 
     my $push = wrap { 'CORE::push' => '\@$' }; # only pushes 1 arg
 
-Others arguments are seen as key / value pairs that are meant to tune the code generated by L</wrap>.
+The remaining arguments C<%opts> are treated as key / value pairs that are meant to tune the code generated by L</wrap>.
 Valid keys are :
 
 =over 4
@@ -279,7 +284,10 @@ sub wrap {
  return $call;
 }
 
-=head2 C<recall $name, @args>
+=head2 C<recall>
+
+    my @res = recall($name, @args);
+    my @res = recall({ $name => $proto }, @args);
 
 Calls the function C<$name> with the prototyped argument list C<@args>.
 That is, C<@args> should be what C<@_> is when you call a subroutine with C<$name> as prototype.
@@ -293,18 +301,36 @@ If you plan to recall several times, consider using L</wrap> instead.
 
 =cut
 
-sub recall {
- my $name = shift;
+sub recall;
 
- my ($wrap, $err);
- {
-  local $@;
-  $wrap = eval { wrap $name };
-  $err  = $@;
- }
- croak _clean_msg $err if $err;
+BEGIN {
+ my $safe_wrap = sub {
+  my $name = shift;
+
+  my ($wrap, $err);
+  {
+   local $@;
+   $wrap = eval { wrap $name };
+   $err  = $@;
+  }
 
- goto $wrap;
+  $wrap, $err;
+ };
+
+ if ("$]" == 5.008) {
+  # goto tends to crash a lot on perl 5.8.0
+  *recall = sub {
+   my ($wrap, $err) = $safe_wrap->(shift);
+   croak _clean_msg $err if $err;
+   $wrap->(@_)
+  }
+ } else {
+  *recall = sub {
+   my ($wrap, $err) = $safe_wrap->(shift);
+   croak _clean_msg $err if $err;
+   goto $wrap;
+  }
+ }
 }
 
 =head1 EXPORT