cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:
I've been having a play, and I've found something that appears to work and because I'm still not 100% on my OO stuff, I was hoping y'all could look at my solution and let me know if I've missed anything glaringly obvious, or really gone about this the wrong way.
I created a 'Common' module (for now it just contains the cgi function):
package JPI::Common; use strict; use warnings; use CGI; { my $q; sub new_cgi { $q = CGI->new() unless defined $q; return $q; } } 1;
To test this, I created a test module to change a param value:
Then I created the test script:package JPI::Test; use strict; use warnings; use JPI::Common; my $q = JPI::Common->new_cgi(); sub change_value { $q->param('test','value changed'); } 1;
And this does what I was looking for, ie, outputs:#!/usr/bin/perl -w use strict; use JPI::Common; use JPI::Test; my $q = JPI::Common->new_cgi(); $q->param('test','initial value'); print $q->header(), 'Before: ', $q->param('test'), "\n"; JPI::Test->change_value(); print 'After: ', $q->param('test'), "\n";
So, have I managed to solve the problem, or did I just get lucky? Am I doing this the most efficient way, or should I be returning a reference to the CGI object?!? Arghhh - another all-nighter takes its toll...Before: initial value After: value changed
thoughts welcomed :)
cLive ;-)
--
seek(JOB,$$LA,0);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using modules already 'used' (part 2)
by vladb (Vicar) on May 11, 2002 at 16:36 UTC | |
by cLive ;-) (Prior) on May 11, 2002 at 16:51 UTC |