[PerlChina] the plugin CGI::Application::Plugin::Session issue

Mike.G hylinux at gmail.com
Tue Jun 10 18:28:15 PDT 2008


CAP好像停止开发了啊。
我选型的时候也看看了。
但是看到最后的更新日期太老了。
就没有采用。

Mike.G


2008/6/11 Qiang <shijialee at gmail.com>:

> Mike.G wrote:
> > Hi, list
> > I got one issue when I use the plugin CGI::Application::Plugin:
> > :Session
> >
> > I have a parent package(Class), named "FWebApp",
> > and this class extends the CGI::Application.
> > I did some setting work in the method cgiapp_init
> >
> > like this:
> >
> > sub cgiapp_init {
> >     my $this = shift;
> >
> >     #get the database configuration
> >     my $datasource = $this->cfg('data_source');
> >     my $data_user = $this->cfg('data_username');
> >     my $data_auth = $this->cfg('data_userauth');
> >     my $attr = $this->cfg('data_attr');
> >
> >     #configuration the Database
> >     $this->dbh_config($datasource,
> >         $data_user,
> >         $data_auth,
> >         $attr);
> >
> >
> >     #configuration the Session
> >     $this->session_config(
> >         CGI_SESSION_OPTIONS => [
> >         "driver:mysql",
> >         $this->query,
> >         {
> >             Handle=>$this->dbh
> >         }],
> >
> >         COOKIE_PARAMS => {
> >         -domain => $this->cfg('site_domain'),
> >         -expires=>'+40m',
> >         -path=>'/',
> >         -secure=>1,
> >         },
> >
> >     );
> >
> >     #set the template path
> >     $this->tmpl_path($this->cfg('template_path'));
> >
> >
> >
> > and the session configuration look like is ok.
> >
> > and so, just now, i assume I have a action: it is register .
> > so, I will write a new module named:
> >
> > package FWebApp::Register;
> > =head1  NAME
> >
> > FWebApp::Register - show the register page
> >
> > =head1  SYNOPSIS
> >
> > extends the Class FWebApp,
> > show the register page
> >
> > =cut
> > use strict;
> > use warnings;
> > use base qw/FWebApp/;
> > use CGI::Application::Plugin::AutoRunmode;
> > use CGI::Application::Plugin::DBH qw/dbh_config dbh/;
> > use CGI::Application::Plugin::ConfigAuto qw/cfg/;
> > use CGI::Application::Plugin::Session;
> >
> >
> > # the default requirement mode
> > # show the register page.
> > sub show_register: StartRunmode {
> >     my $this = shift;
> >
> >     # if that user had login, we will jump to home page
> >     my $template = undef;
> >     if ( $this->session->param('loginname') ) {
> >         $template = $this->load_tmpl('had_login.html');
> >         $template->param('HOMEPAGE', 'index.html');
> >     } else {
> >         $template = $this->load_tmpl('register.html');
> >     }
> >
> >
> >     return $template->output;
> >
> > }
> >
> >
> >
> >
> > 1;
> >
> >
> > it is extends FWebApp, but when I had prepared a script:
> > like this:
> > #!/usr/local/bin/perl -w -T
> > use strict;
> > use lib qw(. ../lib);
> > use CGI::Application::Plugin::ConfigAuto;
> > use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
> > use FWebApp::Register;
> >
> > my $app = FWebApp::Register->new(
> >     PARAMS => {
> >         cfg_file => 'config.pl' } );
> >
> > $app->run;
> >
> >
> > _*when I refresh that script, we always got the difference session id,
> > why?*_
> >
> >
>
> 我用 CGI::Application 但并不怎么使用 CGI::Application::Plugin::Session
> (缩为 CAP::Session)。 大致看了你的例子, script 每次运行都会调用 sub
> show_register 里的 $this->session->param('loginname') 来检查用户是否已登
> 录,如果没有登录,$this->session 的调用就会生成一个新的 CGI::Session
> object 因此生产一个新 session id. 你的 script 没有登录的那部分,即每次都
> 是一个非登录的用户访问,自然每次都拿到一个新 session id 了。
>
> 另外,CGI::Application 里一般都在 base class 里把要用到的 CAP 的 plugins
> load 进去,例如 CAP::DBH, CAP::ConfigAuto 等,没有必要在子包里在 use 了。
>
> > thanks
> >
> >
> > Mike.G
>
> HTH,
>
> Qiang
> _______________________________________________
> China-pm mailing list
> China-pm at pm.org
> http://mail.pm.org/mailman/listinfo/china-pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/china-pm/attachments/20080611/3f71a765/attachment.html 


More information about the China-pm mailing list