I have no doubt that the 17thc ballad was based on a folk tale as many of them are, but I'm pretty sure it was a hack in London who put it into verse. The type of humour of course is exactly that used in 'John Blunt'/'Get up and bar the Door'.
Have you got the Pills reference please, Jim?