-sub recall {
- my ($name, @a) = @_;
- croak 'Wrong subroutine name' unless $name;
- $name =~ s/^\s+//;
- $name =~ s/[\s\$\@\%\*\&;].*//;
- my $proto = prototype $name;
- my @args;
- if (defined $proto) {
- my $i = 0;
- while ($proto =~ /(\\?)(\[[^\]]+\]|[^\];])/g) {
- my $p = $2;
- if ($1) {
- my $r = _check_ref $a[$i], $p;
- push @args, join '', $sigils{$r}, '{$a[', $i, ']}';
- } elsif ($p =~ /[\@\%]/) {
- push @args, join '', '@a[', $i, '..', (@a - 1), ']';
- last;
- } elsif ($p =~ /\&/) {
- push @args, 'sub{&{$a[' . $i . ']}}';
- } elsif ($p eq '_') {
- push @args, '$_';
+sub _wrap {
+ my ($name, $proto, $i, $args, $coderefs, $opts) = @_;
+
+ while ($proto =~ s/(\\?)(\[[^\]]+\]|[^\];])//) {
+ my ($ref, $sigil) = ($1, $2);
+ $sigil = $1 if $sigil =~ /^\[([^\]]+)\]/;
+
+ my $cur = "\$_[$i]";
+
+ if ($ref) {
+ if (length $sigil > 1) {
+ my $code = "my \$r = $opts->{ref}($cur); ";
+ my @branches = map {
+ my $subcall = _wrap(
+ $name, $proto, ($i + 1), $args . "$_\{$cur}, ", $coderefs, $opts
+ );
+ "if (\$r eq '$reftypes{$_}') { $subcall }";
+ } split //, $sigil;
+ $code .= join ' els', @branches, "e { $opts->{wrong_ref} }";
+ return $code;
+ } else {
+ $args .= "$sigil\{$cur}, ";
+ }
+ } elsif ($sigil =~ /[\@\%]/) {
+ $args .= '@_[' . $i . '..$#_]';
+ } elsif ($sigil =~ /\&/) {
+ my %h = do { my $c; map { $_ => $c++ } @$coderefs };
+ my $j;
+ if (exists $h{$i}) {
+ $j = int $h{$i};