Advertisement
ronabraham

TestCGIApplication

Oct 10th, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.66 KB | None | 0 0
  1. package TestCGIApplication;
  2. use base 'CGI::Application';
  3. use CGI::Application::Plugin::TT;
  4. use CGI::Application::Plugin::Session;
  5. use Template;
  6. use CGI::Application::Plugin::LogDispatch;
  7. use strict;
  8.  
  9. my $global_session;
  10. my @parameter_list = ("session_id","t1","t2","cbox");
  11.  
  12.  
  13. our $TEMPLATE_OPTIONS = {
  14.     INCLUDE_PATH => \@INC,
  15. };
  16.  
  17. TestCGIApplication->tt_config( TEMPLATE_OPTIONS => $TEMPLATE_OPTIONS );
  18.  
  19. sub setup {
  20.   my $self = shift;
  21.  
  22.   #$self->tmpl_path('/Library/WebServer/Documents/XXXXXX/cgi-bin/tt/');
  23.   $self->start_mode('mode1');
  24.   $self->run_modes({    
  25.      
  26.       'mode1' => 'collect_data',
  27.       'mode2' => 'display_data'
  28.      
  29.   });
  30. }
  31.  
  32. sub cgi_app_init(){
  33.  
  34.   my $self = shift;
  35.   $self->session_config(
  36.    
  37.     CGI_SESSION_OPTIONS => [
  38.       undef,
  39.       $self->query,
  40.       { Directory => '/tmp/sessions' }
  41.      
  42.     ]) or die $!;
  43.  
  44. $self->log_config(
  45.    LOG_DISPATCH_MODULES => [
  46.    {
  47.        module => 'Log::Dispatch::File',
  48.        name =>  'info',
  49.        filename => 'info.log',
  50.        min_level => 'info',
  51.        close_after_write => 'false',
  52.    },
  53.    ]) or die $!;
  54.  
  55.  
  56.  
  57. }
  58.  
  59. sub error(){
  60.   return $!;
  61. }
  62.  
  63. sub collect_data(){
  64.  
  65.   my $self = shift;
  66.   $global_session = $self->session();
  67.   my $query = $global_session->query();
  68.   my %page_data;
  69.   $self->log->info(sprintf "\ncollect_data() cbox=:%s:",$query->param('cbox'));
  70.   if(!$global_session->is_new()){
  71.   $global_session->clear();
  72.   %page_data = ('session_id' => $global_session->id(),
  73.                       't1' => $query->param('t1'),
  74.                       't2'=> $query->param('t2'),
  75.                       'cbox' => $query->param('cbox')
  76.                     );
  77.    $global_session->save_param();
  78.   }else {
  79.  
  80.   %page_data = ('session_id' => $global_session->id(),
  81.                       't1' => $query->param('t1'),
  82.                       't2'=> $query->param('t2'),
  83.                       'cbox' => $query->param('cbox')
  84.                     );
  85.   }
  86.   #$global_session->load_param($query,\@parameter_list);
  87.   return $self->tt_process('collect_data.tt',\%page_data);
  88. }
  89.  
  90. sub display_data(){
  91.  
  92.   my $self = shift;
  93.   $global_session = $self->session;
  94.   my $query = $global_session->query();
  95. my %page_data = ('session_id' => $global_session->id(),
  96.                       't1' => $query->param('t1'),
  97.                       't2'=> $query->param('t2'),
  98.                       'cbox' => $query->param('cbox')
  99.                     );
  100.  
  101. $self->log->info(sprintf "\ndisplay_data() cbox=:%s:",$query->param('cbox'));
  102.   $global_session->save_param($query,\@parameter_list);
  103.   # $global_session->save_param();
  104.   return $self->tt_process('display_data.tt',\%page_data);
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement