I think you should seriously reconsider this approach. Ask for help on the errors you encountered (here on PM, or on the cgiapp mailing list, or even in #cgiapp on irc.perl.org). I promise you that cgiapp will make your life a lot easier than this blob of code.