Piers Cawley wrote:
One of the 'mental apps' that's been pushing some of the things I've been
asking for in Perl 6's introspection system is a combined
refactoring/debugging/editing environment for the language. One of the
annoyances of the 'only perl can parse Perl' thing is not so much the truth of
the statement, but that perl 5 doesn't allow you to ask about the parsed code
in ways that would be useful for an IDE. Perl 6 promises to change that -- it
should be possible to either write a fantastic Perl 6 IDE in perl itself, or to
write a codegrokker object that can be used by some pre existing IDE.
While I agree with this wholeheartedly, I am afraid to say that I
haven't seen a lot of evidence that introspection has been given much
thought in the Perl 6 design process. There was a flurry at one point
about the execution of BEGIN blocks, but then silence again.
One thing is for sure: although B::Deparse is a wonder to behold, it
isn't something that we should try to be repeating. It doesn't give you
control over how much of the code to parse, whether you trust the code
your're parsing, or in the case of BEGIN blocks even whether you have
the choice to execute them or not. It doesn't give you the ability to
load parts of another program into the running program's namespace, and
it doesn't give you enough hooks and callbacks to be able to transform
syntax trees. At least, if it does do any of those things, then I
haven't seen ways of doing them in the documentation for B and O.
I'm afraid that because of the dynamic parse/execute nature of Perl, it
may be a theoretically intractable problem to parse Perl safely. Don't
run the BEGIN blocks and you change the way future source is parsed
compared with true runtime. Do run them and you risk someone inserting
dangerous code into one. It isn't good if turning on syntax
highlighting on some found-in-the-wild code in your Perl-aware editor
could wipe your hard disk.
Oh, and I don't have a lot of faith in the Safe module, either, which is
a marvel of kludge engineering and broken, both at the same time.
What's the plan for that module's moral equivalent in Perl 6?
I'd love it if someone could set my mind at ease here. I have to
process syntax trees of Perl code quite often in my line of work and I'd
love something less finicky than a Safe/B::* combination.