in reply to Re^3: Setting a type=file parameter in CGI.pm
in thread Setting a type=file parameter in CGI.pm

The reason to set after? To eliminate code redundancy. I have an existing, fairly complex subroutine and I have since added other functionality. The existing way takes input via a form submission, the new way adds a feature to "submit" via email. I want to share the same code between the two (one block of code to process email attachments the same way as file uploads via form). So, before I pass the CGI object to that existing subroutine I set everything the same way the form submission would. Works great... except file uploads.
  • Comment on Re^4: Setting a type=file parameter in CGI.pm

Replies are listed 'Best First'.
Re^5: Setting a type=file parameter in CGI.pm
by kyle (Abbot) on Jan 05, 2009 at 17:02 UTC

    Perhaps you could write the existing code to accept some data structure other than a CGI object. Then in the CGI that uses it, have something "convert" the CGI object you have into the data structure the new code takes. In your email processing code, you pass data in with the new structure directly.

      The only problem with that is that I kill my consistency. Every function in this particular project takes the same three objects as arguments and I don't want to break from that. I did come up with a work around though, the new function just deals with the attachments as uploads after the old function returns. So, some slight redundancy but only about 15 lines. I can live with it.