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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to