Since you're eval()ing the code they enter to set the variables and such, you can directly reproduce the code of the subroutine, as long as you request that they enter ONE subroutine at a time, and that subroutines are entered by themselves. This also does not work for code references. But it is a start.
# in evaluate()
if (/^\s*sub\s+(\S+)/) {
$WorkSpace::functions{$1} = $_;
}