Kasturirangan Rangaswamy wrote:
Hi,

I am building a web-based system and am trying to use CGI::Application
and HTML::Template to achieve both a modular structure and design/code
separation.

My design goal can be summarized as:

-- Base.pl is instance script for base module Base.pm
-- Base.pm throws a HTML page with a link which links to another instance script data_entry_index.pl
-- data_entry_index.pl is instance script for data_entry.pm
module which I want to be the child of Base.pm and be able to have access to it's app instance but is not!

I think you might be confusing what param() does... I'll elaborate below...

Base.pm module
-----------------------------------------------------------
#!/usr/local/bin/perl

package BASE;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use HTML::Template;
use CGI::Session qw/-ip-match/;
use base 'CGI::Application';

sub setup {

my $self = shift;
$self->start_mode('display_entry_screen');
$self->run_modes(
'display_entry_screen' => 'display_entry_screen',
);

}

sub display_entry_screen {

my $self = shift;
# I am purposely setting this parameter to test if it
# is accessible in the child module
$self->param('here' => 'here');

This will set the param for the remainder of this execution cycle. param() does not set things that are visible across multiple invocations.



-----------------------------------------------------------

and am calling the above module using the following instance script

Base.pl
------------------------------------------------------------
#!/usr/local/bin/perl

use lib '/export/home/r/rangask/software/cgi-bin/SoftwareDistribution';

use base 'BASE';

use base? in a script? that really only has meaning inside of a package so you don't need that line.


use strict;

my $webapp = BASE->new(TMPL_PATH => '/export/home/r/rangask/software/html/'
);
$webapp->run();
------------------------------------------------------------


Now Base.pm results in a screen with a single link from where I call
another instance script. That instance script calls a module which
needs to use Base.pm


as it's 'parent'. But I find thats not happening. The code is pasted
below


data_entry_index.pl
------------------------------------------------------------
#!/usr/local/bin/perl

use lib
'/export/home/r/rangask/software/cgi-bin/SoftwareDistribution/data_entry';

use data_entry;
use strict;

use lib '/export/home/r/rangask/software/cgi-bin/SoftwareDistribution';
use base 'BASE';

same thing... you don't need a 'use base' inside of a script.

my $webapp = data_entry->new(
TMPL_PATH => '/export/home/r/rangask/software/html/'
);
$webapp->run();
------------------------------------------------------------

data_entry.pm
------------------------------------------------------------
#!/usr/local/bin/perl

package data_entry;
use CGI::Application;
use CGI::Session;
use CGI::Application::ValidateRM;
use Data::FormValidator;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use HTML::Template;
use lib '/export/home/r/rangask/software/cgi-bin/SoftwareDistribution';
use base 'BASE';

sub setup {

my $self = shift;
$self->start_mode('data_entry_user_details');
$self->run_modes(
'data_entry_user_details' => 'data_entry_user_details',
);
}


sub data_entry_user_details {

my $self = shift;

# This should have given me a 1 because of the 'here' param I set in
Base.pm but it gives
a '0'!!
return $self->param();

Why do you think that this run mode would know anything about what was set in a different run mode? Yes, your data_entry class now has two run modes, 'data_entry_user_details' and 'display_entry_screen' (which it inherits from your BASE.pm), but one can't see what happens in the other, especially on different requests. If you have data you need to pass between pages you will need to propagate them using a query string or form variables (usually hidden). HTTP (and thus CGI) is a state-less environment. After your app sends the page to the user it no-longer knows the user exists. If you want it to remember the user then you need sessions, etc.


You might try reading the this page on the cgi-app.org wiki which explains the order of execution for a cgi-app: http://twiki.med.yale.edu/twiki2/bin/view/CGIapp/OrderOfOperations

There's also a lot of material on the wiki showing how to process forms, use sessions, etc.
--
Michael Peters
Developer
Plus Three, LP



--------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to