You know, I would really like to be able to hide outer scopes in Perl. There are plenty of times that I've worked with bad code and I would love to quickly and easily see what variables are embedded in a chunk of code which are defined in another scope. I figured out one way to do this with a primitive refactoring tool I'm working on. I shove the code into a different namespace, wrap it in a subroutine to prevent it from being executed (the code will croak() if there is a BEGIN block), and then eval it with strict and warnings. The error messages are trivial to parse and I can figure out which variables are not defined there.
This leads to my next problem: which variables are defined after that chunk of code which are dependent on that chunk of code. Trying to figure out the "extract method" refactoring means I have nastiness like this:
my ( $foo, $bar );
($foo, $bar, $baz ) = $self->_extracted_method($baz);
That raises another issue. The code must now always work in list context (let's hope you don't have wantarray embedded in the extracted code) and if there is an embedded return (some languages only allow return at the end of a method/subroutine), then this could also screw things up.
The more I play with this, the more I understand why Adam Kennedy struggled with a refactoring editor.
However, if I go for an 80% solution and I write tests (which, as you know, I do), then I could execute a refactoring and then automatically run all tests for the refactored code.