NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
PMD (Score:1)
I was interested to run across PMD [sourceforge.net], the software on which the Copy/Paste Detector runs. Though it's not possible to do that sort of static analysis in Perl, there are ways to do something very similar. I've resurrected my long-dormant bytecode-to-XML project.
PMD uses treecc [southern-storm.com.au] to build an AST, then uses the Visitor pattern to call an event for each node in the tree. From there, he looks for specific patterns of nodes. It's a little tricky, but you can build up a sort of state machine.
My code is B::SAX (no, it's not ready yet), which is like an inside-out Visitor. It throws events for each node in the tree. I just have to write a SAX handler that can check for patterns, a handler to transform bad patterns into good patterns, and a handler that mangles the output into something B::Deparse can understand.
Yeah, there's a lot of hand-waving there, but the really hard part -- tokenizing Perl -- is done.
Reply to This