Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

CGI::Application design question
Hi,

This is a CGI::Application design question. It concerns side-
stepping normal run modes at any point within the application
to display an error screen.

I have created a 'base' module whose job it is to

a. Setup a connection to a database
b. Initialize session
c. Bring the user to an index screen.

I have put (a) and (b) in the cgiapp_init method as I intend to
extend this class in the future.

My code inside cgiapp_init looks as below


---------------------------------------------------------------------
sub cgiapp_init {

my $self = shift;

#Create a database connection
$self->initialize_database;

#Create a new session
$self->initialize_session;

}

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

'initialize_database' is a subroutine which is as follows


---------------------------------------------------------------------
sub initialize_database {

open(DB_CONNECTION_FILE, '/export/home/r/rangask/software/cgi-
bin/SoftwareDistribution/common/daase_connection_params.txt') ||
display_error_page("blah");
my ($hostname, $database, $user, $password) =
split(/:/,<DB_CONNECTION_FILE> );

}

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

I wish to display an error screen if something goes wrong with
opening of the file. Thats done by 'display_error_page' subroutine.


---------------------------------------------------------------------
sub display_error_page {

#my $self = shift;
print "in here";
my $msg_string = shift;

#Load the error template page
# my $tmpl_error_page = $self->load_tmpl('error_page.tmpl',
#                                        die_on_bad_params => 0,
#                                        cache => 1
#                                      );

my $tmpl_error_page = HTML::Template->new(filename =>
'/export/home/r/rangask/software/html/error_page.tmpl');
$tmpl_error_page->param(error_message => $msg_string);

$tmpl_error_page->output();
print "after the template";

}

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

Finally, my setup method is as follows


---------------------------------------------------------------------
sub setup {

my $self = shift;

#Note that no tmpl_path is being used here. We will give that
while calling this module

$self->start_mode('display_entry_screen');
$self->run_modes(
'display_entry_screen' => 'display_entry_screen',
'AUTOLOAD' => \&deal_with_undefined_run_mode
);
}

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

As you can see, I am calling the 'display_error_page' subroutine
from within the 'initialize_database' subroutine. So before I display
any page, if the file-open fails, I want to display an error page.

PROBLEM: I get to the error subroutine (I should because the DB
parameter filename given is wrong and I tested this fact by giving some

print statements and observing the command line output) but am
automatically redirected to the main page through the
'display_entry_screen' subroutine (details of that sub not shown
here)

How do I make it stay on the error page?

I could possibly define the 'display_error_page' as a run mode and
use the cgiapp_prerun and the mode_prerun methods to go to it
but this 'display_error_page' is a common method I want to call from
my 'child' modules and I feel defining it as an additional run mode
will prove restrictive.

I guess my question could also be rephrased as:

Is there a way of breaking the run-mode path of a CGI::Application
to throw an error page?

Any help is appreciated. Thanks for your patience in reading this
long post.

Sharad



__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail

Report this thread to moderator Post Follow-up to this message
Old Post
Kasturirangan Rangaswamy
11-27-04 01:55 PM


Re: CGI::Application design question

>
> From: Kasturirangan Rangaswamy <kasturiranganr@yahoo.com>
> Date: 27/11/2004 16:54:19
> To: beginners-cgi@perl.org
> Subject: CGI::Application design question
>
> Hi,
>
>    This is a CGI::Application design question. It concerns side-
>    stepping normal run modes at any point within the application
>    to display an error screen.
>
>    I have created a 'base' module whose job it is to
>
>    a. Setup a connection to a database
>    b. Initialize session
>    c. Bring the user to an index screen.
>
>    I have put (a) and (b) in the cgiapp_init method as I intend to
>    extend this class in the future.
>
>    My code inside cgiapp_init looks as below
>
>
> ---------------------------------------------------------------------
> sub cgiapp_init {
>
>     my $self = shift;
>
>     #Create a database connection
>     $self->initialize_database;
>
>     #Create a new session
>     $self->initialize_session;
>
>    }
>
> ---------------------------------------------------------------------
>
>   'initialize_database' is a subroutine which is as follows
>
>
> ---------------------------------------------------------------------
> sub initialize_database {
>
>     open(DB_CONNECTION_FILE, '/export/home/r/rangask/software/cgi-
>       bin/SoftwareDistribution/common/daase_connection_params.txt') ||
>         display_error_page("blah");
>     my ($hostname, $database, $user, $password) =
> split(/:/,<DB_CONNECTION_FILE> );
>
>    }
>
> ---------------------------------------------------------------------
>
>   I wish to display an error screen if something goes wrong with
> opening of the file. Thats done by 'display_error_page' subroutine.
>
>
> ---------------------------------------------------------------------
> sub display_error_page {
>
>     #my $self = shift;
>     print "in here";
>     my $msg_string = shift;
>
>     #Load the error template page
>     # my $tmpl_error_page = $self->load_tmpl('error_page.tmpl',
>     #                                        die_on_bad_params => 0,
>     #                                        cache => 1
>     #                                      );
>
>     my $tmpl_error_page = HTML::Template->new(filename =>
> '/export/home/r/rangask/software/html/error_page.tmpl');
>     $tmpl_error_page->param(error_message => $msg_string);
>
>     $tmpl_error_page->output();
>     print "after the template";
>
>    }
>
> ---------------------------------------------------------------------
>
>    Finally, my setup method is as follows
>
>
> ---------------------------------------------------------------------
> sub setup {
>
>      my $self = shift;
>
>      #Note that no tmpl_path is being used here. We will give that
> while calling this module
>
>      $self->start_mode('display_entry_screen');
>      $self->run_modes(
>               'display_entry_screen' => 'display_entry_screen',
>                           'AUTOLOAD' => \&deal_with_undefined_run_mode
>      );
>    }
>
> ---------------------------------------------------------------------
>
>    As you can see, I am calling the 'display_error_page' subroutine
> from within the 'initialize_database' subroutine. So before I display
>    any page, if the file-open fails, I want to display an error page.
>
>    PROBLEM: I get to the error subroutine (I should because the DB
> parameter filename given is wrong and I tested this fact by giving some
>
>    print statements and observing the command line output) but am
> automatically redirected to the main page through the
>    'display_entry_screen' subroutine (details of that sub not shown
> here)
>
>    How do I make it stay on the error page?
>
>    I could possibly define the 'display_error_page' as a run mode and
> use the cgiapp_prerun and the mode_prerun methods to go to it
>    but this 'display_error_page' is a common method I want to call from
> my 'child' modules and I feel defining it as an additional run mode
>    will prove restrictive.
>
>    I guess my question could also be rephrased as:
>
>    Is there a way of breaking the run-mode path of a CGI::Application
> to throw an error page?
>
>    Any help is appreciated. Thanks for your patience in reading this
> long post.
>
> Sharad
>
>
>
> __________________________________
> Do you Yahoo!?
> Read only the mail you want - Yahoo! Mail SpamGuard.
> http://promotions.yahoo.com/new_mail
>
> --
> To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail: beginners-cgi-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
Hello Sharad and others,
I am not sure about your question except that I think it requires the use of
 a command like exit(0);.  This always exits HTML pages and waits for a resp
onse to checkboxes etc., so I assume it would do the same thing for an error
page,
Kieran.


This message was sent through MyMail http://www.mymail.com.au



Report this thread to moderator Post Follow-up to this message
Old Post
krmair01i@ozemail.com.au
11-28-04 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL CGI Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:03 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.