move perl code from class context into functions

This fixes issue 1958, so we can perl -c without need to worry about
code running
Merge pull request #19 from coolo/master

move perl code from class context into functions