CAP好像停止开发了啊。<br>我选型的时候也看看了。<br>但是看到最后的更新日期太老了。<br>就没有采用。<br><br>Mike.G<br><br><br><div class="gmail_quote">2008/6/11 Qiang &lt;<a href="mailto:shijialee@gmail.com">shijialee@gmail.com</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">Mike.G wrote:<br>
&gt; Hi, list<br>
&gt; I got one issue when I use the plugin CGI::Application::Plugin:<br>
&gt; :Session<br>
&gt;<br>
&gt; I have a parent package(Class), named &quot;FWebApp&quot;,<br>
&gt; and this class extends the CGI::Application.<br>
&gt; I did some setting work in the method cgiapp_init<br>
&gt;<br>
&gt; like this:<br>
&gt;<br>
&gt; sub cgiapp_init {<br>
&gt; &nbsp; &nbsp; my $this = shift;<br>
&gt;<br>
&gt; &nbsp; &nbsp; #get the database configuration<br>
&gt; &nbsp; &nbsp; my $datasource = $this-&gt;cfg(&#39;data_source&#39;);<br>
&gt; &nbsp; &nbsp; my $data_user = $this-&gt;cfg(&#39;data_username&#39;);<br>
&gt; &nbsp; &nbsp; my $data_auth = $this-&gt;cfg(&#39;data_userauth&#39;);<br>
&gt; &nbsp; &nbsp; my $attr = $this-&gt;cfg(&#39;data_attr&#39;);<br>
&gt;<br>
&gt; &nbsp; &nbsp; #configuration the Database<br>
&gt; &nbsp; &nbsp; $this-&gt;dbh_config($datasource,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $data_user,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $data_auth,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $attr);<br>
&gt;<br>
&gt;<br>
&gt; &nbsp; &nbsp; #configuration the Session<br>
&gt; &nbsp; &nbsp; $this-&gt;session_config(<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; CGI_SESSION_OPTIONS =&gt; [<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &quot;driver:mysql&quot;,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;query,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Handle=&gt;$this-&gt;dbh<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; }],<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; COOKIE_PARAMS =&gt; {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; -domain =&gt; $this-&gt;cfg(&#39;site_domain&#39;),<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; -expires=&gt;&#39;+40m&#39;,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; -path=&gt;&#39;/&#39;,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; -secure=&gt;1,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; },<br>
&gt;<br>
&gt; &nbsp; &nbsp; );<br>
&gt;<br>
&gt; &nbsp; &nbsp; #set the template path<br>
&gt; &nbsp; &nbsp; $this-&gt;tmpl_path($this-&gt;cfg(&#39;template_path&#39;));<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; and the session configuration look like is ok.<br>
&gt;<br>
&gt; and so, just now, i assume I have a action: it is register .<br>
&gt; so, I will write a new module named:<br>
&gt;<br>
&gt; package FWebApp::Register;<br>
&gt; =head1 &nbsp;NAME<br>
&gt;<br>
&gt; FWebApp::Register - show the register page<br>
&gt;<br>
&gt; =head1 &nbsp;SYNOPSIS<br>
&gt;<br>
&gt; extends the Class FWebApp,<br>
&gt; show the register page<br>
&gt;<br>
&gt; =cut<br>
&gt; use strict;<br>
&gt; use warnings;<br>
&gt; use base qw/FWebApp/;<br>
&gt; use CGI::Application::Plugin::AutoRunmode;<br>
&gt; use CGI::Application::Plugin::DBH qw/dbh_config dbh/;<br>
&gt; use CGI::Application::Plugin::ConfigAuto qw/cfg/;<br>
&gt; use CGI::Application::Plugin::Session;<br>
&gt;<br>
&gt;<br>
&gt; # the default requirement mode<br>
&gt; # show the register page.<br>
&gt; sub show_register: StartRunmode {<br>
&gt; &nbsp; &nbsp; my $this = shift;<br>
&gt;<br>
&gt; &nbsp; &nbsp; # if that user had login, we will jump to home page<br>
&gt; &nbsp; &nbsp; my $template = undef;<br>
&gt; &nbsp; &nbsp; if ( $this-&gt;session-&gt;param(&#39;loginname&#39;) ) {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $template = $this-&gt;load_tmpl(&#39;had_login.html&#39;);<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $template-&gt;param(&#39;HOMEPAGE&#39;, &#39;index.html&#39;);<br>
&gt; &nbsp; &nbsp; } else {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; $template = $this-&gt;load_tmpl(&#39;register.html&#39;);<br>
&gt; &nbsp; &nbsp; }<br>
&gt;<br>
&gt;<br>
&gt; &nbsp; &nbsp; return $template-&gt;output;<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; 1;<br>
&gt;<br>
&gt;<br>
&gt; it is extends FWebApp, but when I had prepared a script:<br>
&gt; like this:<br>
&gt; #!/usr/local/bin/perl -w -T<br>
&gt; use strict;<br>
&gt; use lib qw(. ../lib);<br>
&gt; use CGI::Application::Plugin::ConfigAuto;<br>
&gt; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;<br>
&gt; use FWebApp::Register;<br>
&gt;<br>
&gt; my $app = FWebApp::Register-&gt;new(<br>
&gt; &nbsp; &nbsp; PARAMS =&gt; {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; cfg_file =&gt; &#39;config.pl&#39; } );<br>
&gt;<br>
&gt; $app-&gt;run;<br>
&gt;<br>
&gt;<br>
&gt; _*when I refresh that script, we always got the difference session id,<br>
</div></div>&gt; why?*_<br>
&gt;<br>
&gt;<br>
<br>
我用 CGI::Application 但并不怎么使用 CGI::Application::Plugin::Session<br>
(缩为 CAP::Session)。 大致看了你的例子, script 每次运行都会调用 sub<br>
show_register 里的 $this-&gt;session-&gt;param(&#39;loginname&#39;) 来检查用户是否已登<br>
录,如果没有登录,$this-&gt;session 的调用就会生成一个新的 CGI::Session<br>
object 因此生产一个新 session id. 你的 script 没有登录的那部分,即每次都<br>
是一个非登录的用户访问,自然每次都拿到一个新 session id 了。<br>
<br>
另外,CGI::Application 里一般都在 base class 里把要用到的 CAP 的 plugins<br>
load 进去,例如 CAP::DBH, CAP::ConfigAuto 等,没有必要在子包里在 use 了。<br>
<br>
&gt; thanks<br>
&gt;<br>
&gt;<br>
&gt; Mike.G<br>
<br>
HTH,<br>
<font color="#888888"><br>
Qiang<br>
_______________________________________________<br>
China-pm mailing list<br>
<a href="mailto:China-pm@pm.org">China-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/china-pm" target="_blank">http://mail.pm.org/mailman/listinfo/china-pm</a></font></blockquote></div><br>