-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, $cr, $opts) = @_;
+ while ($proto =~ s/(\\?)(\[[^\]]+\]|[^\];])//) {
+ my ($ref, $p) = ($1, $2);
+ $p = $1 if $p =~ /^\[([^\]]+)\]/;
+ my $cur = '$_[' . $i . ']';
+ if ($ref) {
+ if (length $p > 1) {
+ return 'my $r = ' . $opts->{ref} . '(' . $cur . '); '
+ . join ' els',
+ map( {
+ "if (\$r eq '" . $reftypes{$_} ."') { "
+ . _wrap($name, $proto, ($i + 1),
+ $args . $_ . '{' . $cur . '}, ',
+ $cr, $opts)
+ . ' }'
+ } split //, $p),
+ 'e { ' . $opts->{wrong_ref} . ' }'
+ } else {
+ $args .= $p . '{' . $cur . '}, ';
+ }
+ } elsif ($p =~ /[\@\%]/) {
+ $args .= '@_[' . $i . '..$#_]';
+ } elsif ($p =~ /\&/) {
+ my %h = do { my $c; map { $_ => $c++ } @$cr };
+ my $j;
+ if (not exists $h{$i}) {
+ push @$cr, $i;
+ $j = $#{$cr};