The author of Caterwaul, Spencer Tipping, has a document (which is a self-modifying Perl program itself) explaining the technique.
https://github.com/spencertipping/writing-self-modifying-per...
https://github.com/spencertipping/writing-self-modifying-per...
The coolest thing about these files, I think, is that they support inheritance from one another and are fairly smart about it. (This feature didn't exist at first, and as a result they were impossible to manage.) If you locally modify one to differ from one of its parents, it makes a note of this and preserves your changes to the modified attributes during upgrades. I use this on the Caterwaul page to provide custom HTML -- most scripts load some Javascript that shows you the attribute table.