in reply to Re: CGI Module
in thread CGI Module

This is the entire code for my module. Yes I know I am reinventing the wheel a bit, but the purpose is to store all form elements in a standard location accessable from any of the other modules in the system that would be dependant. Instead of having to call the CGI module from each(which mind you doesnt work anyway.
package forms; use strict; use warnings; use CGI; sub new { my ($class) = @_; my $self = {_form => undef}; bless $self,$class; return $self; } sub fetch { my ($self) = @_; $self->{_form} = new CGI; return $self->{_form}; } 1;

Replies are listed 'Best First'.
Re^3: CGI Module
by brian_d_foy (Abbot) on Jun 05, 2005 at 04:11 UTC

    What are you trying to do with this module, or why do you need a separate module? That's a lot of typing to simply do my $q = CGI->new.

    Remember that once you've created a CGI object, it reads STDIN, and you won't be able to read that again. If all of your form data is in the message body, only the first CGI object will have been able to see it.

    How are you using this module in your script?

    --
    brian d foy <brian@stonehenge.com>
Re^3: CGI Module
by tlm (Prior) on Jun 05, 2005 at 04:03 UTC

    One potential problem I see is that, as you have it, the fetch method will return a different CGI object with each invocation. Also, it's not clear to me that a OO class is particularly useful here. (I mean, if you are going to pass an object of this class around so that you can access the CGI object through it, then you may as well pass around the CGI object in the first place.)

    I'm not entirely clear on what you're trying to do, but maybe this would do what you want:

    package forms; my $FORMS; sub fetch { $FORMS ||= CGI->new(); return $FORMS; } ## elsewhere use forms; my $q = forms::fetch();

    the lowliest monk

      That worked. But I found in my infinate wisdom I didnt realize by dumb luck that Iwas calling the module AFTER the return statement so it was being ignored... I has returned to strictly using the CGI module and its all good everything works