+
+ $name =~ s/^\s+//;
+ $name =~ s/[\s\$\@\%\*\&;].*//;
+
+ return $name, $proto;
+}
+
+sub wrap {
+ my ($name, $proto) = _check_name shift;
+ croak 'Optional arguments must be passed as key => value pairs' if @_ % 2;
+ my %opts = @_;
+
+ $opts{ref} ||= 'ref';
+ $opts{sub} = 1 unless defined $opts{sub};
+ $opts{compile} = 1 if not defined $opts{compile} and $opts{sub};
+ $opts{wrong_ref} = 'undef' unless defined $opts{wrong_ref};
+
+ my @coderefs;
+ my $call;
+ if (defined $proto) {
+ $call = _wrap $name, $proto, 0, '', \@coderefs, \%opts;
+ } else {
+ $call = _wrap $name, '', 0, '@_';
+ }
+
+ if (@coderefs) {
+ my $decls = @coderefs > 1 ? 'my @c = @_[' . join(', ', @coderefs) . ']; '
+ : 'my @c = ($_[' . $coderefs[0] . ']); ';
+ $call = $decls . $call;
+ }
+
+ $call = "{ $call }";
+ $call = "sub $call" if $opts{sub};
+
+ if ($opts{compile}) {
+ my $err;
+ {
+ local $@;
+ $call = eval $call;
+ $err = $@;
+ }
+ croak _clean_msg $err if $err;
+ }
+
+ return $call;
+}
+
+=head2 C<recall $name, @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.
+You can still force the prototype by passing C<< { $name => $proto } >> as the first argument.
+
+ my $a = [ ];
+ recall { 'CORE::push' => '\@$' }, $a, 1, 2, 3; # $a just contains 1
+
+It's implemented in terms of L</wrap>, and hence calls C<eval> at each run.
+If you plan to recall several times, consider using L</wrap> instead.
+
+=cut
+
+sub recall {
+ my $name = shift;
+
+ my ($wrap, $err);
+ {
+ local $@;
+ $wrap = eval { wrap $name };
+ $err = $@;
+ }
+ croak _clean_msg $err if $err;
+
+ goto $wrap;