Hi Anonymous Monk,
You said
my $q = CGI->new; instead of my $q = CGI->new( { } );
and
. . . reads all the POST data and makes it unavailable to your main pr
+ogram
Yes both, cases were true. I changed them and now everything is working fine. Just to confirm whether I am following good coding practice or not, below are my few doubts on same line.
- myModule has following code in its new sub routine, does it has any flaws:
sub new {
bless {}, shift
}
- How do I use relative name scheme? (instead, of using : use lib 'D:\\Websiste\\One\cgi-bin';) I tried earlier, but it failed. Normal CGI scripts and myModule are in same directory.
- In myModule, I was using my $session = CGI::Session->load or die CGI::Session->errstr; at global scope to check sessions, before generating HTML contents. Now after your suggestion, I moved same code in each sub routine. But this duplicates code, and I have to write it in, every sub routine. Is there any work around for same. Or all session handling code should be put into different sub routine.
| [reply] [d/l] [select] |
myModule has following code in its new sub routine, does it has any flaws:
I don't see any flaws with that "class method"
2. How do I use relative name scheme? (instead, of using : use lib 'D:\\Websiste\\One\cgi-bin';) I tried earlier, but it failed. Normal CGI scripts and myModule are in same directory.
?? File::FindLib - Find and use a file/dir from a directory above your script file
?? FindBin - Locate directory of original perl script
In myModule, I was using my $session = CGI::Session->load or die CGI::Session->errstr; at global scope to check sessions, before generating HTML contents. Now after your suggestion, I moved same code in each sub routine. But this duplicates code, and I have to write it in, every sub routine. Is there any work around for same. Or all session handling code should be put into different sub routine. Um, try
sub new {
my( $class, %args ) = @_;
my $self = bless { %args }, $class
my $query = CGI->new;
my $sessionargs = $self->{sessionargs} || $default_sessionargs;
my $session = CGI::Session->load(
$sessionargs->{dsn}, $query, $sessionargs->{dsn_args},
) or die CGI::Session->errstr;
$self->{query} = $query;
$self->{session} = $session;
return $self;
}
sub param {
my $self = shift;
$self->{query}->param( @_ );
}
sub session { $_[0]->{session}; }
sub fandango {
my( $self ) = @_;
$self->param ...;
...;
$self->session->param ...;
...;
}
Things like that, see http://cgi-app.org//CGI::Application
http://mojolicio.us/perldoc/Mojolicious/Guides/Growing
Re^3: web applications: what is the correct way to realise web applications
Re: I need wisdom on structuring procedural code in Catalyst
Re: Form validation and best practice in CGI::Application
Re^2: mod_perl website structure
Re^2: High level OOP query ( Building Skills Object-Oriented Design Mindset Development )
Re^3: High level OOP query (internal data),
Re: RFC: beginner level script improvement (version control)
Re: Perl MIME parser partially works with my code I wrote (code does not exist , there is no code)
| [reply] [d/l] |
Hi, Anonymous Monk
This post, not only answers, my original questions, but would also clear my upcoming doubts, on same path. Thanks!
| [reply] |
Oops! I replied, to your first post, without reading, this one.
Testing, what you have said, and would communicate back results. Thanks for giving pointer. | [reply] |